|
formFromVarsMethodPHP
formFromVarsWiki > Syntax > formFrom > formFromVars Parameters
Array of names of following vars:
Form structure information. This should be easily fetchable from ORM layer. Possible types:
Default field's value. Used when field isn't present within supplied record. Ex:
Additional data for fields. For now it's only used for populating select boxes. Example:$defaultData = array( 'select-field-optgroups' => array( array( // 1st optgroup '__label' => 'optgroup 1 label', 'group1_1' => 'group1_1 label', 'group1_2' => 'group1_2 label', ), array( // 2nd optgroup '__label' => 'optgroup 2 label', 'group2_1' => 'group2_1 label', 'group2_2' => 'group2_2 label', ), 'bar' => 'Bar', // no optgroup ), );
Input wrapper template. This template will be used for each field. Use array to per field template, 'default' means default. All types allowed in $structure can be used as per-type default template when indexed like '$type' ex 'checkbox'. To each input wrapper will be added a class which is field's type. Example:$templates`['__checkbox']` = ' <div class="input"> <div>Checkbox field below</div> <label/> <input/> </div>';Default template is:<div class="input"> <label/> <input/> <ul class="errors"> <li/> </ul> </div>
Array of selectors indexed by it's type. Allows to customize lookups inside inputs wrapper. Possible values are: Callback triggered after preparation of each field. DescriptionEXPERIMENTAL - works, but not for production code Method formFromVars acts as flexible form helper. It creates customized exacutable form without the need of suppling a line of markup. Form code is executed during template-execution and creates final form using record from variable. Created form have following features:
Created form can be customized using:
Example $structure = array(
'__form' => array('id' => 'myFormId'),
array(
'__label' => 'Fieldset 1 legend',
'default-field' => array( // 'text' is default
'label' => 'default-field label',
'id' => 'default-field-id',
),
'text-field' => array('text',
'label' => 'text-field label',
'id' => 'text-field-id',
),
'hidden-field' => 'hidden',
'checkbox-field' => 'checkbox',
),
array(
'__label' => 'Fieldset 2 legend',
'select-field' => array('select',
'label' => 'select-field label',
),
'select-field-optgroups-multiple' => array('select',
'label' => 'select-field-optgroups label',
),
'radio-field' => array('radio',
'values' => array('possibleValue1', 'possibleValue2')
),
'textarea-field' => 'textarea',
),
);
See alsoComments allowed |
Sign in to add a comment