Chapter 2. PHP and XHTML Forms

In This Chapter

  • Understanding the relationship between XHTML and PHP

  • Using the date() function

  • Formatting date and time information

  • Creating XHTML forms designed to work with PHP

  • Choosing between get and post data transmission

  • Retrieving data from your XHTML forms

  • Working with XHTML form elements

PHP is almost never used on its own. PHP is usually used in tight conjunction with XHTML. Many languages have features for creating input forms and user interfaces, but with PHP, the entire user experience is based on XHTML. The user never really sees any PHP. Most of the input to PHP programs comes from XHTML forms, and the output of a PHP program is an XHTML page.

In this chapter, you discover how to integrate PHP and XHTML. You explore how PHP code is embedded into XHTML pages, how XHTML forms can be written so they will send information to a PHP program, how to write a PHP program to read that data, and how to send an XHTML response back to the user.

Exploring the Relationship between PHP and XHTML

PHP is a different language than XHTML, but the two are very closely related. It may be best to think of PHP as an extension that allows you to do things you cannot do easily in XHTML. See Figure 2-1 for an example.

Every time you run getTime.php, it generates the current date and time and returns these values to the user. This would not be possible in ordinary XHTML because the date and time (by definition) always change. While you could make this page using JavaScript, ...

Get HTML, XHTML, & CSS All-in-One For Dummies®, 2nd Edition 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.