Open In App
Related Articles

How to specify the URL that will process the data supplied through input(s) when the form is submitted?

Improve Article
Improve
Save Article
Save
Like Article
Like

The HTML <input> formaction attribute is used to specify the URL of the file which will process the input control when the form is submitted. After submission of the form, the formaction attribute is called. The form data is to be sent to the server after the submission of form. It overrides the action attribute of the <form> element.

Syntax: 

<input type = "submit" formaction = "URL">

The possible value of URL are as follows.

  • Absolute URL: It contains the full address of the page. For example “https://www.geeksforgeeks.org/c-plus-plus/”
  • Relative URL: It points to a file within the current webpage. For example “gfg.php”

Example :  The following example defines to specify the URL which will process the data supplied when the form is submitted.

HTML




<!DOCTYPE html>
<html>
  <body style="text-align: center">
    <h1>GeeksForGeeks</h1>
  
    <h2>HTML input formAction Attribute</h2>
    <!--Form stays in the same page -->
    <form action="#" method="get" target="_self">
      <label for="fname">Username</label>
      <input type="text" 
             id="userName" 
             name="userName" />
      <br /><br />
      <label for="lname">Password</label>
      <input type="password" 
             id="password" 
             name="password" />
      <br /><br />
      <!--The data is send to "test.php" after submit -->
      <input
        type="submit"
        id="gfg"
        name="geeks"
        value="Submit @ GFG"
        formtarget="_blank"
        formmethod="post"
        formaction="test.php"
      />
    </form>
  </body>
</html>


Output:


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 27 Apr, 2021
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials