OverviewThe qForms API was designed with a very basic principal in mindto simplify the process of retrieving and setting form field variables. This was accomplished by creating two of the core API methods: the obj.fieldName.getValue() and obj.fieldName.setValue() methods. Once you've initialized the API, you'll by able to retrieve the value of any form field by using the following syntax:
Regardless whether the field is a text box, radio button, selectbox or some other form field, the getValue() method always retrieves the value of the form field. That means no writing code to loop over arrays to see what elements are selected or checkedthe getValue() method works for all field types.
Likewise, the obj.fieldName.setValue() method will set the value of any form field to the value specified. For example:
This would set the value of the "SampleText" field to "Hello World!" It's as easy as that. For example, to create a button that displays the contents of a field called "SampleText" to the screen, you just need the following:
<INPUT TYPE="Button" NAME="Test" onClick="alert(objForm.SampleText.getValue();">
When a qForm object is created, the object is a global objectthis means you can access the form object from any function within the template. If you have more then one form in the document, you can also initialize more then one qForm object. Just make sure to give each qForm object a unique name.
Whenever a new qForms object is created, several events are automatically attached to the form's onSubmit handler. These events provide several key pieces of functionality that are normally a burden to program.
The most common piece of functionality web developers probably code, is for form validation. The qForms API provides an entire library of useful validation methods for you to use. When a form is submit, all validation rules defined for the form are test and if an errors occur, they are reported to the user and the submission request is cancelled automatically.
Another common problem developers face is preventing duplicate data from being submitted to the server. While there is no way to completely prevent this from happening, we can take steps to help prevent it. Probably the most common reason duplicate data gets created is because an impatient user has repeatedly clicked the submit button. The qForm API automatically prevents this from happening, just by initializing the form! It does this by attaching an event to the form's onSubmit event that ensures only a single submission is allowed. Now how cool is that!