Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 10-05-2009, 08:48 AM   #1
Warrior Member
 
Join Date: Jul 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb A Feedback Form

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
duleto is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
feedback, form

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 04:30 AM.