Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit a form with a button (HTML)

Tags:

html

forms

submit

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

like image 902
taze totero Avatar asked Mar 21 '15 19:03

taze totero


People also ask

Can you use a button to submit a form?

Using submit buttons<input type="submit"> buttons are used to submit forms. If you want to create a custom button and then customize the behavior using JavaScript, you need to use <input type="button"> , or better still, a <button> element.

Do HTML forms need a submit button?

If you don't have any submit button it is acceptable after all it is an element of form tag and if it is not required you may not add it with in form .

How do I submit a form with an external button?

You can tie a submit button to a form that the button doesn't live inside of. The trick is to give the form an id and then reference that id with the button's form property. With this setup, clicking the Submit button will cause the form to be submitted.

Should I use input or button for Submit?

input suggests that the control is editable, or can be edited by the user; button is far more explicit in terms of the purpose it serves. Easier to style in CSS; as mentioned above, FIrefox and IE have quirks in which input[type="submit"] do not display correctly in some cases.


1 Answers

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.

like image 81
Antrikshy Avatar answered Oct 24 '22 19:10

Antrikshy