View Full Version : Adding form field in PHP

01-17-2008, 12:19 AM
I'm trying to ad some additional fields to a PHP form. I can't get the field to come through on the form.

FROM html page:

<tr><td>Site Name:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Site URL:</td><td><input type="text" name="siteurl" size="25" /></td></tr>
<tr><td>Email address:</td><td><input type="text" name="email" size="25" /></td></tr>

From the php form:

$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Site Name: $name\n" .
"Site URL: $siteurl\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.08" );
header( "Location: $thankyouurl" );
exit ;

The email comes through with the Site URL field blank as follows:
Site Name: buzzzzzzzzzz
Site URL:
Email of sender: abc@xxxxxxxx.ca
------------------------- COMMENTS -------------------------

kdoodf kdkkfdpkf pkdpkfpfkzdk/zdp

Can someone point me to what I am missing in the code to make the addition field "siteurl" work? Thank You.

01-17-2008, 02:06 AM
Check your log files, chances are you have an undefined variable being called.
Nothing is incorrect with your code, just the way you are accessing it. PHP uses superglobals and more and more hosts are leaving the register_globals directive disabled (which is good, php 6 removes them completely and I'm happy about that :)).
The other variables are likely extracted elsewhere, using either a $_REQUEST/_POST/_GET array indexed with the field name. So, to retrieve your data you would use $_POST['siteurl'] or $_GET['siteurl'] depending on if your form's method is get or post.
That is a likely cause for your problem. Try that first (remember to clean your variables out using addslashes and htmlspecialchars or htmlentities before using), and see if that works for you. Otherwise I don't see anything wrong with what you have.
On a side note, I didn't think you could use "name="name"" as a named field item, could swear that caught me up once... or maybe that was id? Meh, whatever lol