<<

. 94
( 132 .)



>>

— password ” This type is identical to the text field, except that the text that
is typed into the box is shown as asterisks.
— hidden ” This type does not render on the screen. It is very useful for
passing values between pages. The name and value attributes are all you
need with hidden fields; consider using them if you™re uncomfortable
with cookies or sessions. Note that by simply viewing the source of your
Web page, a savvy user will be able to see your hidden form elements.
Do not put any sensitive data in hidden form fields.
— submit ” Places a submit button on the page. The text in the value
attribute will appear on the submit button. When the form is submitted,
the name and value of the submit button are passed along like all other
form elements. If you use name/value pairs for all of your submit buttons,
you have the extra flexibility of having multiple submit buttons on a
single form.
— image ” Serves the same purpose as the submit button, but it enables you
to specify an image to use instead of that ugly old submit button. Treat
this form element as you would any <img> tag. Provide both src and alt
attributes. If you™re working with image maps, in which clicks on different
regions of the same image have different functional significance, you can
access the coordinates of a click through name_x and name_y.
564 Part V: Appendixes

— reset ” This form field creates a button that, when pressed, returns the
form to the state it was in when the page loaded. Any data that the user
has entered into the form is cleared.
— file ” Allows users to send files from their computer to a remote server.
The field looks much like a text box that has a button labeled “Browse”
placed next to it. When a user presses the Browse button, a file selection
dialog box is displayed. The user can choose one file per file upload
form field. A form can have multiple file upload fields. When using this
input type, be sure to change the form enctype attribute to multipart/
form-data. See Chapter 12 for a discussion of file uploads with PHP.

— checkbox ” The name and value of the checkbox is passed only if the
checkbox is checked when the form is submitted. If the word “checked”
appears in the tag, the checkbox will be checked by default. Remember
to use name=box_name[] to pass multiple checkboxes as an array. See
Chapter 4 for a discussion of passing arrays with PHP.
— radio ” Enable the user to select only one of several choices. Radio but-
tons with the same name attribute belong to the same group. The checked
attribute signifies the default choice.

The following form makes use of all the form elements we just covered, except
for the image type. Figure B-2 shows how it is rendered in the browser.

<h2>Please Enter Personal Information</h2>
<form>
<input type=”text” size=”25” maxlength=”15” name=”name”
value=”Name Here”><br>
<input type=”password” size=”25” maxlength=”15” name=”password”
value=””><br>
<input type=”hidden” value=”you can™t see me”>
<input type=”checkbox” name=”telemmarket” value=”yes” checked>If
checked, I have permission to clear out your bank account.
<p>
<b>What is your eye color?</b><br>
<input type=”radio” name=”eye_color” value=”blue”
checked>blue<br>
<input type=”radio” name=”eye_color” value=”green”>green<br>
<input type=”radio” name=”eye_color” value=”brown”>brown<br>
<input type=”radio” name=”eye_color” value=”red”>red<br>
<input type=”submit” name=”submit” value=”submit”> &nbsp; &nbsp;
&nbsp;
<input type=”Reset”>
</form>
Appendix B: HTML Forms 565




Figure B-2: More form elements


select, multiple select
The select form element creates drop-down boxes and (to use the Visual Basic
term) list boxes. To create drop-down boxes you must use an opening <select> tag
with a name attribute. Within the select element, <option> tags will indicate pos-
sible choices. Each of these can have a value attribute; without one, the value of
the option is the text between the opening and closing <option> tags. If the word
selected appears in the tag, that option is set as the default value of the <select>
field (as with ˜checked™ for checkboxes and radio buttons).
The following HTML code creates a drop-down box with three elements:

<form name=”tester” action=”script.php” method=”GET”>
<select name=”dinner”>
<option value=”1”>chicken</option>
<option value=”2”>fish</option>
<option value=”3”>vegetarian</option>
</select>
</form>

By adding the word multiple to the select element you enable the user to pick
more than one of the choices. The size attribute determines how many of the
options are visible at one time.
566 Part V: Appendixes

The following code creates a list box with three visible elements. Figure B-3
shows how this HTML code looks in the browser.

<form name=”tester” action=”script.php” method=”GET”>
<select name=”side_dishes” multiple size=”3”>
<option value=”1”>potato</option>
<option value=”2”>pasta</option>
<option value=”3”>carrot</option>
<option value=”4”>celery</option>
<option value=”5”>mango</option>
</select>
</form>

If you want that select list to support multiple selections (by holding down Ctrl),
you have to put square brackets after the name value. In other words, the opening
line of the preceding select box would be as follows:

<select name=”side_dishes[]” multiple size=”3”>


textarea
The textarea element creates a large block for text entry. Add a rows and columns
attribute to specify the size of the box. textarea is different from other form ele-
ments in that opening and closing tags surround the default text. For instance:

<textarea name=”mytext” rows=”5” columns=”20”>Here™s the default text</textarea>


