Click to See Complete Forum and Search --> : Form Not working


saud
09-24-2007, 08:26 PM
I have a form script. It used to work perfect. But I changed my hosting company and since then it is not working. Everything is working fine and I am also getting the email, but the values that are filled are not included in the email.


<center>
<img src="images/contactus.jpg" border="0" width="120" height="50">
<br><br>
<?php

/*
This is the contact form I use on my site
Feel free to modify it and use it as a guide
to setting up securimage for your site.
*/

$SiteName = "http://www.virginmaryexports.com"; // change to your web site URL
$SiteEmail = "xxx@xxx.com"; //change to your e-mail address
$ThankYouMessage = "Thank you for your message"; // Your thank you subject line
$SiteUserName = "Virgin Mary Exports";
$today = date("F d, Y. H:i:s ",time()+34200); // 37900 Uncomment this to add the date and time
$ip = $_SERVER[REMOTE_ADDR];


if (!isset($_POST['submit'])) {

showForm();

} else { //form submitted

$error = 0;


if(empty($_POST['Name'])) {
$error = 1;
$errstr[] = "Please enter your name";
}

if(empty($_POST['Email'])) {
$error = 1;
$errstr[] = "Please enter a valid email address";
}

if(empty($_POST['Comments']) || preg_match("/^enter your message here$/i", $_POST['UserComments'])) {
$error = 1;
$errstr[] = "Please enter your message";
}

if(empty($_POST['imagetext'])) {
$error = 1;
$errstr[] = "Please validate the image code";
} else {
include "security/securimage.php";
$img = new Securimage();
$valid = $img->check($_POST['imagetext']);

if(!$valid) {
$error = 1;
$errstr[] = "The code you entered was incorrect";
}
}

if ($error == 1) {
echo "<center>\n<font style=\"color: #FF0000\">\n";
foreach($errstr as $err) {
echo "<li> " . $err . "</li>\n";
}
echo "</font>\n</center>\n<br />\n\n";

showForm();

} else {
$AdminMessage = "
".$Name." , Submitted the following Information:

Name: ".$Name."
E-mail: ".$Email."
Company: ".$Company."
Website: ".$Website."
Address: ".$Address."
City: ".$City."
State: ".$State."
Zip: ".$Zip."
Country: ".$Country."
Phone: ".$Phone."
Fax: ".$Fax."
Comments:
".$Comments."

-------------------------------------------------------------------------
Date/Time: ".$today."
".$HTTP_USER_AGENT." - ".$ip."

Map: http://soft.zoneo.net/phpTrafficA/mapIP.php?ip=".$ip."
-------------------------------------------------------------------------
";
mail("$SiteEmail", "WWW Form Submission", $AdminMessage, "From: $Email");

echo <<<EOD
<table width="745" border="0" cellspacing="0" cellpadding="0" align="center" height="127">
<tr>
<td width="6" height="6" align="left" valign="bottom"><img src="images/line3_1.gif" width="6" height="6"></td>
<td background="images/line3_1_bg.gif" width="731" height="6"></td>
<td width="8" height="6" align="right" valign="bottom"><img src="images/line3_2.gif" width="8" height="6"></td>
</tr>
<tr>
<td style="border-left:1px solid #ADADAD; " width="5" height="112">&nbsp;</td>
<td align="center" width="740" height="125" style="border:1px solid #fafafa; ">
Thank you $Name for sending us your message.<br>
We have received your message.<br>
We will contact you shortly.<br>
Good Bye !!!<br><br>
</td>
<td background="images/line3_2_line.gif" width="8" height="112">&nbsp;</td>
</tr>
<tr>
<td width="6" height="9" align="left" valign="bottom">
<img src="images/line3_4.gif" width="6" height="9"></td>
<td background="images/line3_4_bg.gif" width="731" height="9"></td>
<td width="8" height="9" align="right" valign="bottom">
<img src="images/line3_3.gif" width="8" height="9"></td>
</tr>
</table>
<br><br><br>

EOD;

}

} //else submitted



