The detritus of a Button Monkey

22 Mar

Retaining a value in a form in php

The standard construction of an input box is like this:

<INPUT type=”text” name=”name” size=”5″  maxlength=”5″>

The various components being fairly obvious, size being the length of the screen box and max length referring to the length of input that can be stored.  When the page is submitted and validated, the values are lost if validation fails.

One way to retain the values is to use the value=”” option.  In this case the value you are going to use is the posted value.  When the page first loads, the box is empty as nothing as yet been posted.  When some input is stored in the text box, it gets retained, allowing a person to concentrate on correcting the validation error and not entering all of the information. A typical example is:

<INPUT type=”text” name=”name” size=”5″ value=”<?php echo $_POST[‘name’]; ?>” maxlength=”5″>

This will retain the value assigned to “name” when the form gets submitted.

Leave a Reply

You must be logged in to post a comment.

© 2022 The detritus of a Button Monkey | Entries (RSS) and Comments (RSS)

Design by Your Index - Powered By Wordpress