How to get the data of a "multiselect option" coming from a cell

Hello guys!

I created a cell to assemble a “multiple selection option” and inserted it into a view for the user.

Fill in the fields like this:

<select class="form-control" multiple id="product">
    <?php foreach ($json["data"] as $product):?>
    <option value="<?php echo $product["id"]; ?>"><?php echo $product["name"]; ?></option>
    <?php endforeach; ?>
</select>

I added this cell to a user registration form along with other fields!

<?= $this->cell('Products');?>

How can I get the information selected by the user and send it to the controller after submitting the form?
Can I solve this using the cell?

The form will return in the post the fields which have name specified which was not provided for your generated fields. Try something like: -

<select class="form-control" multiple id="product">
    <?php foreach ($json["data"] as $product): ?>
        <option value="<?=$product['id']?>" name="<?=$product['id']?>"><?=$product['name'];?></option>
    <?php endforeach; ?>
</select>

Without knowing the structure of your JSON array I’m only guessing a fieldname id is unique. If not then create a counter or some such field and use that as your name.

Hi.
I capture the content of the variables sent to the Controller using CakePHP’s methods like so:

$this->request->getData();

You should be aware that the Select element is set to “multiple”, which causes it to return an associative array.