-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Determine Which Button Submitted The Form | ||
|
||
It is pretty common for a form to have a singular submit button. If the user clicks 'Submit', then the form fires a `POST` off to the server, the server can process the request, and that's it. | ||
|
||
But what about a form that has two or more buttons? For instance, imagine some kind of consent form where the user needs to either _Accept_ or _Reject_ some terms. | ||
|
||
Just like other inputs, [the `<button>` tag can take both `name` and `value` attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-name). | ||
|
||
```html | ||
<form action="/terms" method="post"> | ||
<p>Something about the terms ...</p> | ||
<div> | ||
<label for="name">Email: </label> | ||
<input type="email" name="email" id="email" required> | ||
</div> | ||
<div> | ||
<button type="submit" name="commit" value="accept">Accept</button> | ||
<button type="submit" name="commit" value="reject">Reject</button> | ||
</div> | ||
</form> | ||
``` | ||
|
||
In addition to the `email` attribute, when the user submits the form, it will include a `commit` attribute that has a value of either `'accept'` or `'reject'`. | ||
|
||
|