DANLEE
DANLEE

Reputation: 453

Radio Button CakePHP 3.0

In CakePHP 2.0 I can actually add 'before', 'after' and 'separator' attributes to the radio button. The attributes will create a div element between my radio options. It seems like these options have been removed from CakePHP 3.0. How can I do that 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>

Upvotes: 6

Views: 8226

Answers (2)

user1418909
user1418909

Reputation:

You need to use FormHelper Templates. From migration guide:

The separator, between, and legend options have been removed from radio(). You can use templates to change the wrapping HTML now.

The div, before, after, between and errorMessage options 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:

Upvotes: 9

Soft Kitty
Soft Kitty

Reputation: 11

It so very easy.

You can use 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;'],
    ]
);

Docs

Upvotes: 1

Related Questions