Forms

Forms

If you have to give some data (eg. To be added to the database), then the only way is to download them from the standard HTML form. In most programming languages ​​use additional libraries to access the data sent from the form. The PHP has been simplified.

All the data from the form go to the appropriate associative array of key names, such as the names of the form fields. If a PHP configuration option register_globals is enabled (it is disabled by default since version 4.2.0), it will be created once the variables with names such as the names of the form fields.
There are two methods of passing parameters to other websites: „GET” and the method „POST”. GET method is used when the parameters are few. This is because the parameters shall be by means of a URL (eg. Http://www.nnn.pl/strona.php?parametr1=wartość1&parametr2=wartość2), whose length is limited. Please also note that the parameters are visible in the browser address bar, so this method should not be used if you are transferred eg. Password. As you can see, the same address parameters is separated by a question mark and another parameter = value pairs using the ampersand character ( „&”). This method can also be used in the transmission parameters by reference.

The method „POST” to pass parameters using the headline question – enough to know that this method enables the transfer of much larger parameters, and the parameters that you can not see in the browser bar.
Depending on the method, variables, go to the appropriate associative arrays. The data transferred using GET go to the $ _GET array (or $ HTTP_GET_VARS in versions older than 4.1.0) and data from the POST method to the array $ _POST (or $ HTTP_POST_VARS). Arrays $ _GET and $ _POST are Superglobal. This means that they are visible all over the place PHP code without the use of syntax globals.

Example
file one.html

<html>
<head>
<title>

test form
</ title>
</ head>
<body>
<form action = „dwa.php” method = „GET”>
name: <input type = text name = „name” /> <br/>

name: <input type = text name = „name” /> <br/>
Please invoice for the order: <input type = checkbox name = „invoice” /> <br/>
I want to order: <br/>
<Input type = Order a radio name = value = „Coca-cola” /> Coca-Cola <br>

<Input type = Order a radio name = value = „fanta” /> Fanta <br>
<Input type = Order a radio name = value = „sprite” /> Sprite <br>
<Input type = submit value = „Submit” />
</form>
</body>

</html>

file two.php

<html>
<head>
<title>
Results
</title>
</head>

<body>
name: <?php echo $ _ GET [ ‚name’]?> <br>
name: <?php echo $ _ GET [ ‚name’]?> <br>
invoice: <?php echo ($ _ GET [ ‚invoice’] == ‚on’? ‚Yes’, ‚No’)?> <br>

Order: <?php switch ($ _ GET [ ‚order’]) {
case „Coca-cola”:
echo „Coca-Cola”;
break;
case „fanta”:
echo „Fanta”
break;
case „sprite”:
echo „Sprite”
break;
}
?>

</body></html>

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close