lundi 21 janvier 2019

Cakephp 3.6.17: Create and submit form with table and checkbox for each row

I am trying to create a form where the user can check a checkbox for each row of a table. On submit of the form I want to execute some code in the add action of the same controller.

This is my AddElement\index.ctp :

<table cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th scope="col"><?= $this->Paginator->sort('id') ?></th>
            <th scope="col"><?= $this->Paginator->sort('name') ?></th>
            <th scope="col"><?= $this->Paginator->sort('element_category_id') ?></th>
            <th scope="col">Select</th>
        </tr>
    </thead>
    <tbody>
        <?php echo $this->Form->create('AddElement', ['url' => ['action' => 'add']]); ?>
        <?php foreach ($taskElements as $taskElement): ?>
        <tr>
            <td><?= $this->Number->format($taskElement->id) ?></td>
            <td><?= h($taskElement->name) ?></td>
            <td><?= $taskElement->element_category_id != 0 ? $this->Html->link($taskElement->element_category->name, ['controller' => 'ElementCategories', 'action' => 'view', $taskElement->element_category->id]) : '' ?></td>
            <td><?= $this->Form->control('selected', ['type' => 'checkbox']);?></td>
        </tr>
        <?php endforeach; ?>            
    </tbody>
</table><?php
echo $this->Form->button('Add');
echo $this->Form->end();?>

And this is the add action of the AddElementController.php:

public function add($tasktypeid)
{   
    $this->autoRender = false; //no need for view

    debug($this->request->data());
    if($this->request->is('post'))
    {
        debug($this->request->data());
    }

}

But when I click submit it does nothing. Its just loading for a second but it doesn't execute the code in the controller.




Aucun commentaire:

Enregistrer un commentaire