Open In App

How to use formaction attribute in HTML ?

Last Updated : 16 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to use the formaction attribute in HTML. Basically, the information attribute is used to define where to send the data of the form after submitting the form the working of formaction will begin. It overrides the feature of the action attribute of the <form> element

Why do we use formaction Attribute

Let’s suppose, we have two submit buttons in one form and both the buttons work separately and redirect to another URL of the page. Both buttons send data to different pages.

Values: It contains the physical address of the location of the file where to send the form data. 

Two possible values are –

  • absolute URL: It points to the full address of a page. For example “www.geeksforgeeks.org/data-structure”
  • relative URL: It is used to point to a file within a webpage. For example gfg.php

Example: In this example, we will use the formaction attribute in HTML

HTML




<!DOCTYPE html>
<html>
   
<head>
    <title>
        How to use formAction Attribute in HTML ?
    </title>
</head>
   
<body style="text-align:center;">
    <h1>
        GeeksForGeeks
    </h1>
    <h2>
        How to use formAction Attribute in HTML?
    </h2>
    <form method="get" target="_self">
        Username:<input type="email" name="ename"><br><br>
        Password <input type="password" name="passwrd"><br>
        <input type="submit"
               value="submit for Java User"
               formaction=
 
        <input type="submit"
               value="submit for python User"
               formaction=
    </form>
</body>
 
</html>


Output:

  • After Click on the Submit for Java user Button: 

  • After Click on the Submit for Python user Button:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads