Declaration:
<? class Form ?>
Description: The Form class serves to gather information about the form fields and to display them in documents. Form will be considered valid if all input from user is validated. The form is considered submitted if all its fields are present in the request. Normally the action that processes the form can be called with all parameters correctly passed from the request, in such case it will detect it was submitted and perform its operation. Doing so the same action that displays form can be called as, for example, a remote service. The form detects it is a valid submisiion by the fact that all fields pass validation. The form's lifecycle is as follows:
The form has a way to carry parameters between requests - using the setParameter() method. Such parameters will be available on subsequent request because they will be included as hidden fields. By default all forms will be submitted with the POST method and all forms will have enctype='multipart/form-data', so they are ready to upload files. Each uploaded file in a request will be represented by the UploadedFile instance. However, you can specify which HTTP method to use in the form constructor. The form upon validation will set the offending field values to NULLs - note how this differs from the values submitted by users - empty fields are carried as empty strings. Note that HTML forms must render a special hidden fields of value '' for checkboxes since browsers DO NOT SEND ANYTHING when checkbox is unchecked. In such case the form will get never 'submitted' on the server side. Also note that you cannot trust any field values unless you are sure that the form was submitted. If you use field values and validate them before the call to Form::isSubmitted(), the result of validation can be wrong and the value will be not the value submitted by user. This is because the form can make any assumptions on it being submitted only after all fields have been added to it; only then it copies field values from the request. After that it starts validating field values and, if it fails, the field value is set to NULL. In short, the call to isSubmitted() signals the form that all its fields have been added. Also note that you have to display all the fields you have added to the form on the page, otherwise the form will never get submitted. The best place to construct the form is the Action's onInit() method. The best place to check the validity of submission is the process() method. Authors:
Methods:
|
|