Jump to content

Form Errors


PHPJack77

Recommended Posts

I have a form that was working fully, however I am now trying to make it submit the data to the same page as the form for error handleing and am now getting an error on line 145. The origional code on line 145 was this...

<form action="contactformhandler.php" method="post">

which I changed to...

$form ="<form action=\"$_SERVER['PHP_SELF']\" method=\"post\">";

and am now getting the error...

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 145

Can anyone tell me what this means, and how to fix the error? Thanks!!

Link to comment
Share on other sites

You can change this:<form action="contactformhandler.php" method="post">to this:<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">Or else like they said, the error is happening on a different line so we would need at least 10 or so lines before the one that is indicated.

Link to comment
Share on other sites

Here is the full php code... Thanks for your help :)

<?php      $firstname = $_POST['firstname'];      $lastname = $_POST['lastname'];      $phonenumber = $_POST['phonenumber'];      $email = $_POST['email'];      $street = $_POST['street'];      $city = $_POST['city'];      $state = $_POST['state'];      $zip = $_POST['zip'];      $questcomment = $_POST['questcomment'];      $sent = $_POST['sent'];      $form ="<form action=\"$_SERVER['PHP_SELF']\" method=\"post\">";#<!-- Nested Form Table 1 -->      $form .="<table>";       $form .="<tr>";        $form .="<td>*First Name</td> <td>Last Name</td>";       $form .="</tr>";       $form .= "<tr>";        $form .= "<td><input name=\"firstname\" type=\"text\" size=\"12\" maxlength=\"12\" class=\"formstyle\"/></td>";        $form .= "<td><input name=\"lastname\" type=\"text\" size=\"12\" maxlength=\"12\" class=\"formstyle\"/></td>";       $form .= "</tr>";      $form .= "</table>";#<!-- End of Nested Table 1 -->#<!-- Nested Form Table 2 -->      $form .= "<table>";       $form .= "<tr>";        $form .= "<td>Phone Number</td>";       $form .= "</tr>";       $form .= "<tr>";        $form .= "<td><input name=\"phonenumber\" type=\"text\" size=\"12\" maxlength=\"12\" class=\"formstyle\"/></td>";       $form .= "</tr>";       $form .= "<tr>";        $form .= "<td>*Email:</td>";       $form .= "</tr>";       $form .= "<tr>";        $form .= "<td><input name=\"email\" type=\"text\" size=\"35\" class=\"formstyle\"/></td>";       $form .= "</tr>";       $form .= "<tr>";        $form .= "<td>Address (optional):</td>";       $form .= "</tr>";       $form .= "<tr>";        $form .= "<td><input name=\"street\" type=\"text\" size=\"35\" class=\"formstyle\"/></td>";       $form .= "</tr>";      $form .= "</table>";#<!-- End of Nested Table 2 -->#<!-- Nested Form Table 3 -->      $form .= "<table>";       $form .= "<tr>";        $form .= "<td>City/State/Zip:</td>";       $form .= "</tr>";       $form .= "<tr>";        $form .= "<td><input name=\"city\" type=\"text\" size=\"18\" class=\"formstyle\"/></td>";        $form .= "<td><input name=\"state\" type=\"text\" size=\"2\" maxlength=\"2\" class=\"formstyle\"/></td>";        $form .= "<td><input name=\"zip\" type=\"text\" size=\"5\" maxlength=\"5\" class=\"formstyle\"/></td>";       $form .= "</tr>";      $form .= "</table>";#<!-- End of Nested Table 3 -->#<!-- Nested Form Table 4 -->      $form .= "<table>";       $form .= "<tr>";        $form .= "<td>*Questions and/or Comments:</td>";       $form .= "</tr>";       $form .= "<tr>";        $form .= "<td><textarea name=\"questcomment\" rows=\"7\" cols=\"35\" class=\"formstyle\"></textarea></td>";       $form .= "</tr>";       $form .= "<tr>";        $form .= "<td align=\"right\"><input name=\"submit\" type=\"submit\" value=\"Submit...\" class=\"submitbtn\"/></td>";       $form .= "</tr>";      $form .= "</table>";#<!-- End of Nested Table 4 -->      $form .= "</form>";      $form .= "<h3>*Required Field</h3>";      if($sent)      { $valid=true;        if( !$firstname )	{ $errormsg .= "Please enter your first name <br />"; $valid = false; }        #if( !$lastname )	#{ $errormsg .= "Please enter your last name <br />"; $valid = false; }        #if( !$phonenumber )	#{ $errormsg .= "Please enter your phone number <br />"; $valid = false; }        if( !$email )	{ $errormsg .= "Please enter your e.mail address <br />"; $valid = false; }        else        {         $email = trim( $email );         $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+";         $_host = "([-0-9A-Z]+\.)+";         $_tlds = "(0-9A-Z]) {2,4}$/i";         if( !preg_match($_name."@".$_host.$_tlds,$email) )         {          $errormsg .= "Please correct the format of your e.mail address <br />";          $valid = false;         }        #if( !$street )	#{ $errormsg .= "Please enter your address <br />"; $valid = false; }        #if( !$city )	#{ $errormsg .= "Please enter your city <br />"; $valid = false; }        #if( !$state )	#{ $errormsg .= "Please enter your state <br />"; $valid = false; }        #if( !$zip )	#{ $errormsg .= "Please enter your zip code <br />"; $valid = false; }        if( !$questcomment )	{ $errormsg .= "Please enter your question or comment <br />"; $valid = false; }      }}      if (!$valid)      { echo( $errormsg . "<br /><br />" . $form ); }      else      {       $to = "sampleemail@sampledomain.com";    $subject = "Question-Comment from a website user";       $message = "<b>Name:</b>" . $firstname . " " . $lastname . "<br /><br />";       $message .="<b>Phone Number:</b>" . $phonenumber . "<br /><br />";       $message .="<b>Email Address:</b>" . $email . "<br /><br />";       $message .="<b>Address:</b> <br />" . $street . "<br />";       $message .=$city . ", " . $state . "  " . $zip . "<br /><br />";       $message .="<b>Question/Comment:</b>" . $questcomment;       $headers="MIME-Version: 1.0\r\n";       $headers.="Content-type: text/html;";       $headers.=" Charset=iso-8859-1 \r\n";       $headers.="From: $email \r\n";       if( mail ($to, $subject, $message, $headers) )       { echo("Thanks for the feedback!  If a responce is necessary, you can expect to hear from us within 24 - 48 hours."); }      }    ?>

Link to comment
Share on other sites

I should have caught that. If you use an array variable inside a string (or, if you want to be nice and consistent, any variable), then surround it with curly brackets:$form ="<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">";

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...