Hey there everyone,
I am trying to get this form validation to work, and i think i am screwed unless i build a new form to work with validation. I would love for someone to sugjest an edit that would allow me to keep my form.
Here is the validation i have. towerdata gave this to me.
<script type="text/javascript">
function check_user(name,phone,email)
{
$.ajax({
type: "POST",
url: "mail.php",
data: "t1="+name+"&t2="+phone+"&t3="+email+,
success: function(ajax_val) {
//alert(ajax_val);
$('#msg').show();
$('#msg').addClass('alert_error');
$('#msg').html(ajax_val);
$('#pmsg').hide();
}
});
}
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#pmsg').hide();
var name = $("#name");
var phone = $("#phone");
var email = $("#email");
//var phoneRegex = /^[2-9]\d{2}-\d{3}-\d{4}/;
name.blur(validateName);
phone.blur(validatePhone);
email.blur(validateEmail);
name.keyup(validateName);
phone.keyup(validatePhone);
email.keyup(validateEmail);
$('#submit').click(function(){
if(validateName() & validatePhone() & validateEmail())
{
var fname = document.getElementById('Name').value;
var phone = document.getElementById('phone').value;
var email =document.getElementById('email').value;
//alert(email);
check_user(name, phone, email,);
$('#pmsg').show();
return true
}
else
{
return false;
}
});
function validateName(){
//if it's NOT valid
if(name.val()==''){
nameo.text("Enter Name");
name.addClass("error");
return false;
}
//if it's valid
else{
name.text("");
name.removeClass("error");
return true;
}
}
function validatePhone(){
//if it's NOT valid
//Matches : xxx-xxx-xxxx only
var phoneRegex = /^\(?(\d{3})\)?[-\. ]?(\d{3})[-\. ]?(\d{4})$/;
var phoneval = $('#phone').val();
if(!phoneRegex.test(phoneval)){
//alert("hello");
phone.text("Enter Valid Phone");
phone.addClass("error");
return false;
}
//if it's valid
else{
phone.text("");
phone.removeClass("error");
return true;
}
}
function validateEmail(){
//testing regular expression
var a = $("#email").val();
var filter = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
//if it's valid email
if(filter.test(a)){
email.text("");
email.removeClass("error");
return true;
}
//if it's NOT valid
else{
email.text("Enter Valid eMail");
email.addClass("error");
return false;
}
}
})
</script>
here is the form that i have. The reason why i want to keep the form is because i have already had the css developed for this.
<div class="form-section">
<form action="thanks.php" method="post" class="form">
<span>Free Consultation</span>
<i></i>
<div class="form-input">
<label for="name" name="name" class="clearfix"><small>Full Name:</small>
<input type="text" placeholder="*Required" id="name">
<i> </i></label>
<label for="phone" name="phone" class="clearfix"><small>Phone:</small>
<input type="text" placeholder="*Required" id="phone"> <i> </i></label>
<label for="email" name="email" class="clearfix"><small>Email:</small>
<input type="text" placeholder="*Required" id="email">
<i> </i></label>
</div>
<div class="custom-form form-input">
<label name="date" class="clearfix"><small>Request for:</small>
<input type="text" placeholder="*Optional" id="datepicker">
</label>
<div class="form-input select clearfix">
<label name="time" for="name">at:</label>
<select>
<option>--Select Time--</option>
<option>09:10AM</option> <option>11:10AM</option>
<option>11:10AM</option>
<option>13:10PM</option>
<option>15:10PM</option>
</select>
</div>
</div>
<input type="submit" value="Request Appointment">
<p>We will contact you to set a final appointment time that best accomodates your request</p>
</form>
</div>
Thanks in advance