Jump to content

richnb1974

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

richnb1974's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi Guys, Im a bit of a novice to Php but somehow I've managed to get myself a form together for customers to book online. My problem is that i need to validate all the input's of my form. To give you some idea of what i mean. The $name should only contain letters and be no longer than 25 characters. The $address should only contain letters & numbers and be no longer than 40 characters. The $district and $town should only contain letters and be no longer than 30 characters each. The $postcode should only contain letters and Numbers and be no longer than 8 characters, it should start and end with a letter if thats possible. The $phone should only contain numbers and be no longer than 11 characters. And the email, well im lost with how that should be set out because of all the different options you can have. Anyway, this is my code: <?php $to = 'myemail.com' ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $phone = $_REQUEST['Phone']; $headers = "From: $from"; $subject = "Booking Request"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Address"} = "Address"; $fields{"District"} = "District"; $fields{"Town"} = "Town"; $fields{"Postcode"} = "Postcode"; $fields{"Phone"} = "Phone"; $fields{"Email"} = "Email"; $fields{"list"} = "Mailing List"; $fields{"Message"} = "Message"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } if ($name == '') {print "You have not entered a name, please go back and try again";} elseif ($phone == '') {print "You have not entered a Phone number, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); if($send) {header( "Location: http://www.(not applicable).com" );} else {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } } ?> Any help is greatly apprecaited. Kind regards Rich
  2. I got the following code from About.com and adjusted it to suit my needs, but even though it sends my emails perfectly well, it also shows an error message after the email has sent. <html><body><font face=Arial size=2> <form method="post" action="contact.php"> <table bgcolor=#ffffcc align=center> <tr><td colspan=2><strong>Contact us using this form:</strong></td></tr> <tr><td>Department:</td><td><select name="sendto"> <option value="info@mycompany.com">General</option> <option value="support@mycompany.com">Support</option> <option value="sales@mycompany.com">Sales</option> </select></td></tr> <tr><td><font color=red>*</font> Name:</td><td><input size=25 name="Name"></td></tr> <tr><td><font color=red>*</font> Email:</td><td><input size=25 name="Email"></td></tr> <tr><td>Company:</td><td><input size=25 name="Company"></td></tr> <tr><td>Phone:</td><td><input size=25 name="Phone"></td></tr> <tr><td>Subscribe to<br> mailing list:</td><td><input type="radio" name="list" value="No"> No Thanks<br> <input type="radio" name="list" value="Yes" checked> Yes, keep me informed<br></td></tr> <tr><td colspan=2>Message:</td></tr> <tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr> <tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr> <tr><td colspan=2 align=center><small>A <font color=red>*</font> indicates a field is required</small></td></tr> </table> </form> </body> </html>
  3. Hi guys, I have a booking form on my website for potential customers to request a booking. The form asks for their Name, Address, Email and Tel No. I need the code to be able to send the form by Php. I also need it to show an error message if they haven't completed any of the fields. The fields on my form are: Name, Address, District, City, Postcode, Tel No, Email. Please help.
  4. Hi Pikachu, Thanks for the response. Unfortunately it is still doing the same thing and echoing both of the error messages after the email has been sent. I receive the emails perfectly well, even though there are error messages. It definitely seems to be the if($from =='') statement which isn't functionong properly. Thanks anyway. Any other suggestions are welcomed. Rich
  5. Hi guys, Please help me sort this annoying problem. Im new to the forum and quite new to Php.. weren't we all? My problem is, i have this code set up to send a form. However, when the form is completed and submitted it returns the error message i have written saying no email has been completed. The funny thing is though...it sends the email. this is my code: <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "Booking Request"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Address"} = "Address"; $fields{"District"} = "District"; $fields{"Town"} = "Town"; $fields{"Postcode"} = "Postcode"; $fields{"Phone"} = "Phone"; $fields{"Email"} = "Email"; $fields{"list"} = "Mailing List"; $fields{"Message"} = "Message"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: noreply@YourCompany.com"; $subject2 = "Thank you for contacting us"; if($from == '') {echo "You have not entered an email, please go back and try again";} else { if($name == '') {echo "You have not entered your name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); if($send) {header( "Location: http://www.21stcenturyportraits.com/emailresponse.php" );} else {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } } } ?> As I said, the problem seems to be with my If statements, even though I enter an email address it shows my error message. Regards Rich
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.