Form Tag
About HTML Form Tag

When we create input box. check box, radio button etc. So this necessary to send these control value to the server. So Form tag is use to send these control value to the server.

code:-

<form name="frm" action="test2.php" method="post">
your input box, check box etc here.
</form>

name :-  name of the form
action :- write page name on which page you want to send values. if you take action blank like action="" then values send on same page.
method :- there are two method post and get.
post send value to the server but values not show on URL.
get send value to the server but values show on URL.

Example 1:- Simple Form Tag Example

<html>
<head>
<title>test1</title>
</head>
<body>
<form name="frm" action="test1.php" method="post">
Enter Name<input name="name" type="text" /><br />
<input name="btnsubmit" type="submit" value="Submit" />
</form>
</body>
</html>

 

save this php script by name of test1.php.

In this code we use action="test1.php" then these control value send to test1.php page We reterive these value on test1.php page and can print it. Now make another page test1.php for reterive these values

How to reterive value of Form tag.

For reterive value of Form tag use super global variable
$_POST['controlname'] when method is post on form tag.
$_GET['controlname'] when method is get on form tag.

Example 1:- PHP script to reterive form tag value. please save this file test1.php.

<html>
<head>
<title>test1</title>
</head>
<body>
<?php
$name=$_POST['name'];
echo $name;
?>
</body>
</html>

Example 2:- To use of get method

test1.php

<html>
<head>
<title>test1</title>
</head>
<body>
<form name="frm" action="test2.php" method="get">
Enter Gender<input name="gender" type="radio" value="Male" /><br />
<input name="btnsubmit" type="submit" value="Submit" />
</form>
</body>
</html>

test2.php

<html>
<head>
<title>test2</title>
</head>
<body>
<?php
$gender=$_Get['gender'];
echo $gender;
?>
</body>
</html>

isset()

isset function is very usefull when you send value to the server and reterive value.
Now Look functiong of isset function
isset function is use to check variable exists or not. This return true if variable exists otherwise this return false. This is a language construct and not a function.

Now Why we use isset function and benefit of isset function.
When we send value of the server we check $_POST['controlname'] in isset function. when we click on submit button then this variable exits on page and write code inside this section. if variable exits our code run otherwise code not run. if we are not use isset function then code is run without submit the page.

Example 3:- PHP script to use of isset function.

<?php
if(isset($_POST['btnsubmit']))
{
echo $_POST['city'];
}
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form name="frm" action="" method="post">
<input name="city" type="text"><br>
<input name="btnsubmit" type="submit" value="Submit" />
</form>
</body>
</html>

when you click on Submit Then isset will do work.This show Text Box data without submit page echo will not pring $_post['city'] data.


Previous
Next