lundi 31 août 2015

CakePHP dynamic form inputs

I'm using CakePHP 2.3.8 and I'm trying to create a form with dynamically added inputs from this tutorial but I'm having some issues. The adding and removing of inputs works just fine, but when I submit the form I get a black hole error message. Upon inspecting the inputs, it doesn't appear as if the key value isn't properly set and causing some issues with the id's of the inputs.

For example, with this code in an element

//Elements/users.ctp
$key = isset($key) ? $key : '<%= key %>';

<tr>
    <td><?php echo $this->Form->input("Role.{$key}.user_id", array('options' => $users, 'label' => false)); ?></td>
    <td class="actions">
        <a href="#" class="remove">Remove User</a>
    </td>
</tr>

this is the select that is generated

<select name="data[Role][0][user_id]" id="Role<%=Key%>UserId">

Edit

The value of $key is being set correctly on /Elements/users.ctp. I can create a row and echo the output of $key, and a number for the row appears correctly. As you can see above, the name of the element is set correctly, but the id is still being set strangely.

The name of the select element is being set properly, but not the id. What is causing the select id to be Role<%=Key%>UserId rather than Role0UserId?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire