CakePHP 3.0 Radio Button

In CakePHP 2.0, I can add the attributes 'before', 'after' and 'separator' to the switch. Attributes will create a div element between my radio options. It seems that these options have been removed from CakePHP 3.0. How can I do this in CakePHP 3.0?

<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6"> <div class="square-screening single-row screen-radio"> <?php echo $this->Form->input('q1',array( 'legend'=> false, 'type'=>'radio', 'options'=> $options, 'required'=>'required', 'before' => '<div class="radio-inline screen-center screen-radio">', 'separator' => '</div><div class="radio-inline screen-center screen-radio">', 'after' => '</div>', )); ?> </div> </div> 
+5
source share
2 answers

You need to use FormHelper Templates . From the migration guide:

The separation parameters between and legend have been removed from the radio (). You can use templates to modify the HTML wrapper.

The div, before, after, between, and errorMessage parameters have been removed from input ().

so in your case use this

 echo $this->Form->input('q1', [ 'templates' => [ 'radioWrapper' => '<div class="radio-inline screen-center screen-radio">{{label}}</div>' ], 'type' => 'radio', 'options' => $options, 'required' => 'required', 'label' => false ]); 

See also:

+8
source

It is very easy.

You can use the form helper.

 Cake\View\Helper\FormHelper::radio(string $fieldName, array $options, array $attributes) 

Using

 echo $this->Form->radio( 'favorite_color', [ ['value' => 'r', 'text' => 'Red', 'style' => 'color:red;'], ['value' => 'u', 'text' => 'Blue', 'style' => 'color:blue;'], ['value' => 'g', 'text' => 'Green', 'style' => 'color:green;'], ] ); 

Documents

+1
source

All Articles