Forms are a collection of HTML elements used to collect date from the user and submit it to a script or server. The script can be client-side (run by the browser like javascript) or server-side (run by a server like PHP). This tutorial will cover forms for PHP.
<form target="display"> ... </form>
the results will be displayed in the frame or iframe named, "display".
Forms start with <form>
and ends with
</form>
. One of the attributes of a form is
method. Method determines how the data is sent. Method has two possible values; get and post.
If data is sent with get it is sent appended to a URL in name/value pairs. You can see this in action when you make a query to search engine. This allows you to bookmark a result or share it with someone. Since the data is visible this is not a good way to send sensitive data like passwords. Get is the default value for get so if you leave out method the data is sent via get. The post method is more secure and also better for sending a large amount of data.
A URL has a limit to it's length. If you exceed that length, the data on the end will be ignored. For something like a search engine, the data will usually fit on a URL so you can use get but if your form is editing a webpage, the data may be hundreds of characters long so in that case, you should use post. Images are also sent as post.
Action is an attribute of forms that tell it where to send the data. If you are sending the data to another website then the value of action is the URL of the target website. If the data is going to a different page on your website then the value is a file path to the page. If the form and the script are on the same page then you don't need action because the same page is the default value for action.
<input>
is an element of a form for collecting and
submitting data.
Name All inputs except one must have a unique name. The data is
sent in name/value pairs. If the input has no name, no data is sent.
Type is an attribute of form defines how the input looks. The default value is text.
Submit is a value for type that makes the input a submit button. A submit input is the one type that does not require a unique name. It can share the name with other submit inputs with each having
different values or have no name at all. It can not share a name with an input of another type.
You can the names of inputs by looking at the URL of the output. For example
I Googled "PHP Books" and got:
https://www.google.com/search?client=firefox-b-1-d&q=php+books
From that you can see that the action is "https://www.google.com/search" and
the name of the input is "q". With that information you can make a form.
If you give a value to the submit button it will be displayed on the button.
<form action="https://www.google.com/search"> <input name="q"> <input type="submit" value="Google It!"> </form> |