Development

Changeset 1433

You must first sign up to be able to contribute.

Changeset 1433

Show
Ignore:
Timestamp:
06/13/06 14:23:05 (2 years ago)
Author:
fabien
Message:
  • added a new get_name_from_id() and label() helpers (to automatically convert array form names to proper (and unique) ids with underscores.)
  • added id value to radiobutton_tag()
  • wrapped each id with the _parse_id() function.

closes #521 - patch from slickrick/fabien

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/data/generator/sfPropelAdmin/default/template/templates/editSuccess.php

    r1348 r1433  
    5454<?php endif; ?> 
    5555<div class="form-row"> 
    56   <label <?php if ($column->isNotNull()): ?>class="required" <?php endif; ?>for="<?php echo $this->getSingularName() ?>[<?php echo $column->getName() ?>]">[?php echo __('<?php echo str_replace("'", "\\'", $this->getParameterValue('edit.fields.'.$column->getName().'.name')) ?>:') ?]</label> 
     56  [?php echo label_for('<?php echo $this->getSingularName() ?>[<?php echo $column->getName() ?>]', __('<?php echo str_replace("'", "\\'", $this->getParameterValue('edit.fields.'.$column->getName().'.name')) ?>:'), '<?php if ($column->isNotNull()): ?>class="required" <?php endif; ?>') ?] 
    5757  <div class="content[?php if ($sf_request->hasError('<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}')): ?] form-error[?php endif; ?]"> 
    5858  [?php if ($sf_request->hasError('<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}')): ?] 
  • trunk/lib/helper/FormHelper.php

    r1432 r1433  
    6767  foreach ($options as $key => $value) 
    6868  { 
    69   if (is_array($value)) 
    70  
    71     $optgroup_html_options = $html_options; 
    72     unset($optgroup_html_options['include_custom']); 
    73     unset($optgroup_html_options['include_blank']); 
    74     $html .= content_tag('optgroup', options_for_select($value, $selected, $optgroup_html_options), array('label' => $key)); 
    75  
    76   else  
    77  
     69    if (is_array($value)) 
     70   
     71      $optgroup_html_options = $html_options; 
     72      unset($optgroup_html_options['include_custom']); 
     73      unset($optgroup_html_options['include_blank']); 
     74      $html .= content_tag('optgroup', options_for_select($value, $selected, $optgroup_html_options), array('label' => $key)); 
     75   
     76    else  
     77   
    7878      $option_options = array('value' => $key); 
    79      
     79       
    8080      if ( 
    8181          isset($selected) 
     
    9090 
    9191      $html .= content_tag('option', $value, $option_options)."\n"; 
    92  
     92   
    9393  } 
    9494 
     
    133133  } 
    134134 
    135   return content_tag('select', $option_tags, array_merge(array('name' => $name, 'id' => $id), $options)); 
     135  return content_tag('select', $option_tags, array_merge(array('name' => $name, 'id' => get_name_from_id($id)), $options)); 
    136136} 
    137137 
     
    184184function input_tag($name, $value = null, $options = array()) 
    185185{ 
    186   return tag('input', array_merge(array('type' => 'text', 'name' => $name, 'id' => $name, 'value' => $value), _convert_options($options))); 
     186  return tag('input', array_merge(array('type' => 'text', 'name' => $name, 'id' => get_name_from_id($name, $value), 'value' => $value), _convert_options($options))); 
    187187} 
    188188 
     
    313313    return 
    314314      content_tag('script', javascript_cdata_section($tinymce_js), array('type' => 'text/javascript')). 
    315       content_tag('textarea', $content, array_merge(array('name' => $name, 'id' => $id), _convert_options($options))); 
     315      content_tag('textarea', $content, array_merge(array('name' => $name, 'id' => get_name_from_id($id, $value)), _convert_options($options))); 
    316316  } 
    317317  elseif ($rich === 'fck') 
     
    372372  else 
    373373  { 
    374     return content_tag('textarea', (is_object($content)) ? $content->__toString() : $content, array_merge(array('name' => $name, 'id' => $id), _convert_options($options))); 
     374    return content_tag('textarea', (is_object($content)) ? $content->__toString() : $content, array_merge(array('name' => $name, 'id' => get_name_from_id($id, null)), _convert_options($options))); 
    375375  } 
    376376} 
     
    378378function checkbox_tag($name, $value = '1', $checked = false, $options = array()) 
    379379{ 
    380   $html_options = array_merge(array('type' => 'checkbox', 'name' => $name, 'id' => $name, 'value' => $value), _convert_options($options)); 
     380  $html_options = array_merge(array('type' => 'checkbox', 'name' => $name, 'id' => get_name_from_id($name, $value), 'value' => $value), _convert_options($options)); 
    381381  if ($checked) $html_options['checked'] = 'checked'; 
    382382 
     
    386386function radiobutton_tag($name, $value, $checked = false, $options = array()) 
    387387{ 
    388   $html_options = array_merge(array('type' => 'radio', 'name' => $name, 'value' => $value), _convert_options($options)); 
     388  $html_options = array_merge(array('type' => 'radio', 'name' => $name, 'id' => get_name_from_id($name, $value), 'value' => $value), _convert_options($options)); 
    389389  if ($checked) $html_options['checked'] = 'checked'; 
    390390 
     
    935935} 
    936936 
     937function label_for($id, $label, $options = array()) 
     938{ 
     939  $options = _parse_attributes($options); 
     940 
     941  return content_tag('label', $label, array_merge(array('for' => get_name_from_id($id, null)), $options)); 
     942} 
     943 
     944function get_name_from_id($name, $value = null) 
     945{ 
     946  // check to see if we have an array variable for a field name 
     947  if (strstr($name, '[')) 
     948  { 
     949    $name = str_replace( 
     950        array('[]', '][', '[', ']'), 
     951        array((($value != null) ? '_'.$value : ''), '_', '_', ''), 
     952        $name 
     953    ); 
     954  } 
     955 
     956  return $name; 
     957} 
     958 
    937959function _add_zeros($string, $strlen) 
    938960{