Jump to content

Form Validation & Submission


irishpeck
 Share

Recommended Posts

Hi Guys,

 

I have a form on a website http://www.wewillbuyyourcar.ie/sellyourcar.html. This form has several fields and all fields need to be submitted to a designated email address on submission. To be honest im not sure where im at with it i cant get it to submit so i need some help to validate it and submit and then maybe display a html page to the user like thankyou.html. Heres the code needed.

 

This is the form

<div id="contact_form">
					  <form id="contact" action="process.php">
						<fieldset>


<TR><TD><TABLE BORDER="0" CELLPADDING="3" CELLSPACING="0" WIDTH="50%">

<FORM ACTION="" METHOD="post" name="sellcarform" onsubmit="" >
<TR><TD CLASS="tableBlueBody" ALIGN="right">* <B>First Name</B></TD><TD CLASS="tableBlueBody" STYLE="border-right : 1px solid #CCCCCC;" ALIGN="left"><INPUT  TYPE="Text" NAME="firstname" MAXLENGTH="150"></TD><TD CLASS="tableBlueBody" ALIGN="right">* <B>Last Name</B></TD><TD CLASS="tableBlueBody" ALIGN="center"><INPUT TYPE="Text" NAME="lastname"  MAXLENGTH="150"></TD></TR>
<TR><TD CLASS="tableBlueBody" ALIGN="right"><B>Address</B></TD><TD CLASS="tableBlueBody" STYLE="border-right : 1px solid #CCCCCC;" ALIGN="left"><INPUT TYPE="Text" NAME="AddressLine1" MAXLENGTH="150"></TD><TD CLASS="tableBlueBody" ALIGN="right">* <B>Email</B></TD><TD CLASS="tableBlueBody" ALIGN="center"><INPUT TYPE="Text" NAME="email" MAXLENGTH="150"></TD></TR>
<TR><TD CLASS="tableBlueBody" ALIGN="right"><B>City</B></TD><TD CLASS="tableBlueBody" STYLE="border-right : 1px solid #CCCCCC;" ALIGN="left"><INPUT TYPE="Text" NAME="City" MAXLENGTH="150"></TD><TD CLASS="tableBlueBody" ALIGN="right">* <B>Phone</B></TD><TD CLASS="tableBlueBody" ALIGN="center"><INPUT TYPE="Text" NAME="phone" MAXLENGTH="150"></TD></TR>
<TR><TD CLASS="tableBlueBody" ALIGN="right"><B>Country</B></TD><TD CLASS="tableBlueBody" STYLE="border-right : 1px solid #CCCCCC;" ALIGN="left">


