OK, its pretty simple to add both the validation and file upload indicator using jquery.validity and Kevin's technique i mentioned.
Firstly, go ahead and go through the process to add the upload indicator using the guide Kevin made (http://www.gravityhelp.com/forums/topic/add-a-file-upload-progress-bar).
Make sure you have it working as it should. Then go download jquery.validity at http://validity.thatscaptaintoyou.com add the jquery and css files to your page as outlined in my previous post.
Now, this is where it's a bit different from the previuos example without the uploading indicator. We need to load the start and end methods of validity manually so we can return the result of the validation - we only want to show the upload indicator if the validation found no errors, if it found errors we want nothing to happen until the errors have been fixed by the user.
Here's the code you need to put in you theme's header.php file, i'll explain it below.
OK, so this code just tests to see if we are on the form page if(is_page('submit)
, then I manually start the validation usingjQuery.validity.start();
I then define my validation rules, then manually end the validation and get the validation status with jQuery.validity.end().valid;
If there are no errors then jQuery.validity.end().valid
returns TRUE, if there are errors i believe it returns FALSE.
Then we use the code from Kevin to create and hide the dom elements for the upload indicator.
This next part is where the magic happens, when the submit button is click it tests to see if there were any errors on the form, if not it submits the form and displays the upload indicator - if there were errors it does nothing
This code is customized to my needs, name of the page the form is on will be different for you, as will the validation rules and possibly the element(s) to attach the on click event handler to.
To find the id's of the form inputs to use in the validation rules use the firebug plugin for firefox, you can just right-click on an element and find it's class and id.
If you have trouble following or implementing it just let me know and i'll try to help ;)
Posted 12 years ago on Wednesday August 1, 2012 |
Permalink