Form Validator
Advertisement
Description
Form Validator makes it easy to validate forms. Setup a couple different classes on your input fields and let quick contact take care of the rest. After setting up a couple simple settings form validator allows you to easily validate forms, or make a contact form in seconds.
Recent Versions
- Version 1.5 - Zip Format
- Version 1.4 - Zip Format
- Version 1.3 - Zip Format
Demo
Setup
- Create your form in any fashion you wish.
- For any items that are required add the class ‘is_required’ to that input field.
- All forms are check to be not blank by default. Forms that are not required are
still checked but won’t prevent the form from submiting. - Apply the following classes if you want the validator to check for things other
than not blank:
vdate for date in standard formats dd mm yyyy
vemail for email compatible with . and + in the email
vphone for phone number
vzip for 5 digit US zip code
vstate for two leter state
vname for names, can have space and ‘ characters - Add the following to your document ready statement
$('#formid').FormValidate({ phpFile:"", ajax:true, validCheck: true });phpFile should point to the path of the send.php file included if you are
using the Ajax method. Ajax should be set to true to use the PHP mailer, or
false to allow the form to submit like normal. - Modify the email address in send.php to the email address you want.
- Enjoy.
FAQ
- Does form validator require anything but Jquery?
- No. But if you want to use it as a quick contact form then you will also need PHP to be installed on your server.
Posted on Monday, October 20th, 2008. Category: Form Validator, Jquery Plugins





