Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining which submit button was used?

Is it possible to determine which submit button was used? I have a confirmation form with 2 submit buttons. The first would confirm the order, do some DB tasks, then redirect. The second, which is a Cancel button, will just redirect to the same page, without doing any DB tasks.

Is it possible in the servlet, preferably via the request object, to determine which submit button was used? I'd prefer not to be dependent on Javascript, as that is pretty simple, but will resort to it if the only possibility.

Thanks.

like image 866
Chris Serra Avatar asked Dec 02 '22 08:12

Chris Serra


2 Answers

<button name="someName" value="someValue" type="submit">Submit</button>
<button name="otherName" value="otherValue" type="submit">Cancel</button>

You'll have someName=someValue or otherName=otherValue in your request data

like image 190
Quassnoi Avatar answered Dec 04 '22 00:12

Quassnoi


Sure, just give each of your submit buttons a name attribute, and whichever one was clicked will appear in the submitted variables:

<input type="submit" name="doConfirm" value="Confirm"  />
<input type="submit" name="doCancel"  value="Cancel"  />
like image 22
Alnitak Avatar answered Dec 03 '22 23:12

Alnitak