mootools php faith camera linux

php

Process Form
Checkboxes



I was asked today how to access the value of dropdowns, textareas, and radio buttons. The asker was familiar with how to get the values of regular input areas but did not know that forms' dropdowns, textareas, and radio buttons are not special in their php handling. They only have one value:


echo 'Radio value: '.$_REQUEST['myradio'].'<br/>';


Checkboxes are tricky cause if unchecked they are empty, so we must test to see if they are empty:


echo 'Checkbox: '.(!empty($_REQUEST['mycheckbox']))?'Checked!':'').'<br/>';


That may not be desirable since there isn't an output for an empty checkbox. You could try the yes/no example:


echo 'Checkbox: '.(!empty($_REQUEST['mycheckbox']))?'YES!':'No').'<br/>';

"Dad-gum, Jay, what's with that crazy if/else statement...who can read that??

Sorry about that...here is the yes/no example again without the php alternate if/else control statement:


if (!empty($_REQUEST['mycheckbox'])) {
  echo 
'Checkbox: YES!<br/>';
} else {
  echo 
'Checkbox: No<br/>';
}


Last Updated: 2008-09-18 07:49:17
Creative Commons License Jay Johnston is a Zend Certified Engineer in PHP 5 LPI-ID: LPI000102450, Verfication Code: wmnnt56y2k  ... Jay Johnston is certified as LPIC-1 by the Linux Professional Institute