Using HTML forms and PHP to Set and Process Variables in Linux
Creating the HTML form
In previous articles, we talked about PHP and its syntax, created a working script, executed it and looked at variables. Now lets put some of this to use and create an HTML form that we will use to collect input from the user. We’ll then use variables to store the input from the user and then perform awesome tricks with it using PHP.
We’ll create a web page that takes a message from the user and shows it on a different page.
Lets begin with the HTML page that’ll contain the form. Call it “message_form.html” - if you want to call it something else, you may! For easy reading see this paste bin.
Explained…
Above is just a plain old static HTML form, below points out the juicy bits:
The HTML
ends the form.So now we have a way of collecting the user’s input, we need to do something useful with it! You can use the echo or print command to output the variables contents on another page. In some cases it might be preferable to do all of this in one PHP script.
When the user clicks the submit button “message_tutorial.php” is loaded. Here is “message_tutorial.php” or see this code in this paste bin:
<?php
// Get the values from the form, “FirstName” and “Message”
$FirstName = $_REQUEST[‘FirstName’] ;
$Message = $_REQUEST[‘Message’] ;
?>
Hey,
Your message is
Do I use GET or POST?
You might have noticed that we used the POST method to pass data from the form to the PHP script