<select name="CountryID">

	<option value="1"

	>Albania</option>

	<option value="2"

	>Algeria</option>

	<option value="3"

	>American Samoa</option>

	<option value="4"

	>Andorra</option>

	<option value="5"

	>Anguilla</option>

	<option value="6"

	>Antartica</option>

	<option value="7"

	>Antigua & Barbuda</option>

	<option value="8"

	>Argentina</option>

	<option value="9"

	>Armenia</option>

	<option value="10"

	>Aruba</option>

	<option value="11"

	>Australia</option>

	<option value="12"

	>Austria</option>

	<option value="13"

	>Azerbaijan</option>

	<option value="14"

	>Bahamas</option>

	<option value="15"

	>Bahrain</option>

	<option value="16"

	>Bangladesh</option>

	<option value="17"

	>Barbados</option>

	<option value="18"

	>Belarus</option>

	<option value="19"

	>Belgium</option>

	<option value="20"

	>Belize</option>

	<option value="21"

	>Benin</option>

	<option value="22"

	>Bermuda</option>

	<option value="23"

	>Bhutan</option>

	<option value="24"

	>Bolivia</option>

	<option value="25"

	>Botswana</option>

	<option value="26"

	>Bouvet Island</option>

	<option value="27"

	>Brazil</option>

	<option value="28"

	>British Indian Ocean Terr.</option>

	<option value="29"

	>Brunei Darussalam</option>

	<option value="30"

	>Bulgaria</option>

	<option value="31"

	>Burkina Faso</option>

	<option value="32"

	>Burundi</option>

	<option value="33"

	>Cambodia</option>

	<option value="34"

	>Cameroon</option>

	<option value="35"

	>Canada</option>

	<option value="36"

	>Cape Verde</option>

	<option value="37"

	>Cayman Islands</option>

	<option value="38"

	>Central African Republic</option>

	<option value="39"

	>Chad</option>

	<option value="40"

	>Chile</option>

	<option value="41"

	>China</option>

	<option value="42"

	>Christmas Island</option>

	<option value="43"

	>Cocos (Keeling) Isl</option>

	<option value="44"

	>Colombia</option>

	<option value="45"

	>Comoros</option>

	<option value="46"

	>Congo</option>

	<option value="47"

	>Cook Isl</option>

	<option value="48"

	>Costa Rica</option>

	<option value="49"

	>Cote D'Ivoire</option>

	<option value="50"

	>Croatia</option>

	<option value="51"

	>Cyprus</option>

	<option value="52"

	>Czech Republic</option>

	<option value="53"

	>Denmark</option>

	<option value="54"

	>Djibouti</option>

	<option value="55"

	>Dominica</option>

	<option value="56"

	>Dominican Republic</option>

	<option value="57"

	>East Timor</option>

	<option value="58"

	>Ecuador</option>

	<option value="59"

	>Egypt</option>

	<option value="60"

	>El Salvador</option>

	<option value="61"

	>Equatorial Guinea</option>

	<option value="62"

	>Estonia</option>

	<option value="63"

	>Ethiopia</option>

	<option value="64"

	>Faeroe Islands</option>

	<option value="65"

	>Falkland Isl. (Malvinas)</option>

	<option value="66"

	>Fiji</option>

	<option value="67"

	>Finland</option>

	<option value="68"

	>France</option>

	<option value="69"

	>French Guiana</option>

	<option value="70"

	>French Polynesia</option>

	<option value="71"

	>French Southern Terr.</option>

	<option value="72"

	>Gabon</option>

	<option value="73"

	>Gambia</option>

	<option value="74"

	>Georgia</option>

	<option value="75"

	>Germany</option>

	<option value="76"

	>Ghana</option>

	<option value="77"

	>Gibraltar</option>

	<option value="78"

	>Greece</option>

	<option value="79"

	>Greenland</option>

	<option value="80"

	>Grenada</option>

	<option value="81"

	>Guadeloupe</option>

	<option value="82"

	>Guam</option>

	<option value="83"

	>Guatemala</option>

	<option value="84"

	>Guernsey C.I.</option>

	<option value="85"

	>Guinea</option>

	<option value="86"

	>Guinea-Bissau</option>

	<option value="87"

	>Guyana</option>

	<option value="88"

	>Haiti</option>

	<option value="89"

	>Heard and McDonald Isl</option>

	<option value="90"

	>Honduras</option>

	<option value="91"

	>Hong Kong</option>

	<option value="92"

	>Hungary</option>

	<option value="93"

	>Iceland</option>

	<option value="94"

	>India</option>

	<option value="95"

	>Indonesia</option>

	<option value="96"
		selected			
	>Ireland</option>

	<option value="97"

	>Isle of Man</option>

	<option value="98"

	>Israel</option>

	<option value="99"

	>Italy</option>

	<option value="100"

	>Jamaica</option>

	<option value="101"

	>Japan</option>

	<option value="102"

	>Jersey C.I.</option>

	<option value="103"

	>Jordan</option>

	<option value="104"

	>Kazakhstan</option>

	<option value="105"

	>Kenya</option>

	<option value="106"

	>Kiribati</option>

	<option value="107"

	>Korea Republic of</option>

	<option value="108"

	>Kuwait</option>

	<option value="109"

	>Kyrgyzstan</option>

	<option value="110"

	>Laos</option>

	<option value="111"

	>Latvia</option>

	<option value="112"

	>Lebanon</option>

	<option value="113"

	>Lesotho</option>

	<option value="114"

	>Liberia</option>

	<option value="115"

	>Liechtenstein</option>

	<option value="116"

	>Lithuania</option>

	<option value="117"

	>Luxemborg</option>

	<option value="118"

	>Macau</option>

	<option value="119"

	>Madagascar</option>

	<option value="120"

	>Malawi</option>

	<option value="121"

	>Malaysia</option>

	<option value="122"

	>Maldives</option>

	<option value="123"

	>Mali</option>

	<option value="124"

	>Malta</option>

	<option value="125"

	>Marshall Isl</option>

	<option value="126"

	>Martinique</option>

	<option value="127"

	>Mauritania</option>

	<option value="128"

	>Mauritius</option>

	<option value="129"

	>Mexico</option>

	<option value="130"

	>Micronesia</option>

	<option value="131"

	>Moldova Republic of</option>

	<option value="132"

	>Monaco</option>

	<option value="133"

	>Mongolia</option>

	<option value="134"

	>Montserrat</option>

	<option value="135"

	>Morocco</option>

	<option value="136"

	>Mozambique</option>

	<option value="137"

	>Myanmar</option>

	<option value="138"

	>Namibia</option>

	<option value="139"

	>Nauru</option>

	<option value="140"

	>Nepal</option>

	<option value="141"

	>Netherland Antilles</option>

	<option value="142"

	>Netherlands</option>

	<option value="143"

	>New Caledonia</option>

	<option value="144"

	>New Zealand</option>

	<option value="145"

	>Nicaragua</option>

	<option value="146"

	>Niger</option>

	<option value="147"

	>Nigeria</option>

	<option value="148"

	>Niue</option>

	<option value="149"

	>Norfolk Isl</option>

	<option value="150"

	>Northern Mariana Isl</option>

	<option value="151"

	>Norway</option>

	<option value="152"

	>Oman</option>

	<option value="153"

	>Pakistan</option>

	<option value="154"

	>Palau</option>

	<option value="155"

	>Panama</option>

	<option value="156"

	>Panama Canal Zone</option>

	<option value="157"

	>Papua New Guinea</option>

	<option value="158"

	>Paraguay</option>

	<option value="159"

	>Peru</option>

	<option value="160"

	>Philippines</option>

	<option value="161"

	>Pitcairn</option>

	<option value="162"

	>Poland</option>

	<option value="163"

	>Portugal</option>

	<option value="164"

	>Puerto Rico</option>

	<option value="165"

	>Qatar</option>

	<option value="166"

	>Rest of World</option>

	<option value="167"

	>Reunion</option>

	<option value="168"

	>Romania</option>

	<option value="169"

	>Russian Federation</option>

	<option value="170"

	>Rwanda</option>

	<option value="171"

	>Saint Kitts & Nevis</option>

	<option value="172"

	>Saint Lucia</option>

	<option value="173"

	>Samoa</option>

	<option value="174"

	>San Marino</option>

	<option value="175"

	>Sao Tome & Principe</option>

	<option value="176"

	>Saudi Arabia</option>

	<option value="177"

	>Senegal</option>

	<option value="178"

	>Seychelles</option>

	<option value="179"

	>Sierra Leone</option>

	<option value="180"

	>Singapore</option>

	<option value="181"

	>Slovakia</option>

	<option value="182"

	>Slovenia</option>

	<option value="183"

	>Solomon Islands</option>

	<option value="184"

	>Somalia</option>

	<option value="185"

	>South Africa</option>

	<option value="186"

	>Spain</option>

	<option value="187"

	>Sri Lanka</option>

	<option value="188"

	>St. Helena</option>

	<option value="189"

	>St. Pierre and Miquelon</option>

	<option value="190"

	>St. Vincent & Grenadines</option>

	<option value="191"

	>Suriname</option>

	<option value="192"

	>Svalbard & Jan Mayen Isl</option>

	<option value="193"

	>Swaziland</option>

	<option value="194"

	>Sweden</option>

	<option value="195"

	>Switzerland</option>

	<option value="196"

	>Taiwan</option>

	<option value="197"

	>Tajikistan</option>

	<option value="198"

	>Tanzania United Republic</option>

	<option value="199"

	>Thailand</option>

	<option value="200"

	>Togo</option>

	<option value="201"

	>Tokelau</option>

	<option value="202"

	>Tonga</option>

	<option value="203"

	>Trinidad & Tobago</option>

	<option value="204"

	>Tunisia</option>

	<option value="205"

	>Turkey</option>

	<option value="206"

	>Turkmenistan</option>

	<option value="207"

	>Turks and Caicos Isl</option>

	<option value="208"

	>Tuvalu</option>

	<option value="209"

	>U.A.E.</option>

	<option value="210"

	>U.S.Minor Outlying Isl</option>

	<option value="211"

	>Uganda</option>

	<option value="212"

	>Ukraine</option>

	<option value="213"

	>United Kingdom</option>

	<option value="214"

	>United States</option>

	<option value="215"

	>Uruguay</option>

	<option value="216"

	>Uzbekistan</option>

	<option value="217"

	>Vanuatu</option>

	<option value="218"

	>Vatican City State</option>

	<option value="219"

	>Venezuela</option>

	<option value="220"

	>Viet Nam</option>

	<option value="221"

	>Virgin Isl (British)</option>

	<option value="222"

	>Virgin Isl (U.S.)</option>

	<option value="223"

	>Wallis & Futuna Islands</option>

	<option value="224"

	>Western Sahara</option>

	<option value="225"

	>Yemen Republic of</option>

	<option value="226"

	>Zaire</option>

	<option value="227"

	>Zambia</option>

	<option value="228"

	>Zimbabwe</option>

