Introduction
Please watch over gently🙇♀️
I will write about cakePHP "Form Helper"!
List of things you will often see.
Overall picture
<?= $this->Form->create(null, ['url' => ['controller' => 'Advices', 'action' => 'index']]); ?> <?= $this->Form->control('title', ['type' => 'text']); ?> <?= $this->Form->hidden( 'user_id', ['value'=>$userID]); ?> <?= $this->Form->button(__('tap')) ?> <?= $this->Form->end() ?>
Create
Cake\View\Helper\FormHelper::create(mixed $context = null, array $options = [])
Basic
$this->Form->create(null);
change action
$this->Form->create(null, ['url' => ['action' => 'publish']]);
change controller & action
$this->Form->create(null, [ 'url' => [ 'controller' => 'Articles', 'action' => 'publish' ] ]);
External
$this->Form->create(null, [ 'url' => 'http://www.google.com/search' ]);
Control
Cake\View\Helper\FormHelper::control(string $fieldName, array $options = [])
Basic
$this->Form->control('title', ['type' => 'text']);
$this->Form->control('title', ['type' => 'checkbox']);
$this->Form->textarea('advice', ['rows' => '3']);
Hide
$this->Form->hidden( 'article_id', ['value'=>'1' ]);
?$this->Form->hidden('id');
Remove required
$this->Form->control('title', ['required' => false]);
button
$this->Form->button('Add');
end
$this->Form->end();
Top comments (0)