<input type="button" name="justabutton" value="I'm just a button">
Will the value name pair of the button be sent in the the post request upon submitting the form?
I tried to use the input of button type as textinput by storing some data into its name attribute and pass it in the post body but couldn’t.
2
Answers
Try this form. Before pressing "Run code snippet" open the dev tools in your browser and open the network tab. Try clicking both buttons and see what happens. The
type="button"
doesn’t do anything. Thetype="submit"
does a GET request that looks like this:/post.php?justasubmitbutton=I%27m+just+a+submit+button
.Conclusion
The value of the
type="button"
is not send in the submit event, but the value oftype="submit"
will.No, it won’t be sent in the
POST
request. The only button that’s automatically included in the post request is the submit button that you clicked on to submit the form (if the form is submitted due to pressing Return in the last text field, it’s as if you clicked on the first submit button).So the value of a button with
type="button"
will never be sent automatically.Use a
type="hidden"
input to pass extra values to the server, not a button.