function showForm()
{
$_POST['message'] = @htmlspecialchars(@$_POST['message']);

echo <<<EOD
<form action="http://www.virginmaryexports.com/index.php?page=form" onSubmit="return validateForm(contact);" name="contact" method="POST">
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="left" valign="bottom"><img src="images/line3_1.gif" width="6" height="6"></td>
<td background="images/line3_1_bg.gif"></td>
<td align="right" valign="bottom"><img src="images/line3_2.gif" width="8" height="6"></td>
</tr>
<tr>
<td style="border-left:1px solid #ADADAD; ">&nbsp;</td>
<td align="center" style="border:1px solid #fafafa;">

<TABLE border="0" width="721" cellspacing="0">
<TBODY>
<TR>
<TD BGCOLOR="#ECF0F8" width="139" align="left"><B>Full Name:</B></TD>
<TD BGCOLOR="#ECF0F8" width="274"><INPUT type="text" class="inputstyle" name="Name" size="42" value="{$_POST['Name']}"></TD>
<TR>
<TD width="139" align="left"><B>Email:</B></TD>
<TD width="274"><INPUT type="text" class="inputstyle" name="Email" size="42" value="{$_POST['Email']}"></TD>
<TR>
<TD BGCOLOR="#ECF0F8" width="139" align="left"><B>Company:</B></TD>
<TD BGCOLOR="#ECF0F8" width="274"><INPUT class="inputstyle" type="text" name="Company" size="42" value="{$_POST['Company']}"></TD>
<TR>
<TD BGCOLOR="#FFFFFF" width="139" align="left"><B>Website:</B></TD>
<TD BGCOLOR="#FFFFFF" width="274"><INPUT class="inputstyle" type="text" name="Website" size="42" value="{$_POST['Website']}"></TD>
<TR>
<TD bgcolor="#ECF0F8" width="139" align="left"><B>Address:</B></TD>
<TD bgcolor="#ECF0F8" width="274"><INPUT type="text" class="inputstyle" name="Address" size="42" value="{$_POST['Address']}"></TD>
<TR>
<TD bgcolor="#FFFFFF" width="139" align="left"><B>City/State/ZIP:</B></TD>
<TD bgcolor="#FFFFFF" width="274"><INPUT size="12" class="inputstyle" type="text" name="City" value="{$_POST['City']}"> <INPUT type="text" size="12" class="inputstyle" name="State" value="{$_POST['State']}"> <INPUT type="text" class="inputstyle" size="12" name="Zip" value="{$_POST['Zip']}"></TD>
<TR>
<TD BGCOLOR="#ECF0F8" width="139" align="left"><B>Country:</B></TD>
<TD BGCOLOR="#ECF0F8" width="274"><INPUT type="text" class="inputstyle" name="Country" size="42" value="{$_POST['Country']}"></TD>
<TR>
<TD BGCOLOR="#FFFFFF" width="139" align="left"><B>Phone Number:</B></TD>
<TD BGCOLOR="#FFFFFF" width="274"><INPUT type="text" class="inputstyle" name="Phone" size="42" value="{$_POST['Phone']}"></TD>
<TR>
<TD BGCOLOR="#ECF0F8" width="139" align="left"><B>Fax:</B></TD>
<TD BGCOLOR="#ECF0F8" width="274"><INPUT type="text" class="inputstyle" name="Fax" size="42" value="{$_POST['Fax']}"></TD>
<TR>
<TD BGCOLOR="#FFFFFF" colSpan=3 width="742"><B>Type your message here:</B><font size="2"><BR>
<TEXTAREA name="Comments" rows="25" cols="112">{$_POST['Comments']}</TEXTAREA></TR>
<TR>
<TD BGCOLOR="#FFFFFF" width="139" align="left"><B>Verification:</B></TD>
<TD BGCOLOR="#FFFFFF" colSpan=3 width="742"><B><br>Type the numbers you see in the picture below.</B><br><img src="security/securimage_show.php"><br><br><INPUT TYPE="TEXT" name="imagetext" size="10" class="inputstyle"><br></TD></TR>
<TR>
<TD colSpan=2 bgcolor="#FFFFFF" width="613"><br><INPUT class="input" type="submit" name="submit" value="Send Form"> <input class="input" type="reset" value="Reset" name="B2"><br><br></TD></TR>
</TBODY>
</TABLE>
</td>
<td background="images/line3_2_line.gif">&nbsp;</td>
</tr>
<tr>
<td align="left" valign="bottom"><img src="images/line3_4.gif" width="6" height="9"></td>
<td background="images/line3_4_bg.gif"></td>
<td align="right" valign="bottom"><img src="images/line3_3.gif" width="8" height="9"></td>
</tr>
</table>
</form>
<br><br>


EOD;
}

?>

michael879
09-24-2007, 08:38 PM
its because you have register globals turned off. At some point they changed the default. Anyway, theres two solutions.

1) go into your php.ini file and turn register_globals to on. This method is insecure tho and my advice is to keep it off.

2) Replace any call to $SomethingFromForm with $_POST['SomethingFromForm']

register globals basically puts all the POST variables into the local scope. You take advantage of this when you compose the admin message. Thats the only placed I noticed you doing it so you should be fine if you just use $_POST.

for more info:
http://us.php.net/register_globals

saud
09-24-2007, 08:56 PM
Thanks

It worked, I had to define all the variables

$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Company = $_POST['Company'];
$Website = $_POST['Website'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$Country = $_POST['Country'];
$Phone = $_POST['Phone'];
$Fax = $_POST['Fax'];
$Comments = $_POST['Comments'];

michael879
09-24-2007, 09:02 PM
yea its good to do it that way. I just remembered why register globals are a security risk. Its because anyone can insert any variable into your script with $_GET. just doing script.php?admin_access=true makes $admin_access="true". You could see how that could be a problem.