Re: pup

From: Date: Mon, 20 Apr 2009 03:49:53 +0000
Subject: Re: pup
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.general 
Request: Send a blank email to php-general+get-291675@lists.php.net to get a copy of this message
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
exists
<?php $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: http://www.webbytedd.com/bbbb/post-array1/index.php
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... http://www.w3.org/TR/html401/interact/forms.html#h-17.9.1 <FORM action="..." method="post"> <TABLE> <TR>
    <TD><LABEL for="fname">First Name</LABEL>
    <TD><INPUT type="text" name="firstname" id="fname">
<TR>
    <TD><LABEL for="lname">Last Name</LABEL>
    <TD><INPUT type="text" name="lastname" id="lname">
</TABLE> </FORM> 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 forms! Ash www.ashleysheridan.co.uk


« previous php.general (#291675) next »