Kim Stacks
Kim Stacks

Reputation: 10812

How to ensure that empty select multiple option still will show up as key in request->data in cakephp3?

I am using select. I want to ensure that in CakePHP3 FormHelper, I always have the key inside request->data regardless if it is empty.

Currently, my code is

<?= $this->Form->select('rooms[]', $rooms, ['id' => 'room-tags', 'multiple', 'empty' => '']); ?>

I have tried hiddenField. It does not work.

I need to ensure that inside request->data I will always have the key rooms which points to an empty array.

Upvotes: 0

Views: 68

Answers (1)

ndm
ndm

Reputation: 60453

You are defining the multiple option wrong, while passing it as a value makes it into the HTML element as an attribute, the form helper will not be recognize it as an option.

This is how you have to define it in order to for it to act as a option.

'multiple' => true

Upvotes: 1

Related Questions