DooForm learn to work with forms
Ok in this tutorial I will show you how do you work with forms, its very simple.
Loading DooForm helper is very easy:
1.
Doo::loadHelper(‘DooForm’);
First you create form from array and then just call
1.
echo $form->render();
To render the form, render function is returning html of the form. So we will begin making one simple element, lets say textfield:
01.
$form = new DooForm(array(
02.
‘method’ => ‘post’,
03.
‘action’ => $action,
04.
‘elements’ => array(
05.
‘username’ => array(‘text’, array(
06.
‘required’ => true,
07.
‘label’ => ‘My username: ‘,
08.
‘attributes’ => array(“style” => ‘border:1px solid #000;’, ‘class’ => ‘username-field’),
09.
‘field-wrapper’ => ‘div’,
10.
‘validators’ => array(
11.
array(‘username’,4,7),
12.
array(‘maxlength’,6,’This is too long’),
13.
array(‘minlength’,6)
14.
)
15.
))
16.
)
17.
));
As you can see all form data you can add into form array, so when you are creating form you will have to define method, action and elements you have in your form, elemnts is another array, that array will contain all form elements. You begin with naming your element and then create array that will describe that element (type, label, validators, field-wrappers, etc…)
So in element you will have for example:
01.
‘username’ => array(‘text’, array(
02.
‘required’ => true,
03.
‘label’ => ‘My username: ‘,
04.
‘attributes’ => array(“style” => ‘border:1px solid #000;’, ‘class’ => ‘mitar’),
05.
‘field-wrapper’ => ‘div’,
06.
‘validators’ => array(
07.
array(‘username’,4,7),
08.
array(‘maxlength’,6,’This is too long’),
09.
array(‘minlength’,6))
10.
)
11.
),
So