Form Action

Next ❯Form Elements

It is actually required to perform some action when the form is submitted

  • There are two ways to perform action:
    1. GET Method
    2. POST Method
  • You need to define action Attribute inside <form> Tag first, it define on which page you are sending the form data
  • Syntax is below
<form action="action_page.php">
<!-- Form elements are defined here-->
</form>
  • Note! If the action attribute is omitted then the action attribute is set to the current page by default

Methods

  • Syntax is below
&lt!--GET Method-->
<form action="action_page.php" method="get">
      <!-- Form elements are defined here-->
</form>
&lt!--POST Method-->
<form action="action_page.php" method="post">
      <!-- Form elements are defined here-->
</form>
  • Note! If method is not set, Default method when submitting form data is GET
  • Note! name Attribute should be compulsory, otherwise it will not send that particular input field
Example:
  • turned_in_notGet Method Example
    <!DOCTYPE html>
    <html>
    <head><title>User Form Get Example</title></head>
    <body>
    <form action="action_page.php" method="get">
    First name: <input type="text" name="first_name" /><br>
    Last name: <input type="text" name="last_name" /><br>
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>

    action_page.php file looks like:

    <!DOCTYPE html>
    <html>
    <head><title>Sample PHP File </title></head>
    <body>
    <?php
    $first_name = $_REQUEST['first_name'];
    $last_name = $_REQUEST['last_name'];
    echo "Welcome <b> ".$first_name." ".$last_name."</b>";
    ?>
    </body>
    </html>
    • You will learn PHP in new Tutorial
  • trending_downAbout Get Method !
    • GET Method has limitation on amount of data (maximum URL length is 2048 characters)
    • When GET is used, the submitted form data will be visible in the page URL field
    • Like above example, on submitting in the URL, it looks like:
       /action_page.php?first_name=XXXXX&last_name=XXXX
    • Note! Don't use when submitting any sensitive information
Example:
  • turned_in_notPOST Method Example
    <!DOCTYPE html>
    <html>
    <head><title>User Form POST Example</title></head>
    <body>
    <form action="action_page.php" method="post">
    Username: <input type="text" name="username" /><br>
    Password: <input type="password" name="pass" /><br>
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>

    action_page.php file looks like:

    <!DOCTYPE html>
    <html>
    <head><title>Sample PHP File </title></head>
    <body>
    <?php
    $u_name = $_REQUEST['username'];
    $pass = $_REQUEST['pass'];
    if($u_name=="Rahul" && $pass=="password"){
    echo "Welcome <b> Rahul </b> you are secularly logged-in!";}
    else{
      echo "Sorry your USERNAME or Password is incorrect! ";
    }
    ?>
    </body>
    </html>
    • You will learn PHP in new Tutorial
  • trending_downAbout POST Method !
    • No limitation on amount of data
    • More Secure than GET Method
    • Never cached
    • can't be bookmarked
    • It's used when using some sensitive data (like: password,card no)
Browsers Supports
SafariMicrosoft EdgeMozilla FirefoxChromeOpera Mini

Click on the above icon to see the name of the browser !

  • Tips! Always try to use latest version of browser

  • Form Elements
❮ Prev Form Overview
Next ❯Form Elements
TryOut Examples"Learn to Explore..!"

TryOut Editor

receipt