My favorites | Sign in
Project Logo
                
Search
for
Updated Mar 16, 2009 by tobiasz.cudnik
formFromValuesMethodPHP  

formFromValues

Wiki > Syntax > formFrom > formFromValues

Parameters

Description

Method formFromVars acts as flexible form helper. It creates customized pure-markup form without the need of suppling a line of markup.

Final form is available right after using this method.

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',
         ),
         'radio-field' => array('radio',
             'values' => array('possibleValue1', 'possibleValue2')
         ),
         'textarea-field' => 'textarea',
     ),
 );
 $data = array(
     'select-field' => array(
         // no optgroup
         'bar1' => 'bar1 label',
         'bar2' => 'bar2 label',
         'bar3' => 'bar3 label',
     ),
 );
 $record = array(
   'text-field' => 'value from record',
 );
 $tempalte->
   formFromValues($record, $structure, null, $data)
 ;

Result DOM tree

 form#myFormId
  - fieldset
  -  - input#myFormId_hidden-field[name="hidden-field"][value="new hidden-fiel"]
  -  - legend
  -  -  - Text:Fieldset 1 lege
  -  - div.input.text
  -  -  - label
  -  -  -  - Text:default-field l
  -  -  - input#default-field-id[name="default-field"]
  -  - div.input.text
  -  -  - label
  -  -  -  - Text:text-field labe
  -  -  - input#text-field-id[name="text-field"][value="new text-field "]
  -  -  - ul.errors
  -  -  -  - li
  -  -  -  -  - Text:text-field erro
  -  - div.input.checkbox
  -  -  - div
  -  -  -  - Text:Checkbox field
  -  -  - label
  -  -  -  - Text:Checkbox-field
  -  -  - input#myFormId_checkbox-field[name="checkbox-field"][value="1"][checked]
  - fieldset
  -  - legend
  -  -  - Text:Fieldset 2 lege
  -  - div.input.select
  -  -  - label
  -  -  -  - Text:select-field la
  -  -  - select[name="select-field"]
  -  -  -  - option[value="bar1"]
  -  -  -  -  - Text:bar1 label
  -  -  -  - option[value="bar2"]
  -  -  -  -  - Text:bar2 label
  -  -  -  - option[value="bar3"][selected]
  -  -  -  -  - Text:bar3 label
  -  - div.input.select
  -  -  - label
  -  -  -  - Text:select-field-op
  -  -  - select[name="select-field-optgroups-multiple"]
  -  -  -  - optgroup
  -  -  -  -  - option[value="group1_1"]
  -  -  -  -  -  - Text:group1_1 label
  -  -  -  -  - option[value="group1_2"]
  -  -  -  -  -  - Text:group1_2 label
  -  -  -  - optgroup
  -  -  -  -  - option[value="group2_1"][selected]
  -  -  -  -  -  - Text:group2_1 label
  -  -  -  -  - option[value="group2_2"]
  -  -  -  -  -  - Text:group2_2 label
  -  -  -  - option[value="bar"][selected]
  -  -  -  -  - Text:Bar
  -  -  - ul.errors
  -  -  -  - li
  -  -  -  -  - Text:error1
  -  -  -  - li
  -  -  -  -  - Text:error2
  -  - div.input.radio
  -  -  - label
  -  -  -  - Text:Radio-field
  -  -  - input[name="radio-field"][value="possibleValue1"]
  -  -  - input[name="radio-field"][value="possibleValue2"][checked]
  -  - div.input.textarea
  -  -  - label
  -  -  -  - Text:Textarea-field
  -  -  - textarea#myFormId_textarea-field

See also

Comments allowed


Sign in to add a comment
Hosted by Google Code