user3201500
user3201500

Reputation: 1618

check if button type=submit name=submit has been clicked in Laravel

i am trying to get which button is clicked from a form. I have 3 buttons in a form here is how my view looks like:

<div class="form-actions">
  <button type="submit" name="submit" class="btn green"><i class="fa fa-check"></i> Submit</button>
  <button type="submit" name="draft" class="btn btn-warning"><i class="fa fa-paper-plane-o"></i> Draft</button>
  <button type="submit" name="Trash" class="btn red"><i class="fa fa-trash-o"></i> Trash</button>
</div>

And here is how i am checking that on my controller:

  if(Button::get('submit')) {
  $request['status'] = 1;
}
elseif(Input::has('draft')) {
  $request['status'] = 2;
} else {
  return "something else"; //i am ending us with this all the time.

}

I am always ending up with something else. when i do the return $request->except('_token'); i get this:

{
  "pagename": "asdfasdf",
  "pagecontent": "<p>asdfasdf<\/p>\r\n",
  "displayfrom": "2016-02-04 00:00:00",
  "submit": "",
  "metatitle": "",
  "metakeywords": "",
  "metadescription": "",
  "user": 11,
  "active": 1
}

I dont know why its not getting the value of a <button type="submit">.

Any suggestions will be helpful. Thank you!

Upvotes: 2

Views: 1947

Answers (1)

paranoid
paranoid

Reputation: 7105

Add this in submit button value="submit"

<button type="submit" value="submit" name="submit" class="btn green">
<button type="submit" value="draft" name="draft" class="btn btn-warning">

Upvotes: 3

Related Questions