get my inputs inside my labels with CakePHP's FormHelper::radio() method -


i've looked quite thoroughly through previous questions , i'm surprised nobody else has asked yet because seems pretty simple thing.

how make labels wrap inputs label text using cakephp's formhelper? using cakephp 2.3.1. call $this->form->radio() standard options yields:

<input id="input_id" type="radio" ... /> <label for="input_id">label text</label> 

what i'm looking is

<label for="input_id"><input type="radio" id="input_id" ... />label text</label> 

i have achieved sort of using:

$this->form->input('input1',array('options'=>$options,'type'=>'radio',     'label'=>false     'before'=>'<label>',     'separator'=>'</label><label>',     'after'=>'</label>' )); 

but solution not ideal. can tell me if cakephp has easier , "more proper" way achieve this?

extend helper, , make own method.

<?php // app/views/helpers/radio.php class radiohelper extends apphelper {      function display($id, $options = array()) {         if (isset($options['options']) && !empty($options['options'])) {             $rc = "";             foreach ($options['options'] $option) {                 $rc .= "<label>";                 $rc .= "<input ....>";                 $rc .= "</label>";             }             return($rc);         }         return(false); // no options supplied.     } }  ?> 

<?php  // some_controller.php var $helpers = array('radio');  ?> 

<?php   // some_view.ctp echo $this->radio->display('input1', array('options' => $options));  ?> 

just make sure copy logic form helper own helper here...

p.s. if you're adding single method, it's not you'll need entire helper. add function "display" app_helper.php , reference "other" helper loaded, since extend app_helper, you'll have display method available in child helpers.


Comments