Re: Determining if checkbox is selected in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> I'm storing the values from a groups of checkboxes
> in an array "keyword[]", but $_POST['keyword'] is
> undefined if none of the checkboxes is checked.

The fact that it is undefined if none of the checkboxes
are checked is expected behavior.  Just do:

if( isset( $_POST['keyword'] ) {
}

to determine if you need to do any further processing.

> I tried using "in_array()" with $_POST to determine
> if any of the group of 'keyword' checkboxes is checked,
> but can't get it to work;  does anyone have any
> suggestions?

if( isset( $_POST['keyword'] ) {
  foreach( $_POST['keyword'] as $checkboxValue ) {
    echo 'Checkbox ' . $checkboxValue . ' was checked<br>';

  }
}

Chris

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux