PDA

View Full Version : PHP FORM Problem


levski
11-18-2005, 02:01 PM
am working on a modified php code for a form that i want to look something like this:
http://www.gravitatedesign.com/contact-us.htm

now i modified my form to make it simplerr. here's my form so you can check it our for yourself:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link href="text.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-color: #ECECEC;
}
-->
</style></head>

<body>
<table width="319" height="248" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="319" height="248" valign="top" class="body11"><table width="319" height="267" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="110" height="22" valign="top">*First Name </td>
<td width="209"><form name="form1" method="post" action="sendmail.php">
<input name="first" type="text" class="body11" id="first" maxlength="20">
</form></td>
</tr>
<tr>
<td height="22" valign="top">*Last Name</td>
<td><form action="sendmail.php" method="post" name="form2" class="body11">
<input name="last" type="text" class="body11" id="last" maxlength="20">
</form></td>
</tr>
<tr>
<td height="14" valign="top">*Telephone</td>
<td><form name="form3" method="post" action="sendmail.php">
<input name="phone" type="text" class="body11" id="phone" maxlength="20">
</form></td>
</tr>
<tr>
<td height="14" valign="top">*E-Mail</td>
<td><form name="form4" method="post" action="sendmail.php">
<input name="mail" type="text" class="body11" id="mail" maxlength="30">
</form></td>
</tr>
<tr>
<td height="14" valign="top">*Business Type </td>
<td><form name="form5" method="post" action="sendmail.php">
<input name="business" type="text" class="body11" id="business">
</form></td>
</tr>
<tr>
<td height="14" valign="top">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="118" valign="top"> *Additional<br>
Information</td>
<td valign="top"><form name="form6" method="post" action="sendmail.php">
<textarea name="info" cols="35" rows="7." class="body11" id="info"></textarea>
</form></td>
</tr>
<tr>
<td height="31" valign="top">&nbsp;</td>
<td valign="bottom"><form name="form7" method="post" action="sendmail.php">
<input name="submit" type="submit" id="submit" value="Submit">
</form></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>


now the form is pretty standard so i took up a basic form PHP and started adding the fields and modifying the validation relative to the fields. here's what i came up with:

<?
// ------------- CONFIGURABLE SECTION ------------------------

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto = "youremailaddress@example.com" ;

$mailto = 'info@burnt-out-lights.com' ;

// $subject - set to the Subject line of the email, eg
//$subject = "Feedback Form" ;

$subject = "Inquiry" ;

// the pages to be displayed, eg
//$formurl = "http://www.example.com/feedback.html" ;
//$errorurl = "http://www.example.com/error.html" ;
//$thankyouurl = "http://www.example.com/thankyou.html" ;

$formurl = "http://burnt-out-lights.com/frame_contact.html" ;
$errorurl = "http://burnt-out-lights.com/error.html" ;
$thankyouurl = "http://burnt-out-lights.com/tnx.html" ;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$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 ;
}
$name = strtok( $name, "\r\n" );
$email = strtok( $email, "\r\n" );
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>\r\nReply-To: \"$name\" <$email>\r\nX-Mailer: chfeedback.php 2.04" );
header( "Location: $thankyouurl" );
exit ;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link href="text.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-color: #ECECEC;
}
-->
</style></head>

<body>
<table width="319" height="248" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="319" height="248" valign="top" class="body11"><table width="319" height="267" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="110" height="22" valign="top">*First Name </td>
<td width="209"><form name="form1" method="post" action="<?=$PHP_SELF;?>">
<input name="first" type="text" class="body11" id="first" maxlength="20">
</td>
</tr>
<tr>
<td height="22" valign="top">*Last Name</td>
<td><form action="" method="post" name="form2" class="body11">
<input name="last" type="text" class="body11" id="last" maxlength="20">
</td>
</tr>
<tr>
<td height="14" valign="top">*Telephone</td>
<td><form name="form3" method="post" action="">
<input name="phone" type="text" class="body11" id="phone" maxlength="20">
</td>
</tr>
<tr>
<td height="14" valign="top">*E-Mail</td>
<td><form name="form4" method="post" action="">
<input name="mail" type="text" class="body11" id="mail" maxlength="30">
</td>
</tr>
<tr>
<td height="14" valign="top">*Business Type </td>
<td><form name="form5" method="post" action="">
<input name="business" type="text" class="body11" id="business">
</td>
</tr>
<tr>
<td height="14" valign="top">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="118" valign="top"> *Additional<br>
Information</td>
<td valign="top"><form name="form6" method="post" action="">
<textarea name="info" cols="35" rows="7." class="body11" id="info"></textarea>
</td>
</tr>
<tr>
<td height="31" valign="top">&nbsp;</td>
<td valign="bottom">
<input name="submit" type="submit" id="submit" value="Submit">
</form>
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>

the result: pressing the submit button produces no errors nor email sent to designated email neither does it show the message sent html.

i guess the it's either in the form or the script. most likely the script as this is my 1st php project.

:stupid:

please advice.

Kalessin
11-18-2005, 02:46 PM
The problem isn't strictly the form, it's the fact that you have a separate form for every field. You should have all the fields enclosed within only one form tag.

Kal

levski
11-18-2005, 02:51 PM
The problem isn't strictly the form, it's the fact that you have a separate form for every field. You should have all the fields enclosed within only one form tag.

Kal

ok. i'll try that.
i did the form using dreamweaver so i rarely read the code.

thanx for pointing that out.