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

Posted by Leif Gregory on 10/19/00 11:30

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.

 

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

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