button value not working in cakephp 3

197 Views Asked by At

I'm using CakePHP 3.4

I have a form with two submit buttons like

<?= $this->Form->create($post) ?>
    <?= $this->Form->control('title') ?>

    <button name="submit_type" value="draft" type="submit">Draft</button>
    <button name="submit_type" value="publish" type="submit">Publish</button>
<?= $this->Form->end() ?>

According to w3schools button value is also sent to server.

But when I debug

debug($this->request->getData('submit_type'));

it gives NULL. Also debugging getData(), it gives only title field.

How to get value of submit button?

1

There are 1 best solutions below

0
On

I had the same problem. Try to use "input type" instead of "button", like

<input name="submit_type" value="Draft" type="submit" />
<input name="submit_type" value="publish" type="submit"/>

Hope, this will help you. :)