Preselecting Check Boxes


 if (isset($_POST['boxname']) && $_POST['boxname'] == 'yes') {    echo 'checked="checked" '; } 


Although some websites pretend to group check boxes like radio buttons, this is technically not true. Every check box stands on its own; therefore, they all should have different names (it would not make sense to give them identical names). Then each check box can be treated individually: Check for the associated value attribute and print out the checked HTML attribute, if there is a match.

Prefilling Check Boxes (checkbox.php; excerpt)
 <input type="checkbox" name="boxname" value="yes"    <?php   if (isset($_POST['boxname']) && $_POST['boxname']       == 'yes') {     echo 'checked="checked" ';   } ?>/>I agree. 

When using cookie data (if available), the code changes slightly.

Prefilling Check Boxes(checkbox-cookie.php; excerpt)
 <?php   require_once 'getFormData.inc.php'; ?> ... <input type="checkbox" name="boxname" value="yes"    <?php   if (getFormDataPOST('boxname') == 'yes') {     echo 'checked="checked" ';   } ?>/>I agree. 




PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net