![]() | | ||||||||
| | #1 |
| Warrior Member Join Date: Jul 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
The feedback program you want to create will have three main tasks, as follows: • Display a form. • Display a verification page to let the user review what he’s about tosubmit. • Send the form’s contents to the Webmaster and display a thank youpage. For the program to know what it should do, you’ll use a variable called stepto let the program know what part of the process it should perform. So, ifstep is 1 or if it isn’t given, the form should be displayed; if step is 2, theverification page should be sent back; and if step is 3, the e-mail should besent and the thank you page should be displayed. Here is how the feedback form program will look like: <?php /* ch07ex08 - feedback form multi-function program */ // Make reference to form variables $form =& $HTTP_POST_VARS; // Define configuration settings define(‘FEEDBACK_TO’, ‘example@example.com’); // email for webmaster define(‘FEEDBACK_SUBJ’, ‘Feedback: ‘); // subject prefix switch ($form[‘step’]) // Decide what to do based on step { case 1: // If step is 1, or if default: // no known step is specified, display the form ?> <html> <head><title>Pela PHP :: Example 8 :: Feedback Form</title></head> <body><h2>Pela PHP :: Example 8 :: Feedback Form</h2> <form action=”<?= $PHP_SELF ?>” method=”post”> <input type=”hidden” name=”step” value=”2”> <b>Name:</b> <input type=”text” name=”feedback_name”> <b>Email:</b> <input type=”text” name=”feedback_email”> <b>Subject:</b> <select name=”feedback_subj”> <option selected>Comment</option> <option>Complaint</option> <option>Suggestion</option> </select> <b>Message:</b> <textarea name=”feedback_msg” rows=”5” cols=”40”></textarea> <input type=”submit” value=”Continue”> </form> </body> </html> <?php break; // end of case 1/default for switch ($form[‘step’]) case 2: // Show user his submission for review ?> <html> <head> <title>Pela PHP :: Example 8 :: Feedback Form - Review Your Submission</title></head> <body> <h2>Pela PHP :: Example 8 :: Feedback Form</h2> <h4>Review Your Submission</h4> <b>Name:</b> <?= $form[‘feedback_name’] ?> <b>Email:</b> <?= $form[‘feedback_email’] ?> <b>Subject:</b> <?= $form[‘feedback_subj’] ?> <b>Message:</b> <?= $form[‘feedback_msg’] ?> <form action=”<?= $PHP_SELF ?>” method=”post”> <input type=”hidden” name=”step” value=”3”> <input type=”hidden” name=”feedback_name” value=”<?= $form[‘feedback_name’] ?>”> <input type=”hidden” name=”feedback_email” value=”<?= $form[‘feedback_email’] ?>”> <input type=”hidden” name=”feedback_subj” value=”<?= $form[‘feedback_subj’] ?>”> <input type=”hidden” name=”feedback_msg” value=”<?= $form[‘feedback_msg’] ?>”> <input type=”button” value=”Back” onClick=”javascript:history.go(-1);”> <input type=”submit” value=”Send”> </form> </body> </html> <?php break; // end of case 2 for switch ($form[‘step’]) case 3: // Send feedback and show thank you page // Send feedback $feedback_subj = FEEDBACK_SUBJ . $form[‘feedback_subj’]; $feedback_body = <<<END Name: {$form[’feedback_name’]} Email: {$form[’feedback_email’]} Subject: {$form[’feedback_subj’]} Message: {$form[’feedback_msg’]} END; mail(FEEDBACK_TO, $feedback_subj, $feedback_body); // Show thank you page ?> <html> <head><title>Pela PHP :: Example 8 :: Feedback Form - Thank You</title></head> <body> <h2>Pela PHP:: Example 8 :: Feedback Form</h2> <h4>Thank You</h4> Your feedback has been sent! </body> </html> <?php break; // end of case 3 for switch ($form[’step’]) } ?> More tutorials on pelaphptutorials |
| Last edited by duleto; 10-05-2009 at 08:51 AM. Reason: adding web site | |
| | |
![]() |
|
| Tags |
| feedback, form |
| Thread Tools | |
| |
![]() |