Feedback form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RumRat
Forum Newbie
Posts: 1
Joined: Sat Oct 09, 2004 3:35 pm

Feedback form

Post by RumRat »

I am a real newbie to PHP and have a feedback form on my site and would like to add some extra fields to the existing form.

At present all I have is Name, Email Address and Comments. I would like to add the following fields: A visitors URL (Not a required field) Select country A required drop down box and how did you find us?, also a d/d box
The present code I have is:

Code: Select all

$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
	header( "Location: $formurl" );
	exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
   header( "Location: $errorurl" );
   exit ;
}
if (get_magic_quotes_gpc()) {
	$comments = stripslashes( $comments );
}

$messageproper =

	"This message was sent from:\n" .
	"$http_referrer\n" .
	"------------------------- COMMENTS -------------------------\n\n" .
	$comments .
	"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper, "From: "$name" <$email>\nReply-To: "$name" 
<$email>\nX-Mailer: chfeedback.php 2.02" );
header( "Location: $thankyouurl" );
exit ;

?>
Can anyone suggest what I do now?

Many, many thanks

Ken
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You would first need to add these to the HTML form - then you can gather the information from them in the same way you do for the other fields. Checking whether required fields are filled or not would mean an addition of more conditions to this line:

Code: Select all

if (empty($name) || empty($email) || empty($comments)) {
Mac
Post Reply