LoginSignup
0
0

More than 5 years have passed since last update.

cakephp3 ラジオボタンのグループ化

Last updated at Posted at 2018-09-07

radio ボタンを グループ化したい。

hoge.ctp


    <?php
    $this->Form->templates([
        'nestingLabel' => '<label class="btn btn-default">{{input}}{{text}}</label>',
        'radioWrapper' => '{{label}}',
    ]);
    ?>

    <label class="control-label">どちらで登録しますか?</label>

    <div class="form-group text">

        <div class="btn-group btn-group-justified" data-toggle="buttons">
            <?php

//            デフォルト値をセット
            $default_value = 1;
            if(!empty($this->request->data['mode'])){
                $default_value = $this->request->data['mode'];
            }

            ?>

            <?=$this->Form->radio('mode',
                [
                    1 => '会員登録 ',
                    2 => '一般利用者'
                ],
                [
                    'label' => [
                        'class' => 'btn btn-default'
                    ],
//                    hidden があると ボタンが四角になるので false にしておく
                    'hiddenField'=>false,

//                    なぜか default が効かないので
                    'value' => $default_value
                ]
            );?>

        </div>


    </div>



    <script>

        $(function () {
            //ボタンを アクティブにする
            $("input:checked").parent().addClass('active')
        });

    </script>


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0