Jump to: navigation, search

HTML form action

From w3cyberlearnings

Contents

HTML - Form Action

In the form tag, you can define the action attribute. The action attribute is where you can place the URL of the server side program for processing your form.

HTML - Syntax Form Action

  • path: Path to the program
  • program: Server side program name uses to process a form
<form action="path/program">
....
.....
....
</form>

Note

  • It can be empty when you want to use jQuery or javascript to process the form data by using ajax.
  • Form action attribute works along with other attributes in the form elements.

Example 1: Process form with PHP program

  • Use test1.php to process the form data, and its default method is GET HTTP REQUEST
<html>
	<head>
		<title>Test 1</title>
	</head>
	<body>
            <form action="test1.php">
                  Content place here
            </form>
	</body>
</html>

Example 2: Process the form uses Perl program

<html>
	<head>
		<title>Test 2</title>
	</head>
	<body>
            <form action="test1.pl">
                  Content place here
            </form>
	</body>
</html>

Example 2: Process form data within the same program

You can use the same page to generate a form and to process a form data.

  • action="checkme.php" is the same name as the script name.
  • Alternative method, you can use: action="<?php echo $_SERVER['PHP_SELF'];?>"
<html>
	<head>
		<title>Test 2</title>
	</head>
	<body>
            <form action="checkme.php">
                  Content place here
            </form>
	</body>
</html>

Related Link


Navigation
Web
SQL
MISC
References