Keep in mind that if you have spaces or hard returns between your <textarea>
tags, those characters will be carried to the form element.
Add the wrap attribute to change how text wraps when it reaches the end of a
line in the box. If the value is wrap=”physical”, carriage returns are added at the
end of line; if the value is wrap=”virtual”, the lines will appear to wrap but will
be submitted as a single line. The latter is almost always the best choice for ease of
processing on the server side ” though “virtual” still preserves any manually
inserted returns.
The attributes just listed came from the folks at Netscape, and you still might
need to use them. The official W3C HTML 4.0 attribute values for wrap are none,
hard, and soft, and these should work in the most of the recent browsers.
Appendix B: HTML Forms 567

Figure B-3 adds the select, multiple select and textarea elements to a
form with the following code:

<h2>Please Enter Personal Information</h2>
<form>
<fieldset id=”fieldset1”
style=”postion:absolute;
width:300;
height:100;
top:20;
left:10;”
>
<legend>Food Questions</legend>
<b>What did you eat for dinner?</b><br>
<select name=”dinner”>
<option value=”1”>chicken</option>
<option value=”2”>fish</option>
<option value=”3”>vegetarian</option>
</select><br>
<b>Any Side dishes?</b><br>
<select name=”side_dishes[]” multiple size=”3”>
<option value=”1”>potato</option>
<option value=”2”>pasta</option>
<option value=”3”>carrot</option>
<option value=”4”>celery</option>
<option value=”5”>mango</option>
</select>
<br>
<b>How are you feeling about dinner?</b><br>
<textarea name=”mytext” rows=”5” columns=”20”>
Here™s the default text</textarea>
</fieldset>
<p>
<button>
<input type=img src=”disk.gif” width=”32” height=”32” border=”0”
alt=”disk”><br>
Pretty Little Button
</button>
</form>
568 Part V: Appendixes




Figure B-3: Additional form elements



Other Attributes
With HTML 4.0 and the newest browsers some additional attributes have been
introduced. Make sure to test these as part of your QA process, because they will
not work on all browsers.

accesskey
An access key is the same as a hot key. If this attribute appears in a form element,
the user can hit (on a PC) Alt and the designated key to be brought directly to that
form element. The hot key is generally indicated by underlining of the hot letter.

<input type=”text” name=”mytext” accesskey=”m”><u>M</u>y text box.



tabindex
Users can use the Tab key to move through form elements. The tabindex attribute
specifies the order in which focus will move through form elements.
Appendix B: HTML Forms 569


Other Elements
Internet Explorer 5 and Mozilla support a couple of new and seldom-used form ele-
ments that you might want to consider using.

button
The button is a fancier version of the submit button. It enables you to put both text
and an image on the same button. There are opening and closing <button> tags,
and everything inside of them appears on the button. Figure B-3 shows an example
of the button.

fieldset and legend
These are nice for grouping elements in forms. All text and tags within the
<fieldset> tags will be surrounded by a thin line. Text within the <legend> tags
will serve as the caption for that grouping.
Figure B-3 shows all the form types.
At present, it is still not a great idea to use most of the HTML 4.0 form elements
and attributes. Generally speaking, they add very little, and they may look very
strange on many browsers.
Appendix C

Brief Guide to MySQL/PHP
Installation and
Configuration
WHEN INSTALLING MYSQL AND PHP, you are faced with all kinds of options. The vari-
ety of operating systems and installation options creates more permutations than
could possibly be handled in this book. Luckily, installation procedures for all pack-
ages are documented well in each package™s respective documentation.
In the first edition of this book, our installation instructions focused on compil-
ing the individual packages from source files and then making changes to configu-
ration files so that Apache, MySQL, and PHP would recognize each other. While
there™s still something to be said for compiling packages from source ” you do get a
finer level of control and may be able to invoke options not available with any other
form of installation ” it™s likely that a simpler method of installation will work just
fine for you. On just about any platform and operating system you can get the most
recent version of all packages precompiled and packaged into an easy-to-install set
of files. We make note of these installers in the following sections.



Windows Installation
At this point in computer history (in the opinion of these authors) far too many ver-
sions of Windows are in use. Windows 98, NT, 2000, and XP all have large user
bases. Though each of these operating systems differs significantly from the others,
the installation of the packages of concern to us is pretty similar on all Windows
variants.
There are a few installers that make MySQL/PHP/Apache installation a truly
painless process on Windows. We discuss two of these in the following sections.

phpdev
The phpdev bundles available at http://www.firepages.com.au/ provide a very,
very clean installation program. To install this package on a Windows machine, all
you have to do is the following.

571
572 Part V: Appendixes

1. Go to the phpdev bundles area of the site.
2. Pick a version and download the installer file ” in this case, the PHP5 beta
bundle, dev5beta3.exe. This is an NSIS installer file.
3. Run the installer and choose the directory where you want your files to be
installed ” C:\phpdev5, for example.

And that™s it. We™re not including a phpdev package on the CD because it™s likely
that by the time you read this book a significant bug or security vulnerability will
have be discovered in one of the included packages. So you™re really better off get-

<<

. 94
( 132 .)



>>