Home
Form effects
Here
|
Categories
Other Sections
Sweet Ads
Compatibility
|
|
FF1+ IE6+ Opera 8+
jQuery Form to Form Wizard (v1.1)
Author:
Oct 21st, 10': Script updated to v1.1, which adds basic form validation functionality, triggered each time the user goes from one page to the next, or tries to submit the form. Description: This powerful jQuery script
turns a FORM into a multi-step FORM wizard! Simply group logical
elements within your FORM by surrounding them with the FIELDSET
element, and the script does the rest in creating a new page for
each group, plus the appropriate "Steps" text and pagination links above
and below the form. It helps make filling out long forms more intuitive
and less daunting. And when it comes to form validation, fear not, a
built in form validation feature plus
two event handlers, The only requirement to using this script on a form is that you have access to the FORM's HTML markup in order to inject a FIELDSET element in the desired locations. Demos:
Step 1: Add the below script to the <HEAD> section of your page: The above references the following two external files, which you should download (right click, and select "Save As") Step 2: Then, insert the below HTML code onto your page, which contains the HTML markup of a single form with fieldset elements grouping logical form elements together: And that's a wrap for installation, but read on to get all the important details on customizing the script. Preparing your form to be transformed into a form wizardThe way to turn your form into a form wizard is to edit the
form's HTML markup to wrap each "page" of form
elements manually with a <form id="feedbackform"> The changes you should make to the form are:
|
| option | Description |
formidRequired |
The ID or NAME of the form you wish to
turn into a form wizard. Either of these attribute values will work, for
example: <form id="feedbackform"> or: <form name="feedbackform"> |
persistsectiondefaults to false |
Boolean that sets whether the script should
persist the last form "page" the user is on within a browser session,
and recall it upon the user's return. Defaults to false. For example:
var myform=new formtowizard({ |
revealfxdefaults to ["slide", 500] |
Sets the effect used to bring each page into view. The
syntax is:
For example:
var myform=new formtowizard({ This sets the reveal effect to "fade" and for 1 second (1000 milliseconds) each time. |
validate
v1.1 featuredefaults to null |
An optional array of the IDs or names of the form fields within the form
that you wish the script to automatically validate. The script will check to
see if these fields are filled out before allowing the user to proceed to
the next form page or submit the form. For example:
var myform=new formtowizard({ More information below on how to use the validate array here. |
oninit:function(){}defaults to empty function |
This event handler is fired once when the script has finished initializing a form and transformed it into a form wizard. This usually happens before the page itself has finished loading. The event is passed three parameters:
|
onpagechangestart:function(){}defaults to empty function |
This event handler is fired each time the user is about to go from one form page to another, such as when the user has filled out the first page and clicks "next”" to proceed to the 2nd. The event is also passed three parameters:
|
When it comes to form validation, most of the time, you just want to ensure
that certain fields are filled out. This script rolls into it a simple form
validation feature that does that and with ease. Simply ensure all of the form
fields you wish to validate carry either an id or name attribute
to help identify them, for example:
<form id="staff_feedbackform">
<fieldset class="sectionwrap">
<legend>Basic Information</legend>
Name:<br /> <input id="staff_username" type="text" size="35" /><br />
Age:<br /> <input id="staff_age" type="text" size="6" /><br />
Sex: <input type="radio" name="staff_sex" value="male" /> Male <input
type="radio" name="staff_sex" value="female" /> Female
</fieldset>
<fieldset class="sectionwrap">
<legend>Shipping Address</legend>
Country:<br /> <input id="staff_country" type="text" size="35" /><br />
State/Province:<br /> <input id="staff_state" type="text" size="35" /><br
/>
Address #1:<br /> <input id="staff_addr1" type="text" size="35" /><br />
Address #2:<br /> <input id="staff_addr2" type="text" size="35" /><br />
</fieldset>
<fieldset class="sectionwrap">
<legend>Comments</legend>
Any additional instructions:<br /> <textarea id="staff_feedback"
style="width:350px;height:150px"></textarea><br />
<input type="submit" />
</fieldset>
</form>
Then inside the intialization code for the form, define the
validate option
with the ids/names of the form fields you wish the script to check for:
<script type="text/javascript">
var myform3=new formtowizard({
formid: 'staff_feedbackform',
validate: ['staff_username', 'staff_sex', 'staff_addr1'],
revealfx: ['slide', 500] //<--no comma after last setting
})
</script>
The result is that the form fields "username", "sex", and "addr1" will now be checked to ensure they are not empty before the user can move on to the next page or actually submit the form:
The built in form validation works instantly and painlessly. However, by
default it only checks if the fields in question contain any data. For more
refined validation that check form fields for certain types of data, you need to
turn to the oninit() and onpagechangestart() event
handlers for the task. That's explained on the
next page.