Re: Type of form element

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

 



Hello Shaun,

Friday, October 28, 2005, 9:00:05 AM, you wrote:
> 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?

Yes and no.

1. You can't determine by the POST variable whether it was a checkbox
or a text field unless you test for 1/0 or a string, but even then,
what if someone types a 0 into a textbox that was supposed to be an
address (input validation). The other option is to name the checkbox
something like "question1_chkbox" and do a strstr() to see if the POST
variable name contains "_chkbox". But you should know what the
variable names of your checkboxes are anyways, so I don't know why
you'd test to see if it was a checkbox.

2. Only set checkboxes (checked) are passed through POST and GET. This
is fine if it's a one time form and you just need to know if they said
"yes" to subscribing to your newsletter, but if it's a form they can
go back into to modify settings (i.e. their account) then you need to
test to see if they unchecked a box which will not be passed back to
you via POST. Basically you'd set all the fields to 1 if the checkbox
variable appeared in the POST, and set all the rest of the fields to
zero (because if it wasn't in the POST variables, it was unchecked).



-- 
                          TBUDL/BETA/DEV/TECH Lists Moderator / PGP 0x6C0AB16B
 __    ____  ____  ____   Geocaching:                    http://gps.PCWize.com
(  )  ( ___)(_  _)( ___)  TBUDP Wiki Site:  http://www.PCWize.com/thebat/tbudp
 )(__  )__)  _)(_  )__)   Roguemoticons & Smileys:    http://PCWize.com/thebat
(____)(____)(____)(__)    PHP Tutorials and snippets:    http://www.DevTek.org

Some days I feel like I'm just rearranging deck chairs on the Titanic.

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux