1

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?

Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
  • The example works just fine... you'll have to do some debugging to figure where exactly the value is being lost (maybe that's not the exact code that you're using, maybe your form is being modified on the client side, maybe the value is not being submitted in the first place, maybe the request data is being modified before you access it, etc...). – ndm May 30 '17 at 12:13

1 Answers1

0

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. :)

bikash.bilz
  • 821
  • 1
  • 13
  • 33