</select>




</TD><TD CLASS="tableBlueBody" ALIGN="right"><B>Fax</B></TD><TD CLASS="tableBlueBody" ALIGN="center"><INPUT TYPE="Text" NAME="fax" MAXLENGTH="150"></TD></TR>

<TR><TD COLSPAN="4" CLASS="tableBlueBody"> </TD></TR>
<TR><TD CLASS="tableBlueBody" ALIGN="right" VALIGN="top">


<B>Comments</B>





</TD><TD COLSPAN="3" CLASS="tableBlueBody" ALIGN="left">

<TEXTAREA NAME="comment" ROWS="7" COLS="45" ></TEXTAREA>


</TD></TR>

</TD><TD COLSPAN="5" CLASS="tableBlueBody" ALIGN="left">


<TR><TD CLASS="tableBlueBody" ALIGN="right">* <B>Registration Number</B></TD><TD CLASS="tableBlueBody" STYLE="border-right : 1px solid #CCCCCC;" ALIGN="left"><INPUT  TYPE="Text" NAME="regnumber" MAXLENGTH="150"></TD><TD CLASS="tableBlueBody" ALIGN="right">* <B>Colour</B></TD><TD CLASS="tableBlueBody" ALIGN="center"><INPUT TYPE="Text" NAME="colour"  MAXLENGTH="150"></TD></TR>
<TR><TD CLASS="tableBlueBody" ALIGN="right">* <B>Car Make</B></TD><TD CLASS="tableBlueBody" STYLE="border-right : 1px solid #CCCCCC;" ALIGN="left"><INPUT TYPE="Text" NAME="carmake" MAXLENGTH="150"></TD><TD CLASS="tableBlueBody" ALIGN="right">* <B>Has the vehicle been used as a taxi?</B></TD><TD CLASS="tableBlueBody" ALIGN="center"><input type='radio' value="Yes" name='question1' /> Yes <input name='question1' type="radio" value="No" checked /> No</TD></TR>
<TR><TD CLASS="tableBlueBody" ALIGN="right">* <B>Model</B></TD><TD CLASS="tableBlueBody" STYLE="border-right : 1px solid #CCCCCC;" ALIGN="left"><INPUT TYPE="Text" NAME="model" MAXLENGTH="150"></TD><TD CLASS="tableBlueBody" ALIGN="right">* <B>Is finance outstanding on the vehicle?</B></TD><TD CLASS="tableBlueBody" ALIGN="center"><input type='radio' value="Yes" name='question2' /> Yes <input name='question2' type="radio" value="No" checked /> No</TD></TR>
<TR><TD CLASS="tableBlueBody" ALIGN="right">* <B>Milage / Kms</B></TD><TD CLASS="tableBlueBody" STYLE="border-right : 1px solid #CCCCCC;" ALIGN="left"><INPUT TYPE="Text" NAME="milage" MAXLENGTH="150"></TD><TD CLASS="tableBlueBody" ALIGN="right">* <B>How did you hear about us?</B></TD><TD CLASS="tableBlueBody" ALIGN="center"><select name="question3"><option value="Other">Other</option><option value="Web">Web</option><option value="Newspaper">Newspaper</option><option value="Radio">Radio</option><option value="Recommended">Recommended</option></select></TD></TR>
<TR><TD COLSPAN="2" CLASS="tableBlueBody" STYLE="border-bottom : 1px solid #CCCCCC; border-right : 1px solid #CCCCCC;"> </TD><TD COLSPAN="2" CLASS="tableBlueBody" STYLE="border-bottom : 1px solid #CCCCCC;"> </TD></TR>



<TR><TD COLSPAN="4" ALIGN="left"><input type="submit" value="Click here to send us your information" class='contactFormSubmit'></TD></TR>
</FORM></TABLE>
</TD></TR></TABLE><BR></TD>
<TD><IMG SRC="images/spacer.gif" WIDTH="8" HEIGHT="1" BORDER="0" ALT=""></TD>
<TD WIDTH="183" VALIGN="top">
</TD></TR></TABLE>

						</fieldset>
					  </form><br />
				</div><!-- end of #contact_form -->

 

And then i have a file called process.php!

<?php 
$emailTo = 'sakura-designs@hotmail.com';
$subject = 'We Will Buy Your Car.ie Form Submission';
$firstname=$_REQUEST['firstname'];
$lastname=$_REQUEST['lastname'];
$email=$_REQUEST['email'];
$AddressLine1=$_REQUEST['AddressLine1'];
$City=$_REQUEST['City'];
$phone=$_REQUEST['phone'];
$CountryID=$_REQUEST['CountryID'];
$fax=$_REQUEST['fax'];
$comment=$_REQUEST['comment'];
$regnumber=$_REQUEST['regnumber'];
$colour=$_REQUEST['colour'];
$carmake=$_REQUEST['carmake'];
$question1=$_REQUEST['question1'];
$model=$_REQUEST['model'];
$question2=$_REQUEST['question2'];
$milage=$_REQUEST['milage'];
$question3=$_REQUEST['question3'];


