views:

28

answers:

3

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

+1  A: 

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.

Will Peavy
A: 

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.

Jay Zeng
+2  A: 
$('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;
});
troynt