====== Form class ====== The form class takes care of html form input, by both rendering forms and setting/receiving form input. ===== Form rendering ===== A form is rendered by first configuring the form object and then rendering it. $form = new Form('form_id'); $form->addField(new FieldText('Type something', 'field_title')); $form->addField(new FieldSubmit('Save form', 'save_form')); $form->render(); This will render a form with a text input field labeled //Type something// and a submit button labeled //Save form// ===== Obtaining form data ===== Validation of the form and retrieval of form data, also requires that the form is setup and then validated. As it is important that the form is set up exactly the same way as the posted form, usually the same object is used, and as an example we can type everything in a single example: $form = new Form('form_id'); $form->addField(new FieldText('Type something', 'field_title')); $form->addField(new FieldSubmit('Save form', 'save_form')); if ($form->isSubmitted()) { // The form was submitted. if ($form->validate()) { // Form input was validated. $values = $form->getValues(); // $values now contain all form values. // Do something when form was posted with success. } else { // When the form didn't validate, it have already been prepared with proper error messages, // so we run-through down to displaying it again where it will also contain the entered values. } } else { // Values can be pre-added to the form if desired $form->setValues( array( 'field_title' => 'Pretyped value'; ) ); } $form->render(); ===== Easy forms ===== In order to provide an easier way to design forms, one can prepare a special html file

Please fill this form

This file can be used like $form = new Form('form_id', 'testform.form'); which will actually provide the same form as above. As one can see the file consist of normal HTML, but with some special tags. These tags should match the last part of every Field*-class, so match the ''FieldText'' class. The tag attribute label will become the field label and the attribute name will become the name of the field. Every other attribute will be passed as an option to the field, so required will match //array('required' => true)// and so on. Never use real html form elements, such as
, and