O'Reilly logo

PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making Sticky Forms

You’ve certainly come across sticky forms, even if you didn’t know that’s what they were called. A sticky form is simply a standard HTML form that remembers how you filled it out. This is a particularly nice feature for end users, especially if you are requiring them to resubmit a form (for instance, after filling it out incorrectly in the first place).

To preset what’s entered in a text box, use its value attribute:

<input type="text" name="city" size="20"
→ value="Innsbruck" />

To have PHP preset that value, print the appropriate variable:

<input type="text" name="city" size="20"
→ value="<?php echo $city; ?>" />

With this in mind, I’ll rewrite calculator.php so that it’s sticky.

To make a sticky form

1.
Open calculator.php ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required