Reputation: 5791
I have a small form with "name", "email", "request", "message" fields. All I want to do is highlight the borders of the input field red if the required info is missing upon submit. I want the form results emailed. Real simple.
Can anyone suggest a fast script for me?
Erik
Upvotes: 0
Views: 842
Reputation: 1387
in addition to the selected answer. maybe someone need my way for valiation:
var postData = $('#formoid').not("input[type='checkbox']").serialize();
var vals = postData.split('&');
for(var i=0;i<vals.length;i++)
{
var comp = vals[i].split("=");
if(comp[0]=="input_cert")//exception
continue;
if(comp[1]!="")
{
$("#"+comp[0]).parent().css("background-color", "white");
}
else
{
$("#"+comp[0]).parent().css("background-color", "red");
$("#"+comp[0]).focus();
$("#test").html("please check clolored field");
return;
}
}
Upvotes: 0
Reputation: 1912
$('form').submit(function(){
var empty_inputs = $(this).find('input[type=text]:empty');
if( empty_inputs.length > 0 ) {
empty_inputs.addClass('error').after('<div class="error">this field is required</div>');
return false;
}
return true;
});
Upvotes: 5
Reputation: 1421
Like what Will Peavy suggested, jQuery validation plug-in (http://docs.jquery.com/Plugins/Validation) does a fairly good job for you to validate various input types, such as email, alph, digits. And it has been integrated very well with frameworks like ASP.NET MVC, Zend. You just need to do some proper set up to activate the plugin.
Upvotes: 0
Reputation: 2358
You can use the jQuery Validation Plug-in (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) for client-side form validation. You'll need something like PHP, ASP.NET, ColdFusion, Jaxer or another server-side utility to fire off the email.
Upvotes: 1