![]() The action attribute of the form would point to the same page.php. In my Effortless E-Commerce with PHP and MySQL book, the first example site uses the page.php script to show any page of content. For example, on any dynamic website, the same PHP script is used to display all the content of a specific type. I would instead submit the form back to the product page. The form submission could go to a new page, but then the user would need to click the Back button to return to the product page, which isn’t ideal. Similarly, if you have a system in place for guaranteeing a person only ever reviews a product once, you’d have PHP check for that scenario before showing this form. ![]() If login is required, you might add (PHP) code that only shows the form to logged-in users, or prints a comment saying the user must log in to review the product. You’d have the PHP script that displays the product write these values to the inputs. The main catch is that the product ID and product type (or whatever the database must have in order to associate a review with an item) must be stored in hidden inputs. Hopefully you’ve done plenty of web development already, so you know that a form for adding reviews would just be like so: Review This Product Rating 5 4 3 2 1 Review Ĭlearly you’d want to use some CSS to make it pretty, but that’s the basic idea. Handle secondary actions, such as flagging reviews or comments as inappropriate, indicating that reviews were helpful, adding comments to reviews, indicating that comments where helpful, and so forth.The reviews.php script would do several things: ![]() ![]() This way, the product pages can remain unadulterated and the same review code can easily be used, or modified, as needed. Learn More Buy Adding Reviews Adding Reviewsįirst, from a code organization standpoint, it’d be better to put all of the review logic into one or more includable files and then include it on product pages: include('includes/reviews.php') ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |