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

varsToForm

Wiki > Syntax > varsTo > varsToForm

Parameters

Description

Injects executable code which toggles form fields values and selection states according to value of variable $varName.

This includes:

Inputs are selected according to $selectorPattern, where %k represents variable's key.

Example

Markup

 <form>
   <input name='input-example'>
   <input name='array[array-example]'>
   <textarea name='textarea-example'></textarea>
   <select name='select-example'>
     <option value='first' selected='selected'></option>
   </select>
   <input type='radio' name='radio-example' value='foo'>
   <input type='checkbox' name='checkbox-example' value='foo'>
 </form>

Data

 $data = array(
   'input-example' => 'foo',
   'array-example' => 'foo',
   'textarea-example' => 'foo',
   'select-example' => 'foo',
   'radio-example' => 'foo',
   'checkbox-example' => 'foo',
 );

QueryTemplates formula

 $template->
     varsToForm('data', $data)
 ;

Template

 <form>
   <input name="input-example" value="<?php  if (isset($data['input-example'])) print $data['input-example'];
 else if (isset($data->{'input-example'})) print $data->{'input-example'};  ?>"><input name="array[array-example]" value="<?php  if (isset($data['array-example'])) print $data['array-example'];
 else if (isset($data->{'array-example'})) print $data->{'array-example'};  ?>"><textarea name="textarea-example"><?php  if (isset($data['textarea-example'])) print $data['textarea-example'];
 else if (isset($data->{'textarea-example'})) print $data->{'textarea-example'};  ?></textarea><select name="select-example"><?php  if ((isset($data['select-example']) && $data['select-example'] == 'first')
     || (isset($data->{'select-example'}) && $data->{'select-example'} == 'first')) {  ?><option value="first" selected></option>
 <?php  }    else {  ?><option value="first"></option>
 <?php  }  ?></select><?php  if ((isset($data['radio-example']) && $data['radio-example'] == 'foo')
     || (isset($data->{'radio-example'}) && $data->{'radio-example'} == 'foo')) {  ?><input type="radio" name="radio-example" value="foo" checked><?php  }    else {  ?><input type="radio" name="radio-example" value="foo"><?php  }    if ((isset($data['checkbox-example']) && $data['checkbox-example'] == 'foo')
     || (isset($data->{'checkbox-example'}) && $data->{'checkbox-example'} == 'foo')) {  ?><input type="checkbox" name="checkbox-example" value="foo" checked><?php  }    else {  ?><input type="checkbox" name="checkbox-example" value="foo"><?php  }  ?>
 </form>

Template tree before

 form
  - input[name="input-example"]
  - input[name="array[array-example]"]
  - textarea[name="textarea-example"]
  - select[name="select-example"]
  -  - option[value="first"][selected]
  - input[name="radio-example"][value="foo"]
  - input[name="checkbox-example"][value="foo"]

Template tree after

 form
  - input[name="input-example"][value=PHP]
  - input[name="array[array-example]"][value=PHP]
  - textarea[name="textarea-example"]
  -  - PHP
  - select[name="select-example"]
  -  - PHP
  -  - option[value="first"][selected]
  -  - PHP
  -  - PHP
  -  - option[value="first"]
  -  - PHP
  - PHP
  - input[name="radio-example"][value="foo"][checked]
  - PHP
  - PHP
  - input[name="radio-example"][value="foo"]
  - PHP
  - PHP
  - input[name="checkbox-example"][value="foo"][checked]
  - PHP
  - PHP
  - input[name="checkbox-example"][value="foo"]
  - PHP

See also

Comments allowed


Sign in to add a comment
Hosted by Google Code