Re: Re: Type of form element

From: Date: Fri, 28 Oct 2005 19:30:58 +0000
Subject: Re: Re: Type of form element
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-224790@lists.php.net to get a copy of this message
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/

« previous php.general (#224790) next »