Sending data from a HTML from via php (text and submit controls)

The process handling FORMS generally requires two pages, one that implements the form and the other that processes the data loaded in the form.

The minimum code of a form is as follows: for the entry of a person’s name, a text object and a button for sending the data to the server:

<html>
<head>
<title> Data entry form </title>
</head>
<body>
<form method = “post” action = “page2.php”>
Enter your name:
<input type = “text” name = “name”>
<br>
<input type = “submit” value = “confirm”>
</form>
</body>
</html>

This page is completely HTML encoded, that is, a form contains pure HTML marks.

The <form> and </form> mark allows us to define a form on the page. The FORM mark has two properties that we must necessarily initialize: action and method. The action property indicates the name of the file that will receive the data entered by the operator in the form and that will be sent to the server when the (submit) button is pressed. The method property indicates how this data is organized to send it to the server, which can be done using the post or get methods (normally the data from a form is sent using the post method).

To create a text box for entering the name, we must define an object of type “text” and give it a name:

<input type = “text” name = “name”>

The type property allows us to define the type of control and with the name property we indicate the name of the control.
Finally, all forms have a submit button:

<input type = “submit” value = “confirm”>

We also use the input mark but in the type property we indicate that it is a data send button. In the value property we indicate the text that we want to appear on the button.

Now we need a page with a small PHP program that processes the data entered in the form:

<html>
<head>
<title> Capture form data </title>
</head>
<body>
<? php
echo “The name entered is:”;
echo $_REQUEST [‘name’];
?>
</body>
</html>

To access the data in PHP, there is a vector called $_REQUEST indicating as subscript the name of the text box that we define in the form (this name is case sensitive)

In our problem we only show on the screen the value entered on the previous page:

echo $_REQUEST [‘name’];

This article was written by admin

Leave a Reply