formaction
formaction attribute
The formaction
attribute in HTML can be applied to <button>
or <input type="submit">
elements to specify the URL where the form data should be sent upon submission. This attribute overrides the action
attribute of the parent form, allowing different submit buttons within the same form to direct data to different URLs.
Syntax
<tagname type="submit | image" formaction="URL" >
Example
Here’s an example of using the formaction
attribute:
<form>
<input type="text" name="username" placeholder="Username">
<input type="text" name="password" placeholder="Password">
<button type="submit" formaction="/login">Login</button>
<button type="submit" formaction="/register">Register</button>
</form>
In this example, clicking "Login" submits the form data to /login
, while clicking "Register" sends it to /register
.
Values
- URL
- A target URL where the form data is sent for processing.
Applies To
The formaction
attribute is applicable to the following HTML elements.
Example
<form>
<input type="text" name="name" placeholder="Enter your name">
<input type="submit" value="Submit to Products">
<input type="submit" value="Submit to Contact Us">
</form>
Conclusion
The formaction
attribute enables you to define a specific URL for submitting form data, bypassing the form's default action. It works with <button>
and <input type="submit">
elements, allowing multiple submit buttons within the same form to send data to different destinations. This ensures that the data is directed to the appropriate endpoint based on the button pressed.
form
The form attribute in HTML links an input or form element to a separate form, allowing elements to be positioned independently while still being submitted as part of the same form.
formnovalidate
The formnovalidate attribute allows form submission without triggering validation checks when used with <button> or <input type="submit">, bypassing the default validation rules.