View Full Version : Form Validation and Submission

12-22-2010, 12:05 AM
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">


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


<option value="2"


<option value="3"

>American Samoa</option>

<option value="4"


<option value="5"


<option value="6"


<option value="7"

>Antigua & Barbuda</option>

<option value="8"


<option value="9"


<option value="10"


<option value="11"


<option value="12"


<option value="13"


<option value="14"


<option value="15"


<option value="16"


<option value="17"


<option value="18"


<option value="19"


<option value="20"


<option value="21"


<option value="22"


<option value="23"


<option value="24"


<option value="25"


<option value="26"

>Bouvet Island</option>

<option value="27"


<option value="28"

>British Indian Ocean Terr.</option>

<option value="29"

>Brunei Darussalam</option>

<option value="30"


<option value="31"

>Burkina Faso</option>

<option value="32"


<option value="33"


<option value="34"


<option value="35"


<option value="36"

>Cape Verde</option>

<option value="37"

>Cayman Islands</option>

<option value="38"

>Central African Republic</option>

<option value="39"


<option value="40"


<option value="41"


<option value="42"

>Christmas Island</option>

<option value="43"

>Cocos (Keeling) Isl</option>

<option value="44"


<option value="45"


<option value="46"


<option value="47"

>Cook Isl</option>

<option value="48"

>Costa Rica</option>

<option value="49"

>Cote D'Ivoire</option>

<option value="50"


<option value="51"


<option value="52"

>Czech Republic</option>

<option value="53"


<option value="54"


<option value="55"


<option value="56"

>Dominican Republic</option>

<option value="57"

>East Timor</option>

<option value="58"


<option value="59"


<option value="60"

>El Salvador</option>

<option value="61"

>Equatorial Guinea</option>

<option value="62"


<option value="63"


<option value="64"

>Faeroe Islands</option>

<option value="65"

>Falkland Isl. (Malvinas)</option>

<option value="66"


<option value="67"


<option value="68"


<option value="69"

>French Guiana</option>

<option value="70"

>French Polynesia</option>

<option value="71"

>French Southern Terr.</option>

<option value="72"


<option value="73"


<option value="74"


<option value="75"


<option value="76"


<option value="77"


<option value="78"


<option value="79"


<option value="80"


<option value="81"


<option value="82"


<option value="83"


<option value="84"

>Guernsey C.I.</option>

<option value="85"


<option value="86"


<option value="87"


<option value="88"


<option value="89"

>Heard and McDonald Isl</option>

<option value="90"


<option value="91"

>Hong Kong</option>

<option value="92"


<option value="93"


<option value="94"


<option value="95"


<option value="96"

<option value="97"

>Isle of Man</option>

<option value="98"


<option value="99"


<option value="100"


<option value="101"


<option value="102"

>Jersey C.I.</option>

<option value="103"


<option value="104"


<option value="105"


<option value="106"


<option value="107"

>Korea Republic of</option>

<option value="108"


<option value="109"


<option value="110"


<option value="111"


<option value="112"


<option value="113"


<option value="114"


<option value="115"


<option value="116"


<option value="117"


<option value="118"


<option value="119"


<option value="120"


<option value="121"


<option value="122"


<option value="123"


<option value="124"


<option value="125"

>Marshall Isl</option>

<option value="126"


<option value="127"


<option value="128"


<option value="129"


<option value="130"


<option value="131"

>Moldova Republic of</option>

<option value="132"


<option value="133"


<option value="134"


<option value="135"


<option value="136"


<option value="137"


<option value="138"


<option value="139"


<option value="140"


<option value="141"

>Netherland Antilles</option>

<option value="142"


<option value="143"

>New Caledonia</option>

<option value="144"

>New Zealand</option>

<option value="145"


<option value="146"


<option value="147"


<option value="148"


<option value="149"

>Norfolk Isl</option>

<option value="150"

>Northern Mariana Isl</option>

<option value="151"


<option value="152"


<option value="153"


<option value="154"


<option value="155"


<option value="156"

>Panama Canal Zone</option>

<option value="157"

>Papua New Guinea</option>

<option value="158"


<option value="159"


<option value="160"


<option value="161"


<option value="162"


<option value="163"


<option value="164"

