views:

48

answers:

1

Hi Can anyone suggest a quick form script for a php form? I generated the one below from telepro and modified the html and emails a bit, but I get this error for the checkbox

Parse error: syntax error, unexpected '=' in /home/inn.co.uk/public/mailer.php on line 14

thanks for your help

Regards Judi

     <form method="POST" action="contact.php">

<div class="form-field">
  <input type="text" name="Name" onFocus="if(this.value=='Name')this.value='';" value="Name">
</div>
 <div class="form-field">
  <input type="text" name="Telephone" onFocus="if(this.value=='Telephone')this.value='';" value="Telephone">
</div>
<div class="form-field">
  <input type="text" name="Timetocall" onFocus="if(this.value=='Time to call')this.value='';" value="Time to call">
  </div>
<div class="form-field">
                <ul class="tickboxes">
                                      <li>Do you agree to our<br/><a href="terms-and-conditions.html">Terms of Business </a><input type="checkbox" name="DoyouagreetoourTermsofBusiness?" value="Yes" /></li></ul></div>




            <div class="button">
              <input type="image" src="images/submit.jpg" value="" name="submit">
            </div>
     </form>

<?php
// Website Contact Form Generator 
// http://www.tele-pro.co.uk/scripts/contact_form/ 
// This script is free to use as long as you  
// retain the credit link  

// get posted data into local variables
$EmailFrom = "[email protected]";
$EmailTo = "[email protected]";
$Subject = "New enquiry";
$Name = Trim(stripslashes($_POST['Name'])); 
$Telephone = Trim(stripslashes($_POST['Telephone'])); 
$Timetocall = Trim(stripslashes($_POST['Timetocall'])); 
$DoyouagreetoourTermsofBusiness? = Trim(stripslashes($_POST['DoyouagreetoourTermsofBusiness?'])); 

// validation
$validationOK=true;
if (Trim($Name)=="") $validationOK=false;
if (Trim($Telephone)=="") $validationOK=false;
if (Trim($Timetocall)=="") $validationOK=false;
if (Trim($DoyouagreetoourTermsofBusiness?)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "Timetocall: ";
$Body .= $Timetocall;
$Body .= "\n";
$Body .= "DoyouagreetoourTermsofBusiness?: ";
$Body .= $DoyouagreetoourTermsofBusiness?;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
+2  A: 

You are using a question mark in your variable name. That doesn't work.

See the PHP Manual on variables for naming conventions.

replace

$DoyouagreetoourTermsofBusiness?

by

$DoyouagreetoourTermsofBusiness

and it will work fine.

Pekka
Also replace that in name value in your form.
Adam Kiss
Thanks Adam, I did everything you said but when i click send i get this message even though I've ticked the check box - You must agree to our Terms of Business. Please click here to return to the form
judi
Did you remove it from the stripslashes() call as well?
Pekka
Nope? Do I need to?
judi
I mean the question mark. The name needs to be the same everywhere, in both the HTML and the PHP file. THere must be no occurrence of DoyouagreetoourTermsofBusiness? (with the question mark) left.
Pekka
Thanks yeh I did take out the question mark, but i still get this message
judi
Thanks it works now I just have to wait for the message to come through :)
judi
You're welcome. If it doesn't come through, read this: http://stackoverflow.com/questions/1892409/php-mail-problem/1967637#1967637 :)
Pekka