View cake variable value in html

Asked

Viewed 19 times

0

Hello, I have a form and would like to know how I can display the value that is in a variable of cake, in my html code, to display in edit.

Explaining better: When registering a new data, I can register several victims (there was a boot that calls a function to register another victim), and this is working, but in editing I needed to display all the victims who are registered, I don’t know how to do this with html code, the code snippet is : <input name="victim[]" class="form-control" id="inputName" placeholder="vítima"> and <?= $this->Form->victim ?>, the variable the information is stored is : $request->victims which is an array

                        <div class="col-sm-12 pad_entry_book">
                            <button type="button" class="btn btn-success" onclick="insertVictim()"><i class="text-white fa fa-plus"></i></button>
                            <button type="button" class="btn btn-danger" onclick="removeVictim()"><i class="text-white fa fa-minus"></i></button>
                        </div>

                        <div id="insert-row">
                            <div id="input0" class="col-sm-3 pad_entry_book">
                                <label>Vítima</label>
                                <div>
                                    <?=var_dump($request->victims)?>

                                    <input name="victim[]" class="form-control" id="inputName" placeholder="vítima">
                                </div>
                            </div>
                            <?= $this->Form->victim ?>

                        </div>

                        <script>
                            var cont = 1;


                            function insertVictim() {
                                $("#insert-row").append("<div id='input" + cont + "' class='col-sm-3 pad_entry_book'>" +
                                    "<label>Vítima</label>" +
                                    "<div>" +
                                    "<input name='victim[]' class='form-control' id='inputName' placeholder='vítima'>" +
                                    "</div>" +
                                    "</div>"
                                );
                                cont++;
                            }

                            function removeVictim() {
                                if (cont != 1) {
                                    cont--;
                                    $('#input' + cont + '').remove();
                                }
                            }
                        </script>
                    </div>
                    <!-- parte7-->

What is brought in the variable $request->victims :

    "victims": [
        {
            "id": 3,
            "name": "maria",
            "created": "2020-11-01T18:16:55+00:00",
            "_joinData": {
                "victim_id": 3,
                "request_id": 2
            }
        },
        {
            "id": 4,
            "name": "joao",
            "created": "2020-11-01T18:16:55+00:00",
            "_joinData": {
                "victim_id": 4,
                "request_id": 2
            }
        }
    ],
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.