HTML Form Action

From CoderLearner
Jump to: navigation, search

Description

The action in the HTML form tag is used to define the server side script to process the HTML form. When user submit the form, the form's elements will be processed by the server side script.

Syntax

 <form action="path/program">
  
 </form>

Example 1

<!DOCTYPE html>
<html>
    <head>
        <title>Form Action</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <form action="sayhi.php">
            <input type="text" name="text_name"/>
            <input type="submit"/>
        </form>
    </body>
</html>

sayhi.php

<?php

if ($_REQUEST['text_name']) {
    echo $_REQUEST['text_name'];
} else {
    echo 'nothing';
}
?>

Example 2

Form without the action attribute value.

<!DOCTYPE html>
<html>
    <head>
        <title>Form Action</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <form action="">
            <input type="text" name="text_name"/>
            <input type="submit"/>
        </form>
    </body>
</html>

<seo metagenerator="HTML Beginner Form,HTML Form" title="HTML Form Beginner Tutorial" metakeywords="HTML form, Design HTML Form, HTML Form INput" metadescription="HTML Form Input, HTML Form Tutorial,HTML For Beginner, HTML Tutorial, HTML Sample Script, HTML Reference"/>