Ashley Sheridan wrote:
On Fri, 2009-04-17 at 12:54 -0400, Bob McConnell wrote:
From: tedd
At 10:43 PM -0700 4/16/09, Jim Lucas wrote:
Have your elements setup like such:

<input type="checkbox" name="reserve[rm1]" value="yes" /> Room #1
<input type="checkbox" name="reserve[rm2]" value="yes" /> Room #2
<input type="checkbox" name="reserve[rm3]" value="yes" /> Room #3
<input type="checkbox" name="reserve[rm4]" value="yes" /> Room #4
<input type="checkbox" name="reserve[rm5]" value="yes" /> Room #5

Then on your processing page, you know that you have 5 rooms, 1 - 5.

With this information you can check to make sure that something
$rooms = range(1,5);
for ( $i = 1; $i <= 5; $i++ ) {
        if ( isset( $_POST['reserve']['rm'.$i] ) {
                # Room was checked
        } else {
                # Room was NOT checked.
Jim et al:

Try this:

<input type="checkbox" name="reserve[1]" > Room #1
<input type="checkbox" name="reserve[2]" > Room #2
<input type="checkbox" name="reserve[3]" > Room #3
<input type="checkbox" name="reserve[4]" > Room #4
<input type="checkbox" name="reserve[5]" > Room #5

if (isset($_POST['reserve']) )
    foreach ($_POST['reserve'] as $key => $a)
       echo("$key $a <br />");

Here's the demo:

Don't forget the </input> on the end of those input lines. I've seen too
many pages already where I had to fix that problem.

Bob McConnell

It shouldn't really be

<input type="checkbox" name="reserve[1]"> Room #1</input>

but something like this:

<label><input type="checkbox" name="reserve[1]"> Room #1</label>

Well, to quote the W3C Recommendation...

<FORM action="..." method="post">
    <TD><LABEL for="fname">First Name</LABEL>
    <TD><INPUT type="text" name="firstname" id="fname">
    <TD><LABEL for="lname">Last Name</LABEL>
    <TD><INPUT type="text" name="lastname" id="lname">

The label tag should reference the input via the for attribute.  Identifying 
the input tag by id attribute value.

And using the for attribute of the label tag in conjunction with the id
attribute of the input tag, you can separate the label and form element
entirely, which is sueful if you still use tables to line up your


PHP General Mailing List (
To unsubscribe, visit:

Reply via email to