Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameter via submit input without javascript?

Tags:

html

forms

submit

I have a form that contains multiple submit buttons. How can I pass a parameter submitting the form to find out which submit has been pressed? No JavaScript allowed.

like image 532
Sergejs Avatar asked Mar 28 '26 05:03

Sergejs


2 Answers

Assuming you have 2 or more buttons like this:

<input type="submit" name="SubmitButtonOne" value="Button One"/>
<input type="submit" name="SubmitButtonTwo" value="Button Two"/>

Check for the names of the buttons, in the submitted (POST) data.

In PHP for example, that would be:

if (isset($_POST['SubmitButtonOne'])){
    //Do something.
}elseif (isset($_POST['SubmitButtonTwo'])){
    //Do something.
}

Or, check for the submitted values:

<input type="submit" name="formSubmit" value="Button One"/>
<input type="submit" name="formSubmit" value="Button Two"/>
switch ($_POST['formSubmit']) {
    case 'Button One':
        //Do something.
        break;
  case 'Button Two':
        //Do something else.
        break;
}
like image 70
Cerbrus Avatar answered Mar 29 '26 22:03

Cerbrus


Only the button that submitted the form will be sent to the server. So just create multiple submit buttons with different names, and then check which button is present in the POST data.

like image 41
Jan Hančič Avatar answered Mar 29 '26 22:03

Jan Hančič



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!