November 4th, 2008 at 12:21 am
Can you use the form validator when creating the form programatically, as in generating the form through JS and appending it to the DOM?
November 4th, 2008 at 7:14 am
Absolutly. You will just want to move the $(’#formid’).FormValidate({options}) from your document ready to right after you add the add the form to the DOM.
Most Jquery functions allow for callback (functions that fire when they finish) so you could add the FormValidate function as a callback on your append function if that is how you are adding the form.
I haven’t tested this before so please let me know how it turns out!
November 4th, 2008 at 1:04 pm
How can one trigger the validation from JavaScript? It is now called when submit is pressed. How could one call the form validation function from a JavaScript function (as if someone had pressed Submit on the form)?
Thanks!
November 4th, 2008 at 1:05 pm
In the previous question/case: I want to avoid calling $(’form’).submit(); I just want to call your form validation code
-j2
November 4th, 2008 at 1:12 pm
I assume calling jQuery.iFormValidate.validateForm($(’form’).find(”:input”).filter(”:not(:submit)”)); is the right way to do it?
-j2
November 4th, 2008 at 2:56 pm
J2 you could call the method directly that way. Another way to do it is using the triggerevent function of Jquery. By triggering “change” on all elements of the form you would cause the validator to check each field.
$(’form’).children(”:input”).each(function(){ $(this).triggerevent(”change”) });
Should do it, but I can’t verify since I’m on the bus right now. Let me know if it works out.
November 10th, 2008 at 7:40 am
nice CF script.
I do have a charset problem with it, and can’t solve it. I’ve been reading a lot about this on JQuery-s homepages, and googling a lot, but can’t find a solution that’s working.
I’m using it for a hungarian site, and I get back really strange characters when posting the message containing special characters (Å‘ ö é á à ű ü).
Could you advise? Thx.
November 10th, 2008 at 9:55 am
Sam,
I’ve uploaded a new version of the form validator script. I’ve changed the email from plain text to html (after all whose still using a plain text email client now of days). This should correct the problems you were having with certain characters.
Thanks for the report!
November 24th, 2008 at 3:01 am
very nice site!
December 2nd, 2008 at 2:13 pm
Nice plugin! What about continuing through all fields even if an error is found? I have a form with about a dozen fields. Even though it’s unlikely a large number will be invalid, I like to plan for the worst case scenario.
December 4th, 2008 at 1:10 pm
Shane,
I’m going to take a look at implementing this. I realize it can be an annoyance for a user to get multiple errors. I’ll let you know when I find a solution.
December 4th, 2008 at 2:49 pm
Can you include several PHP files within the FormValidate function call?
December 4th, 2008 at 2:56 pm
If you are wanting to pass the Ajax call to different php file you can do so by setting the phpFile variable for each different form with the corresponding file. Etc I have two forms I want form1 to send to send1.php and form2 to send2.php. I would do the following in my document.ready
$(’#form1′).FormValidate({phpFile: send1.php, ajax: true});
$(’#form2′).FormValidate({phpFile: send2.php, ajax: true});
Hope that is what you were asking. If not let me know.
December 7th, 2008 at 5:05 am
Hi!
Here’s my question. I let user to add some fields in the form dynamically by pressing “Add” button (using innerHtml). How can I then tell validator to validate those new fields as well as previous? Running
$(’#formid’).FormValidate({})
on pressing “Add” button helps, but it causes my form to validate multiple times (depending on how much fields user has added).
December 8th, 2008 at 7:44 am
Spirik,
The best way to handle this would be to use
$(’#formid’).find(’:input’).change();
once you up date all the fields, or
$(this).change();
for each field you are updating if you do so in a way that makes $(this) point to the correct object. The former of the two options would be the easiest to implement if your Javascript knowledge is limited.
Let me know if it works out for you!
December 9th, 2008 at 1:46 pm
Thanks for response, but problem still remains(
Let me explain it in more details.
For example, in my form I’ve got some div-container “A”, which contains another div “B” (which in turn contains text-input “C”); “Add”-button and submit button (not in those divs). Once user presses “Add”-button, new div created and text-input added in it:
newinput=”";
newnode=document.createElement(”div”);
newnode.innerHTML=newinput;
Than it appends in div-container “A”:
containerDivA.appendChild(newnode);
The problem is: this new added field doesn’t validates on pressing ’submit’ button, even though I still can make it validating on keyup event:
inps = $(newnode).find(”:input”).filter(”:not(:submit)”).filter(”:not(:checkbox)”);
inps.bind(”keyup”, jQuery.iFormValidate.validate);
Using
$(’#formid’).FormValidate({})
on pressing “Add”-button helps, but it causes my form to validate multiple times (depending on how much fields user has added: three fields, then validation goes three times, you can check it, e.g., by placing alert() in validateForm function - it will appear three times) when I try to submit it.
Sorry for long explanation) And thanx again!
December 9th, 2008 at 2:34 pm
I see what you are saying now. I didn’t follow at first. You might try this snipit, not sure if it will work, but it may.
$(’#formid’).unbind(”submit”);
$(’#formid’).FormValidate({});
The reason for this your problem is that formvalidator grabs a list of input when the function is run. If this doesn’t work also try changing line 33 of form js
from
$(this).submit(function(){
to
$(this).bind(”submit”,function(){
Don’t know if that will make a difference but its worth a shot. Good luck.
December 10th, 2008 at 1:03 pm
It worked out just perfect (using $(’#formid’).unbind(â€submitâ€);
$(’#formid’).FormValidate({});). Thanks a lot for your help!
December 17th, 2008 at 4:05 pm
regarding Spirik’s success in using the unbind formulation in order for the form to be resubmittable - wouldn’t you need to re-’bind’ it back?
Or is it that in this case, Spirik (you can ans too) is only needing validation while in non-live submission mode?
just curious… might very well apply to what i’m working on too
December 17th, 2008 at 4:23 pm
Bill,
Yes that assumption is correct. In Sprik’s case he would run $(’#formid’).FormValidate({}); again after unbinding. This would of course setup the bind again.
On a quick note though, I will say that this does create duplicate onChange binds (for keypresses). This won’t have a very big effect if it only happens a couple times, but if for some reason your script run that combination 30 or so times, expect to see some performance issues!
December 20th, 2008 at 1:30 pm
Nice plugin - almost exactly what I need. I made a modification so that you can add a ‘novalid’ class to fields that should be ignored, in this case I didn’t want users to get confused and think that they had to fill out an optional field since it would get a red border if it was blank. At line 80 I inserted:
var doValid = true;
at line 106 I inserted:
//Check for not validating
}else if($(this).hasClass(’novalid’)){
doValid = false;
and I wrapped the if(isValid) block in this:
if(doValid){
if(isValid){
…
}
}else{
$(this).removeClass(”invalid”);
$(this).removeClass(”valid”);
}
Shoot me an email if you’d like the whole modified file.
December 20th, 2008 at 4:39 pm
Great plugin. I think you should add something like Josh said in the last post. I had to modify it like that too, cause you don’t want a red box where a field is not required.
Thanks!
December 20th, 2008 at 5:33 pm
Josh,
Hey thanks for the idea. I think its a good step forward and I implemented it (in a different fashion however) and allowed users to choose between the two options.
Now there is an option validCheck which can be set when calling form validator. Setting it to true prevents the fields with a class of “novalid” from being parsed. Setting validCheck: false, returns to the previous functionality even if there is a class of novalid attached to a field.
This has been implemented in the example on this page!
Thanks again.
December 22nd, 2008 at 7:48 pm
I use FormTools to process my form. The form action is: http://www.somedomain.com/dir/process.php. The form does not submit. I set the ajax to false:
<!–
$(document).ready(function ()
{
$(’#signup1′).FormValidate({
phpFile:”",
ajax:false,
validCheck: true
});
});
How can I have it submit to FormTools? Thanks for your help!
December 22nd, 2008 at 10:03 pm
I updated to ver 1.4 and it works!
December 23rd, 2008 at 10:29 am
Sorry about that John. There was a small bug with the last version and I got it worked out in 1.4.
December 23rd, 2008 at 11:09 am
I think I may have found a bug. I have an email field, set to class=’vemail’, which I want to validate if the user enters input. But in your validateForm function, the actual validation is only run if the field is required.
I fixed this for myself by changing the validateForm function to
var isValid = true; //benifit of the doubt?
$inputs.each(jQuery.iFormValidate.validate);
if($inputs.hasClass("invalid")){isValid=false;}
return isValid;
Is there some drawback to doing it my way, or is there a reason you only checked required inputs?
-Joe
December 23rd, 2008 at 11:41 am
Joe,
I only checked required input because I didn’t want the form to fail if a non required form was invalid (which would also apply to a field being blank).
January 2nd, 2009 at 1:36 pm
Great form, works wonderfully and is so simple to use. Nice work Jeremy.
One quick question.
How would I add an action to reload the form after it has been sent. At the moment it calls the var set in the php file “Thank you for your comments!” which is nice. Is there a way to have this call that var then after say, 2 seconds, have it reload the original form in place?
January 9th, 2009 at 11:54 am
Hi Jeremy,
Any word on the above note?
Checkout the contact link here
http://www.nimmbl.com/site
If you send a message, the form fades to black which is the bg color behind the parent div which is white.
Any ideas?
thanks
January 9th, 2009 at 3:34 pm
Chris,
Everything looked fine on Chrome and Firefox. More than likely this has something to do with IE being… well IE. My suggestion might be to try setting a background color of white to container-1. Unfortunately IE tends to have a mind of its own.
Also if you could clarify for me. Why would you want the form to load again but be blank? In a situation like a contact form you wouldn’t want them to send multiple responses would you?
January 9th, 2009 at 4:14 pm
Hi Jeremy,
Thanks for taking a look at this. I’ll give your suggestion a try.
No, I wouldn’t, you’re right. I thought about that after looking at it again and figured that it’s fine the way it is.
I’ll let you know what I find with IE.
Chris
January 22nd, 2009 at 12:01 pm
Hi i am facing one problem when i using the ajax jquery for validation. i have one php file to validate the my form element but the problem is when we called the $.ajax() function then we call return false so form will not be submitted but i want to submitted the form if php file validated the all form element. There are any solution to submit the form after validate the file.Thanks in Advance
January 26th, 2009 at 10:42 am
sent the mail it appears
“from: anonymous@webxc….”.
How it is made in order to make to appear the mail of the sender?
Tks
January 26th, 2009 at 1:11 pm
Sandeep,
I’m not sure I understand your question. Are you saying you want to execute a server side validation? If that is the case, you would have to write your own script, and have the php file return a 404 to the ajax call. This would cause the form to reload without submitting, but wouldn’t call the validation again.
Francesca,
You want the from address to be different for you sent emails? To do this just add “From: youremail@domain.com” to the header variable.
January 27th, 2009 at 5:00 am
tks Jeremy
January 31st, 2009 at 2:58 pm
I really want a page similar to this:
http://www.rememberthemilk.com/signup/
Your script accomplishes all of that, but I just haven’t figured out a way to check the equality of two strings (password and confirm password fields). Also, do you know of a way to check if an input is equal to an element in an array. (I basically want to check if a username has already been added to my database). That’s also accomplished in the site above, it tells you if a username is available instantly. Thanks.
February 3rd, 2009 at 8:34 am
Hi, nice script!
I was wondering if you have any experience using this with multiple forms on one page. Normally pressing the submit on one form shouldn’t affect the other. But in my case it seems to affect it.
I have two forms one named locatieform and one slaapmutsform beneath the locatieform.
i call the plugin like so:
$(’form#locatieform’).FormValidate({ phpFile:”send.php”, ajax:true });
$(’form#slaapmutsform’).FormValidate({ phpFile:”send.php”, ajax:true });
clicking the submit from locatieform validates and then sends slaapmutsform. This in relation to the last call made to FormValidate(). If i were to place
$(’form#locatieform’).FormValidate({ phpFile:”send.php”, ajax:true });
At the bottom.. it would validate and send locatieform. Even when clicking the submit for slaapmutsform
Any thoughts?
Thnx
February 3rd, 2009 at 12:46 pm
Garrett,
Thats a great idea. I’ll add this feature in before the end of the week. Be sure to check back.
Dwayne,
This is a bug that keeps popping up on me and I’ve been having trouble squashing it. I will devote some time later today to try and solve this once and for all.
February 5th, 2009 at 3:29 am
Hi,
I am trying to apply the Form Validator on my existing code but it is not working.
All js files are included but still validation is not happening..
Can you help me ..
Thanks,
Himanshu
February 5th, 2009 at 11:53 am
Dwayne,
I was a little hasty assuming everything was working correctly. I did in fact reproduce this error on my end. I’ll be releasing a new version later today with a bug fix. I’ll email you when It’s complete.
Himanshu,
Do you have a URL that I could see the error at? Thanks!
February 16th, 2009 at 6:15 pm
I am having some trouble with the vemail, vzip, and vphone classes. When I hit submit they are not changing to red like the is_required fields do.
Is it possible to both do is_required and vemail on the same input field?
Here is a link to my form I am working up right now: http://youthdev.biola.edu/ministry/conferences/wats/index.cfm
February 18th, 2009 at 2:01 am
Hello,
Nice plugin here. But it seems i got an error while trying out the demo.
Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in D:\WAMP\www\formvalidator\send.php on line 10
Error!
I didn’t touch anything yet still got error.
Thanks in advance.
February 18th, 2009 at 9:43 am
Brandon,
Yes it is possible to do both. Just do something along the lines of class=”vphone is_required” Just separate the classes with a space.
Amanruzaini,
This is a problem with your php configuration. To fix this include the following line in the send.php file:
ini_set(’sendmail_from’, ‘me@domain.com’);
Replacing me@domain.com with your email. Be careful however as some email system will block emails if the domain and sending server don’t match up (ie. you use me@yahoo.com, but send it from your webserver).
February 26th, 2009 at 12:29 pm
Hey Jeremy,
First off AWESOME script!
2nd: I’m using smarty templating, and am building a script. All the validation is working fine, but when i go to submit the page, it’s not working [i'm also using mod_rewrite and need to pull in the URL].
{literal}
{/literal}
Ideas ?
Thanks in advance
February 26th, 2009 at 1:11 pm
Brandon,
Are you using the AJAX function or just trying to pass to the default action for the form? If you have a URL I could look at I’ll see what I can figure out.
February 26th, 2009 at 2:35 pm
P.S. Would like for the ajax submission to work, but i found if i choose “ajax:false” then it submits fine
February 27th, 2009 at 12:52 pm
Im surprised nobody else has reported this, it must just be happening to me:
Submit a form (ajax) with invalid fields. It prevents the form from being submitted.
Fix the validation errors and submit again.
FormValidate will submit as many POSTs as there were failed attempts + the last successful one.
Thanks for your hard work Jeremy!
March 5th, 2009 at 12:52 pm
[...] Form Validator makes it easy to validate forms. Setup a couple different classes on your input fields and let quick contact take care of the rest. After setting up a couple simple settings form validator allows you to easily validate forms, or make a contact form in seconds. Download [...]
March 8th, 2009 at 2:19 pm
First off, thank you for the script.
Now, I’m using it in a website with jQuery and Mootools. Therefore I have to use
jQuery.noConflict();
and this is not letting me validate the form.
Any suggestions?
March 9th, 2009 at 7:42 am
Luc,
I can’t say I’ve used noConflict before. My only suggestion would be to make sure you load FormValidator before you call the no conflict, but even then I’m not sure if there will be issues. Let me know what you find out!
March 15th, 2009 at 11:11 pm
I have some problem with ‘vphone’. I’m trying to put:
and when I submit form, it’s not validate this field.
what I’m doing wrong?
March 19th, 2009 at 10:42 am
The phopne field lets you enter in any number you want - it would seem that you would want this to be a little more robust - any ideas?
March 20th, 2009 at 8:19 pm
I was having problems with the phone validation as well, it was throwing an error, then the form would submit. I replaced the phone reg. expression with a different one. it took me a while to find one that wouldnt throw an error:
/^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
March 21st, 2009 at 7:33 pm
How do you validate a checkbox or multi select group?
March 26th, 2009 at 4:10 pm
First of all great script.
I am having a small problem; I get the following error:
Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in C:\xampp\htdocs\xampp\scratch\form\send.php on line 9
Error!
so I use the following line but I get this error message:
ini_set(’sendmail_from’, ‘my@email.com’)
I get the following error:
Parse error: parse error in C:\xampp\htdocs\xampp\scratch\form\send.php on line 15
So I guess my question would be how and where do I add this to the send.php
Chris
April 3rd, 2009 at 4:30 pm
Jeremy,
Do you know if this plugin will work for ASP? I like it a lot but I am having issues making it work on our ASP platform.
Thanks
Corey
April 8th, 2009 at 1:13 pm
Hello again,
I got the ASP to work. However, I am unable to get it to work in IE6. The user can’t even click inside the fields to enter in data.
Any thoughts in getting this to work in legacy browsers?
Corey
May 4th, 2009 at 10:16 am
Hi Jeremy, i want to validate if all fields are correctly input, and when this is alright there is a function:
$(”#Gravar”).click( function(){
$.post(”cedcrbd.php?do=inserir_valida”,{id: $(’#txtID’).val(), tipo: $(’#txtTipoDoc’).val(), numDoc: $(’#txtProcID’).val()},
function(data){ $(”#resulta”).text(data);
});
});
});
who calls a php file to insert/update one register in database but the current page shouldn’t reload because if there is any problem in database the div #resulta should show the message and the input fields should maintain the values to correction.
Email não é necessário mas se pretender uma resposta tenha a certeza de que o coloca!
txtID
Necessário
…..
Best regards
May 5th, 2009 at 2:20 pm
Hi Jeremy, your code is very good and it does almost everything that i have ask to you in my last message except when it calls my php file (code above), it reload my php file page with only the message in the default div:
(pag1.php)
$(document).ready(function (data){
$(’#myform’).FormValidate({
phpFile: “cedcrbd.php?do=inserir_valida”,
ajax:true,
validCheck:false
})
});
It calls “cedcrbd.php?do=inserir_valida” and the resul is correct but opens the same page pag1.php without the fields. Can you tell me something about this?
BEst regards
May 7th, 2009 at 4:10 am
Hummm, is there anybody out there?:)
May 8th, 2009 at 5:01 am
Well i have already done. Thanks if there is anybody out there!!
bye
May 15th, 2009 at 9:51 pm
[...] Alle Dateien zum Download sowie Demos findet ihr auf der offiziellen Website. Form Validator [...]
June 8th, 2009 at 10:30 pm
Awesome script! Nice and simple and I was able to use it as a base for my first Word Press plugin. Thanks man!
July 4th, 2009 at 4:34 pm
[...] Form Validator [...]
Leave a Reply