Re: Re: Type of form element

From: Date: Sat, 29 Oct 2005 20:07:25 +0000
Subject: Re: Re: Type of form element
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-224826@lists.php.net to get a copy of this message
> I usually place a hidden field with the same name as the checkbox > field before the actual checkbox field. I store my 'false' value in > there. If the checkbox is checked the hidden field is overridden. > > <?php > > error_reporting( E_ALL ); > > if( isset( $_POST[ 'submit' ] ) ) > { > echo '<pre>'; > print_r( $_POST ); > echo '</pre>'; > } > > echo <<<EOF > <form method='post' action='$_SERVER[PHP_SELF]'> > <input type='hidden' value='0' name='blah'> > <input type='checkbox' value='1' name='blah'> Blah? > <input type='submit' name='submit'> > </form> > EOF; > > ?> This probably works just fine in all browsers, but... I don't THINK the HTML and HTTP specification specificially require ordering of HTML/INPUT/POST elements to "match up" In fact, as I recall (and it's been YEARS since I read the damn thing) I believe they specifically said that the ordering was NOT to be relied upon... Though this may well have changed in HTTP/HTML 3.0, 4.0, XHTML, etc vesions of specifications. It also seems like rather needless bloat of HTML, to me, unless I'm missing something. $blah = isset($_POST['blah']); //update or process $blah If the processing of $blah is particularly expensive or heinous, and it's a pre-existing preference type of setting, I can see the savings, but given the overhead of checking every value going in/out to compare before update, it seems like the overhead outweighs the savings, and clutters up the code... -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#224826) next »