You are here: Re: [PHP] Type of form element « PHP « IT news, forums, messages
Re: [PHP] Type of form element

Posted by Marcus Bointon on 10/30/05 13:52

On 29 Oct 2005, at 20:59, Richard Lynch wrote:

> So you will most likely be using isset($_POST['checkbox_name']) rather
> than testing for "on"

I classify using isset for checking for the existence of array keys
to be a bad habit as in some common cases it will not work as you
expect, for example:

<input type="checkbox" name="checkbox_name" />

(note it has no value attribute) If it's checked, you would get the
equivalent URL of "...?checkbox_name=", so $_REQUEST['checkbox_name']
exists, but may contain NULL, and isset would return false even
though it's there. A completely reliable check that will never
generate any warnings is:

array_key_exists('checkbox_name', $_REQUEST).

If you have several checkboxes in an array (using names like
name="checkbox_name[option1]"), you would say:

if (array_key_exists('checkbox_name', $_REQUEST) and is_array
($_REQUEST['checkbox_name'])) {
if (array_key_exists('option1', $_REQUEST['checkbox_name'])) {
echo "you selected option 1\n";
}
if (array_key_exists('option2', $_REQUEST['checkbox_name'])) {
echo "you selected option 2\n";
}
//etc...
}

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcus@synchromedia.co.uk | http://www.synchromedia.co.uk

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация