6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cakephp3.x系でformをつかってPOSTを送る

Last updated at Posted at 2016-06-25

CakePHP3でformを作った時に、例があんまりなかったり、2系の情報見てうまくいかなかったりしたのでめも

    <?=$this->Form->create(null,['type' => 'post'])?>
    <ul class="list">
        <?= $this->Form->input('reportType', [
            'type' => 'radio',
            'options' => [
                ['value' => 'blue', 'text' => '青'],
                ['value' => 'mint', 'text' => 'ミントグリーン'],
                ['value' => 'red', 'text' => '赤']
                ['value' => 'white', 'text' => '白']
                ['value' => 'purple', 'text' => '紫']
                ['value' => 'yellow', 'text' => '黄']
            ],
            'templates' => [
                'nestingLabel' => '{{input}}<label{{ attrs }}>{{ text }}</label>',
                'radioWrapper' => '<li class="listItem">{{ label }}</li>'
            ],
            'label' => false, //デフォルトはtrue trueのままでいい場合に明示的に入れるとlabelが表示されるべきところに 1 とか出力される罠マジでビビる
        ]); ?>
    </ul>
    <?=$this->Form->submit('推し',['class' => 'submitbtn',
        'id' => 'fn-reportSubmitBtn', 'submitContainer' => '{{ content }}']) ?>
    <?=$this->Form->end() ?>

ハマったこと

'div' => false は使えなくて消したかったらtemplatesをいじるしかないっぽいです。divもclassも消えなくてはまっていました。
templateを使えば自分の好きなように項目の前後などにほしいタグが出力されたりもするので便利です。

6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?