A form is almost exactly as it sounds - information is completed by a user into fields and it is then processed by PHP.
PHP pages can be used as simply using code and a redirect without the need for any HTML or output.
Below is a small form which has no submit method.
The form above has no action therefore it will not do anything.
The code for that form is shown below:
<!--This form uses the Epic Form class on this website.--> <form class="epic"> <p>This is a form.</p> <p> You can select one of the following options and fill in certain parts of it. </p> <p>Name: <input name="name" type="text" style="width:200px;"></p> <p>Address: <input name="address" type="text" style="width:200px;"></p> <p>Experience with PHP:</p> <input checked name="experience" type="radio" value="none">None<br> <input name="experience" type="radio" value="lots">Lots<br> <p>Text can be included in a form.</p> <p><input name="Submit1" type="submit" value="Submit"></p> </form>
element is used to collect an input whilst
attribute specifies what type of input will
be provided, for instance, checkbox, radio button etc.
<!--This will result in address being passed to the page sample.php--> <form action="sample.php" style="border:thin;"> <input name="address" type="text" style="width:100%;"> <input name="Submit1" type="submit" value="Submit"> </form>
This means that when the user submit the form, the contents of the form input values will be passed to the page sample.php.
One of the fundamentals of PHP and forms is extracting the information
which has been given to it. This can be achieved using the
method where the inputName is replaced with the name of the form
input that we want the value of. This example will look at using
variable and the
So in the previous example, in results to the form shown previously, the following code will the name that has been submitted:
<p> <?php echo $_POST['name']; ?> </p>
This code is taking the form value from the input called "name".
In this sample, it is being put inside a paragraph element. Alternatively
method, there is
variable (it is actually an associative array variable, but this will be discussed later) can be used to obtain URL
variables such as those that follow a question mark in a query string in
a URL, for example: page.php?p=1277.