Control.Form
Before proceeding you may want to read our getting started page.
What does this control do?
Sends form elements using AJAX, and executes commands that are contained within the scripts response. Doing things this way has many advantages, for example, you can add some security without doing things twice by checking fields only in the server-side, the user interaction will be covered within the response. You can even upload files using this control without having to leave the current page. It also can be used to validate forms.
For an usage example check out the Control.Form demo.
How to use
In order to use this control, paste this line of javascript right
at the beginning of your script tag:
This control can be used with any form element, the only thing you need to
do is to attach a special function to the form's onsubmit attribute.
When the users sends the form, the server-side script is supposed to answer
with a special JSON string such as the example below:
'successMessage': 'Everything went OK'.
}
'errorMessage': 'There was an error, please correct it and send the form again'.
}
Validating form inputs
You can perform a simple validation by adding a class to the input
elements you want to validate.
The following examples will validate that the user had filled the input
with an integer number, right before submitting the form.
<label class="required-int"
<input type="text" />
</label>
- required-int An integer number is required.
- required-double A two-decimal number is required.
- required-float A decimal number is required.
- required-alpha Only numbers (0-9), letters (a-zA-Z), dot (.) and underscore (_).
- required-email A valid e-mail address.
- required The user must not leave the field empty.
Overwriting formSubmit()
If you want to overwrite the formSubmit() function just replace it
in any script that will be loaded after Form.js
var control = new Form(form);
if (someProceessIsOK()) {
control.submit();
}
return false;
}
Methods
You don't really need those methods, unless you want to add more things to formSubmit().