HTML Form tag ~ PinoySourceCode

Friday, April 25, 2014

HTML Form tag

When creating textbox. labels,textarea , radio button etc. So this necessary to send these control value to the server.

code:

<form name="formanme" action="action.php" method="post">
your input box, textbox etc..
</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.

Exercise:

<html>
<head>
<title>Exercise</title>
</head>
<body>
<form name="formanme" action="action.php" method="post">
User Name<input name="username" type="text" /><br />
</form>
</body>
</html>

save this php script and name it of index.php.


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

====================================
To Retrieve the value of form
For reterive value of Form tag use super global variable like $_GET and $_POST
$_POST['fieldname']         when method is post on form tag.
$_GET['fieldname']           when method is get on form tag.
====================================

This the code to retrieve the value of the form index.php

<html>
<head>
<title>test1</title>
</head>
<body>
<?php

$user=$_POST['username'];
echo $name;

?>

</body>

</html>

Save this script action.php

How to use get method?

a.php

<html>
<head>
<title>exercise1</title>
</head>
<body>
<form name="frm" action="b.php" method="get">
Enter name:<input name="name" type="text"/><br />
<input name="submit" type="submit" value="Submit" />
</form>
</body>
</html>

v.php

<html>
<head>
<title>exercise1</title>
</head>
<body>

<?php

$name=$_GET['name'];
echo $name;

?>
</body>
</html>

isset()

isset is very usefull function when you send value of the form to the server and reterive value.
isset function is use to check variable exists or not exist.

 This return true if variable exists otherwise this return false.

Why we use isset function and benefit of isset function.


When we send value of the server we check $_POST['fieldname'] 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 to another page.

<?php

if(isset($_POST['submit']))
{
echo $_POST['name'];
}

?>
<html>
<head>
<title>Exercise</title>
</head>
<body>
<form name="" action="" method="post">
<input name="name" type="text"><br>
<input name="submit" type="submit" value="Submit" />

</form>
</body>
</html>

0 (mga) komento:

Post a Comment

Get updates

Twitter Facebook Google Plus LinkedIn RSS Feed Email

Get Free Updates in Your Email


Enter your email address:

Popular Posts