>Puerto Rico</option>

<option value="165"


<option value="166"

>Rest of World</option>

<option value="167"


<option value="168"


<option value="169"

>Russian Federation</option>

<option value="170"


<option value="171"

>Saint Kitts & Nevis</option>

<option value="172"

>Saint Lucia</option>

<option value="173"


<option value="174"

>San Marino</option>

<option value="175"

>Sao Tome & Principe</option>

<option value="176"

>Saudi Arabia</option>

<option value="177"


<option value="178"


<option value="179"

>Sierra Leone</option>

<option value="180"


<option value="181"


<option value="182"


<option value="183"

>Solomon Islands</option>

<option value="184"


<option value="185"

>South Africa</option>

<option value="186"


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


<option value="192"

>Svalbard & Jan Mayen Isl</option>

<option value="193"


<option value="194"


<option value="195"


<option value="196"


<option value="197"


<option value="198"

>Tanzania United Republic</option>

<option value="199"


<option value="200"


<option value="201"


<option value="202"


<option value="203"

>Trinidad & Tobago</option>

<option value="204"


<option value="205"


<option value="206"


<option value="207"

>Turks and Caicos Isl</option>

<option value="208"


<option value="209"


<option value="210"

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

<option value="211"


<option value="212"


<option value="213"

>United Kingdom</option>

<option value="214"

>United States</option>

<option value="215"


<option value="216"


<option value="217"


<option value="218"

>Vatican City State</option>

<option value="219"


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


<option value="227"


<option value="228"



</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">&nbsp;</TD></TR>
<TR><TD CLASS="tableBlueBody" ALIGN="right" VALIGN="top">


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

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


</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;">&nbsp;</TD><TD COLSPAN="2" CLASS="tableBlueBody" STYLE="border-bottom : 1px solid #CCCCCC;">&nbsp;</TD></TR>

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

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

And then i have a file called process.php!

$emailTo = 'sakura-designs@hotmail.com';
$subject = 'We Will Buy Your Car.ie Form Submission';

$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);

Sorry i forgot this code aswell called contact.js

$(document).ready( function() {
$('.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 != '') {
return false;
} else {

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

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>")
.fadeIn(1500, function() {

} else {
return false;
} else {
return false;




12-22-2010, 02:42 AM
Get it to work first without the Javascript part.

That will narrow it down to whether or not the problem is with the Javascript.

Something to also look at ...
The command, $_REQUEST is deprecated (obsolete) for the latest PHP versions.
Since you are using method="post" for your form,
change all of $_REQUEST to $_POST


12-22-2010, 03:03 AM
I'm not a php expert, so please backup original. Try using this:

$emailTo = 'sakura-designs@hotmail.com';
$subject = 'We Will Buy Your Car.ie Form Submission';

$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);
header( "Location: http://www.website.com/thankyou.html" );

I believe the mail() function only takes 3 parameters (your original code had 4). Anybody know if this is correct?

Also, to send people to a thank you page upon successful completion of form submission, look at the header() function.

12-22-2010, 12:28 PM
Thanks for that its at least submitting the form on the website and displaying the page but now the problem is its just not submitting it looks like its working but when i check the destination email address i dont receive any emails??? Any ideas?

12-22-2010, 02:40 PM
Try changing this:

mail("sakura-designs@hotmail.com", $subject, $body);

If all works after this change, you can delete the following 2 lines, which no longer do anything:

$emailTo = 'sakura-designs@hotmail.com';
$headers = 'From: '.$name.' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;

12-22-2010, 02:51 PM
I tried that buddy but it aint working any other suggestions?? for the time being i just need it to submit il do the validation after it.

12-22-2010, 02:55 PM
Hmnn. From my experience, that should have worked. Did you check your spam folder? You might also want to email the tech support for your server and see if the emails are getting held up on their end. It could also be that your server is slow in relaying the email to your hotmail account.

12-22-2010, 03:47 PM
Try this:
update the 'from' part

$headers = 'From: someone@wewillbuyyourcar.ie' . "\r\n" . 'Reply-To: ' . $email;

The 'From' header is important.
Please see this page as well: Why is my PHP script not sending emails? (http://www.html-form-guide.com/blog/php-form-email/3/php-script-not-sending-email/)