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>

Related Posts:

  • If else statement in php if statement is use to check condition if condition is true then body of your code will be  execute.Syntaxif (condition){Code body}Exercise 1:&l… Read More
  • 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" … Read More
  • What is PHP? What is PHP?PHP is basically use for web developing dynamic website.Example of dynamic website are facebook.com,google.com etc.About Web DevelopmentW… Read More
  • PHP Loop Loop execute some statement many times till the condition is fullfill. There are three type or loops. these loops do same work execute statement man… Read More
  • Array in PHP Suppose we want to store 100 data item. So we need 100 different variable. So this is very typical work for programmer to manage 100 different variab… Read More

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

A visitor from Ashburn viewed 'PinoySourceCode' 1 day ago
A visitor from Bengaluru viewed 'PinoySourceCode' 1 day 1 hr ago
A visitor from Iriga viewed 'PinoySourceCode' 2 days 18 hrs ago
A visitor from Ashburn viewed 'PinoySourceCode' 3 days 1 hr ago
A visitor from Nairobi viewed 'PinoySourceCode' 3 days 10 hrs ago
A visitor from Laval viewed 'PinoySourceCode' 3 days 15 hrs ago
A visitor from Kigali viewed 'PinoySourceCode' 3 days 15 hrs ago
A visitor from St petersburg viewed 'PinoySourceCode' 4 days 4 hrs ago
A visitor from Hamadan viewed 'PinoySourceCode' 4 days 4 hrs ago
A visitor from California viewed 'PinoySourceCode' 4 days 4 hrs ago