
To create a form using HTML you only need to know what type of data you are going to transfer.
First and foremost, all of your form elements should reside inside of two form tags such as:
<form action="myPage.php" method="post">
form elements...
</form>
The first tag, <form action=”myPage.php” method=”post”>, contains an action parameter and a method parameter. These two parameters are crucial to the functionality of your form, so I will explain them in better detail.
The “action” parameter is the location of the page you would like to submit your form to. In other words, it is the page you want the form to go to when you click your submit button. The data that the user has entered will be sent to this page as well.
The “method” parameter determines the way that the user’s data is going to be sent. There are two methods for transferring data, one is called “post”, and the other is call “get”.
When you “post” your form to another page, the data that was given in the form is sent invisibly to the next page. This takes it a slightly longer time to send, but a bit more secure as well. When you use the “get” method, the data is actually sent through the URL in the top of your browser. This can be seen, as example, as w ww.mydomain.com/mypage.php?name=john&phone=555_3232 (each item proceeding ? are variables). Since the data is sent through the URL, it can be changed by typing new data in the URL and viewed by someone submitting the form. This has it’s advantages in speed, but lacks an aspect of security that the “post” method retains.
Inside of your form tags, there are various other HTML tags to make your form useful. The two most common ones are the “text” field and the “submit” button.
The “text” field tag: <input type=”text” name=”username” value=””>. It allows a user to enter some text into the field. When the form is submitted the variable entitled “name” will contain the text they input in the text field.
The “submit” button: <input type=”submit” name=”submit” value=”Submit Form”>. This button will send the data entered in the form to the page in your “action” parameter.
Like I said their are many other ways for a user to input data, such as drop-down menus, radio buttons, check boxes, and so on, but I will not be covering them here.
Here is the example outlined above:
<form action="myPage.php" method="post">
Enter your name: <input type="text" name="username" value="">
Press: <input type="submit" name="submit" value="Submit Form">
</form>
Once the form is built, and a user enters their data and submits, what next?
Well, the page that the form submits to has the job of taking care of the data. Using PHP we can quite effortlessly retrieve the data that was sent so we can begin working with it.
Now, since there are two ways of sending the data through the form, “post” and “get”, we can set our PHP variables up to retrieve them. If the form was posted we can access that variable using the syntax $_POST['variable']; . If it was sent using “get” we access that variable through the syntax $_GET['variable']; .
So, assuming we used the example above to submit a name through a form, the receiving end page must have PHP similar to this:
<?php
$name = $_POST['name']; // if it was post
$name = $_GET['name']; // if it was get
?>
$name will then contain the text the user entered in the form, e.g. “john”.
Being able to access the data using $_POST and $_GET is extremely useful, and allows us to perform many operations using PHP on the form data.
Почему подписка еще бесплатная?
)
Faculty can reserve a portion of the land for their classes to use for experimentation and assignments. ,
My local school runs sports sessions early in the mornings to physically prepare the students and they all succumb to the physical pressure proven by their good conduct in classes. ,