Codecademy Logo

PHP Form Handling

Dynamic Webpages using PHP

PHP is a server scripting language. This server side code can be used to fill out HTML templates in order to create a complete HTML document for a visitor. This finished document is called a dynamic webpage.

Dynamic PHP webpages can deliver a custom set of assets to each visitor, unlike static pages which deliver the same set of assets to everyone.

Embedding PHP Code

PHP can generate HTML when saved as a file with a .php extension. These files must always start with the tag <?php (closing tag is optional).

PHP can also be embedded into HTML. In this case, both opening tag <?php and closing tag ?> are used.

For example, in the given code, the PHP code has been embedded into the HTML by enclosing it within the <?php and ?> tags.

echo "Hello PHP World!";

$_REQUEST Superglobal Variable

The $_REQUEST superglobal variable is an array that contains data from the clients cookies, GET and POST request.

Action Form Attribute

The “action” form attribute is used to specify which PHP file handles the request being submitted. The PHP file handling the request can be the same file sending the request or a separate file.

$_POST Superglobal Variable

$_POST, the PHP superglobal variable, is an array that contains data from the client’s POST request. This data is translated from the HTTP request headers

$_GET Superglobal Variable

$_GET is a PHP superglobal variable which is used to collect an array of data transmitted within the URL parameters of a client’s incoming GET request.

echo Shorthand Syntax

Instead of using the regular echo syntax like <?php echo "Hello World"; ?> we can use a shorthand syntax such as <?= "Hello World"; ?>.

HTML Form Name Attribute

The name attribute is used to associate data with an input tag so that PHP can access the data. Unique name attribute values are needed for each input tag.

Learn More on Codecademy