Jump to content

xhtml form validation


orr16875

Recommended Posts

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr"> <head> <title>In Home Estimate</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript"> <!-- function validate() { if(document.f1.FirstName.value=="") { alert("Please enter your first name"); document.f1.FirstName.focus(); return false; } { else(if(document.f1.City.value=="") alert("Please enter City"); document.f1.City.focus(); return false; } else(if(document.f1.HomePhone.value=="") { alert("Please enter home phone number"); document.f1.HomePhone.focus(); return false; } else(if(document.f1.eMail.value=="") { alert("Please fill in email address"); document.forms.f1.eMail.focus(); return false; } else(if(document.f1.eMail.value.indexOf('@')=='-1' || document.f1.eMail.value.indexOf('.')=='-1' || document.f1.eMail.value.indexOf(' ')!='-1') { alert("Please check your email address"); document.f1.eMail.focus(); return false; } else return true;}//--> </script> </head> <body><span style="position:absolute; top:160px; left:310px; font-family:Century Gothic, Arial Rounded MT Bold; font-size:18pt; font-weight:bolder; color:gray;">Project Type: AC</span><span style="position:absolute; left:280px; top: 192px;"><form method="get" name="f1" id="f1" action="mailto:info@inhomeestimates.com" onsubmit="return validate();" enctype="text/plain"> <table width="50%"><tr><td><strong>First Name</strong></td><td><input type="text" name="FirstName" id="FirstName" size="15" maxlength="15" /></td></tr><tr><td><strong>City</strong></td><td><input type="text" name="City" id="City" size="15" maxlength="25" /></td></tr><tr><td><strong>Home Phone</strong></td><td><input type="text" name="HomePhone" id="HomePhone" size="15" maxlength="15" /></td></tr><tr><td><strong>Email</strong></td><td><input type="text" name="eMail" id="eMail" size="15" maxlength="30" /></td></tr><tr><td colspan="2" width="50%" align="center"><button type="submit" /><strong>Get Estimates!</strong><button type="reset" />Reset Form</td></tr> </table></form> </span></body></html>

Link to comment
Share on other sites

well it's only on my laptop, hasn't been published yet, but the errors are:1. when the page uploads, window popup error: Line: 20 Char: 3 Error: Syntax error2. when i click "submit", popup error: Line: 61 Char: 1 Error: Object expectedthen it offers to send the form thru email.

Link to comment
Share on other sites

This is where your syntax error is:return false;}{else(if(document.f1.City.value=="")alert("Please enter City");That else doesn't correspond to an if.Although how "Line: 20 Char: 3" references that, I have no clue. IE seems to enjoy putting some internally-generated line and character numbers in its error messages. You would be able to get a much more helpful error message if you were using Opera to test this instead of IE. The second error probably relates to the first, since there is a syntax error in the validate function, later on when you try to execute validate it hasn't been defined due to the error. Also, you may want to change this:<button type="submit" /><strong>Get Estimates!</strong><button type="reset" />to this:<input type="submit" /><strong>Get Estimates!</strong><input type="reset" />

Link to comment
Share on other sites

To check Javascript errors in Opera, you can go to Tools -> Advanced -> Error Console.If you want to send email yourself (which you should, ideally) instead of having the user send the email, you will need to use a scripting language like PHP or ASP to send it. The first step is to check with whoever hosts your server and figure out what is available for you to use.

Link to comment
Share on other sites

first, thank you for helping me :)now i've wrote a mail.php file and i'm trying to send the form thru it. i don't get any errors any more... but since i did it, i don't get the form to the email, and the user should get a "thankyou.html" page but i get a blank page instead. how should i do the "thankyou.html" page.there is the mail.php code:<html><body><? php$to = "info@inhomeestimates.com";$subject= $_REQUEST['Project:'];$headers .= 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";$Date = $_REQUEST['Date'];$Project: = $_REQUEST['Project:'];$Description = $_REQUEST['Description'];$schedule = $_REQUEST['schedule'];$FirstName = $_REQUEST['FirstName'];$LastName = $_REQUEST['LastName'];$Address = $_REQUEST['Address'];$City = $_REQUEST['City'];$State = $_REQUEST['State'];$Zip = $_REQUEST['Zip'];$HomePhone = $_REQUEST['HomePhone'];$WorkPhone = $_REQUEST['WorkPhone'];$Cell = $_REQUEST['Cell'];$email = $_REQUEST['eMail'];$Estimates = $_REQUEST['Estimates'];$Budget = $_REQUEST['Budget'];$Advertising = $_REQUEST['Advertising'];$agree = $_REQUEST['agree'];mail("$to, $subject:, "from: $eMail");header("Location: http://www.inhomeestimates.com/thankyou.html");?>

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...