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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.