HTML Submit Button

A submit button sends the form's successful controls to the URL defined by the form's action, using the form's method.

<form action="save.php" method="post">
  <label for="name">Name</label>
  <input type="text" id="name" name="name">

  <button type="submit">Submit</button>
</form>
Two common forms are valid: <input type="submit"> and <button type="submit">. The button element is more flexible because it can contain formatted text or other phrasing inside the button.

Using input type=submit Top ↑

The classic submit control uses an <input> element:

<input type="submit" name="submitbtn" value="Submit">

The value attribute supplies the text shown on this type of submit button.

Using button type=submit Top ↑

The <button> element is often more convenient because its visible label is placed between the opening and closing tags:

<button type="submit">Submit</button>

Be explicit about the type when a button is inside a form:

<button type="submit">Save</button>
<button type="button">Preview</button>
Inside a form, a plain <button> defaults to submit behavior. Use type="button" for a button that should not submit the form.

Submit Button Attributes Top ↑

AttributePurpose
type="submit"Makes the control submit the form.
nameDefines the submitter field name when that button is used to submit.
valueDefines the submitted value; for input type="submit", it also supplies the visible button text.
disabledPrevents the button from being used and excludes it from normal submission.
formactionOverrides the form's action for this submit button.
formmethodOverrides the form's method for this submit button.
formenctypeOverrides the form encoding type for this submit button.
formtargetOverrides where the response is displayed.
formnovalidateSubmits without browser constraint validation.

name and value Top ↑

A submit button can contribute its own name/value pair when it is the button used to submit the form.

<button type="submit" name="action" value="save">Save</button>

If that button submits the form, the request includes a value equivalent to:

action=save

This is useful when one form has several submit actions.

Multiple Submit Buttons Top ↑

Two submit buttons can share the same name but use different values:

<form action="article.php" method="post">
  <button type="submit" name="action" value="save">Save Draft</button>
  <button type="submit" name="action" value="publish">Publish</button>
</form>

The server can distinguish which submit button was used from the submitted action value.

Using two submit buttons in one form

Override Form Action with formaction Top ↑

The formaction attribute lets a submit button send the same form to a different URL than the form's normal action.

<form action="save.php" method="post">
  <button type="submit">Save</button>
  <button type="submit" formaction="preview.php">Preview</button>
</form>

This provides a modern HTML solution for several workflows that older tutorials handled entirely with scripting.

Override Method with formmethod Top ↑

A submit button can also override the form method:

<form action="search.php" method="get">
  <button type="submit">Search</button>
  <button type="submit" formaction="save-search.php" formmethod="post">Save Search</button>
</form>

Use GET for retrievable requests such as searches and POST for requests that create or change server-side state.

Open Submission in Another Target Top ↑

formtarget overrides the form's target for one submit button:

<button
  type="submit"
  formaction="preview.php"
  formtarget="_blank"
>Preview in New Tab</button>

See submitting a form to a new window or tab.

formnovalidate Top ↑

If a form contains browser validation constraints, one submit button can bypass them with formnovalidate:

<button type="submit">Submit</button>
<button type="submit" name="action" value="draft" formnovalidate>Save Draft</button>
formnovalidate affects only browser-side constraint validation. The server must still validate any submitted data appropriate to that action.

Disabled Submit Button Top ↑

<button type="submit" disabled>Submit</button>

A disabled submit button cannot normally be activated and does not contribute its name/value pair to form submission.

Disabling a button in HTML or JavaScript is a user-interface choice, not an authorization control. The server must independently decide whether a request is permitted.

JavaScript Validation and Submission Top ↑

JavaScript can validate or enhance a form before submission, but important validation must also run on the server.

JavaScript form validation

Avoid disabling the submit button permanently after the first click without handling validation errors or failed requests. Users must be able to correct the form and submit again when needed.

Common Submit Button Mistakes Top ↑

Using a button without type inside a form Top ↑

A plain <button> inside a form defaults to submit behavior. Use type="button" for buttons that should not submit.

Confusing the visible text with the submitted value Top ↑

For input type="submit", the value is both the displayed label and the submitted value. For button type="submit", the visible label is its content and the submitted value comes from its value attribute when provided.

Assuming every submit includes every button Top ↑

Only the submitter button normally contributes its own name/value pair. This is useful for identifying which of several actions the user chose.

Using JavaScript when HTML submitter attributes are enough Top ↑

For different actions, methods or targets, consider formaction, formmethod and formtarget before adding script.

Relying only on browser validation Top ↑

HTML and JavaScript validation improve usability but do not replace server-side validation.

Using a disabled button as a security control Top ↑

Users can construct requests independently of the interface. Authorization belongs on the server.

Frequently Asked Questions Top ↑

Q1: How do I create a submit button in HTML?

Use either input type="submit" or button type="submit".

Q2: What is the difference between input type="submit" and button type="submit"?

Both submit a form. Input uses its value as the button text, while button places visible content between opening and closing tags and is more flexible.

Q3: Can one form have more than one submit button?

Yes. Different name/value combinations or submitter attributes can identify and control different actions.

Q4: What does formaction do?

It overrides the form's action URL for the submit button that was used.

Q5: What does formmethod do?

It overrides the form's method, such as GET or POST, for that submit button.

Q6: What happens if button type is omitted inside a form?

A button element inside a form defaults to submit behavior, so specify type="button" when submission is not intended.

Q7: Does formnovalidate remove the need for server validation?

No. It only bypasses browser constraint validation for that submission. Server-side validation is still required.


Buttons in Form Reset Button HTML Form



plus2net.com










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer