Chapter 12. Generating Dynamic HTML

In this lesson you will learn how to create elements of an HTML form by using PHP. These techniques enable you to specify default values for input items and create dynamic drop-down menus or radio button groups based on data in a script.

Setting Default Values

Let's begin with some simple examples that embed PHP within form elements to set the default values of some items when the page is loaded.

Default Input Values

The default value of a text input is given in the VALUE attribute. This value displays in the field when the page is loaded, and, unless it is overtyped, the same value is sent to the PHP processing script when the form is submitted.

Consider a shopping cart page for an online store, where customers ...

Get Sams Teach Yourself PHP in 10 Minutes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.