$body = "First Name: $firstname \n\nLast Name: $lastname \n\nEmail: $email \n\nAddress: $AddressLine1 \n\nCity: $city \n\nPhone: $phone \n\nCountry: $CountryID \n\nFax: $fax \n\nComment: $comment \n\nReg Number: $regnumber \n\nColour: $colour \n\nCar Make: $carmake \n\nQuestion1: $question1 \n\nModel: $model \n\nQuestion2: $question2 \n\nMilage: $milage \n\nQuestion3: $question3";
$headers = 'From: '.$name.' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;

mail($emailTo, $subject, $body, $headers);
?>

 

PLEASE HELP!! Thanks

Link to comment
Share on other sites

Sorry i forgot this code aswell called contact.js

$(document).ready( function() {
$('.error').hide();
$('.but').click( function() {

	var fname = document.getElementById('firstname');
	var lname = document.getElementById('lastname');
	var email = document.getElementById('email');
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var comment = document.getElementById('comment');

	if(fname.val() != '' && lname.val() != '') {
		if(email.val() != '' && emailReg.match.exp) {
			if(comment != '') {
				$('#comment_error').show();
				comment.focus();
				return false;
			} else {

				var dataString = 'name='+ fname + lname +'&email=' + email + '&comment=' + comment;
				//alert (dataString);return false;

  				$ajax({
     					 type: "POST",
     					 url: "process.php",
     					 data: dataString,
     					 success: function() {
     					   $('#contact_form').html("<div id='message'></div>");
     					   $('#message').html("<strong>Contact Form Submitted!</strong>")
     					   .append("<p>We will be in touch soon.</p>")
     					   .hide()
     					   .fadeIn(1500, function() {
     					     jQuery('#message');
     					   });
     					}
    				});

			}
		} else {
			$('#email_error').show();
			email.focus();
			return false;
		}
	} else {
		$('#name_error').show();
		fname.focus();
		return false;
	}

});

});

 

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

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