Re: [PHP] Re: Type of form element
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Type of form element
If you have a checkbox you just test if the value is set with isset() if it's not set they never selected the checkbox. Or if thats not what you mean maybe this could help http://php.net/variables.external Shaun wrote: Hi, I have some checkboxes on my page which correspond with boolean fields in my database - actually they are TINYINT's in which I store a 0 or 1 in for false and true values respectively. Is it possible to loop through all $_POST values to see if it is a checkbox? If so then for that element if it is equal to 'on' then change it to 1 otherwise change it to 0? Thanks for your advice. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Type of form element
On Fri, 28 Oct 2005, James Benson wrote: If you have a checkbox you just test if the value is set with isset() if it's not set they never selected the checkbox. I have some checkboxes on my page which correspond with boolean fields in my database - actually they are TINYINT's in which I store a 0 or 1 in for false and true values respectively. Is it possible to loop through all $_POST values to see if it is a checkbox? If so then for that element if it is equal to 'on' then change it to 1 otherwise change it to 0? 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; ? -- Greg Donald Zend Certified Engineer MySQL Core Certification http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php