RE: [PHP] pup

From: Date: Fri, 17 Apr 2009 19:25:22 +0000
Subject: RE: [PHP] pup
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.general 
Request: Send a blank email to php-general+get-291654@lists.php.net to get a copy of this message
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> 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 (#291654) next »