A Feedback Form

Oct 05, 2009 Author: Developer

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:

/* feedback form multi-function program */
// Make reference to form variables
$form =& $HTTP_POST_VARS;
// Define configuration settings
define(‘FEEDBACK_TO’, ‘smile@pelaphptutorials.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
<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”>
<input type=”text” name=”feedback_name”><br><br>
<input type=”text” name=”feedback_email”><br><br>
<b>Subject:</b><br><select name=”feedback_subj”>
<option selected>Comment</option>
<textarea name=”feedback_msg” rows=”5” cols=”40”></textarea><br><br>
<input type=”submit” value=”Continue”>
break; // end of case 1/default for switch ($form[‘step’])
case 2: // Show user his submission for review
<title>Pela PHP :: Example 8 :: Feedback Form - Review Your
<h2>Pela PHP :: Example 8 :: Feedback Form</h2>
<h4>Review Your Submission</h4>
<?= $form[‘feedback_name’] ?><br><br>
<?= $form[‘feedback_email’] ?><br><br>
<?= $form[‘feedback_subj’] ?><br><br>
<?= $form[‘feedback_msg’] ?><br><br>
<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”>
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’]}
mail(FEEDBACK_TO, $feedback_subj, $feedback_body);
// Show thank you page
<head><title>Pela PHP :: Example 8 :: Feedback Form - Thank You</title></head>
<h2>Pela PHP:: Example 8 :: Feedback Form</h2>
<h4>Thank You</h4>
Your feedback has been sent!
break; // end of case 3 for switch ($form[’step’])

tags: feedback form

views 6199
  1. Add New Comment