Submit a form with a button (HTML)
Asked Answered
R

1

20

I am making a program that would post on a webpage, to submit the form it has to "click" on a button:

<button class="form" type="submit">Send</button>

From what I know (not much) to submit a POST request when it's INPUT you must do name=value, but I don't know how I could do that with a submit button.

Basically I want to know what I must POST to the website so that it submits the form :p

Roxannaroxanne answered 21/3, 2015 at 19:31 Comment(0)
H
35

Here's basic syntax for a form:

<form>
  <input name="name" type="text"/>
  <button type="submit"> Send </button>
</form>

Whatever backend you are using should be able to read POST request parameter "name" to read what that form contains.

If you're trying to make a form with just that one button, you can do that by just skipping that input element. Of course, there will be no data in that post request, but you can add the action attribute to the containing form and set it equal to a URL where you would like to redirect the user on button click.

Hands answered 22/3, 2015 at 1:47 Comment(1)
This form will not POST data as there is no method attribute - the default method used by forms is GET so the comment Whatever backend you are using should be able to read POST request parameter "name" is incorrect.Pedrick

© 2022 - 2024 — McMap. All rights reserved.