FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Eregi possible problem
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Eregi possible problem [message #169386 is a reply to message #169362] Thu, 09 September 2010 06:54 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 08/09/2010 17:40, GarryJones escribió/wrote:
> I "solved" this today in a different way....
> First I set all values to nej.
> <input name="boksin" type="hidden" value="nej">
> <input name="boksil" type="hidden" value="nej">
> <input name="boktav" type="hidden" value="nej">
> <input name="boklic" type="hidden" value="nej">
> <input name="bokncg" type="hidden" value="nej">
> <input name="bokpap" type="hidden" value="nej">
>
> Then if they are later displayed as checkboxes the value is
> redeclared, if not then the "post" reads from the above.

But, why do you need to receive explicitly both checked and unchecked
options in the first place? You are supposed to know what the available
options are and whatever option does not show up as checked, well, it
must be unchecked.

I presume *you* know the options but your PHP code doesn't. In this
cases, it can be useful to define an array at the top of your code:

$options = array(
// Code name => Descriptive label
'boksin' => 'Receive the Boksin newsletter',
'boksil' => 'Receive the Boksil newsletter',
'boktav' => 'Receive the Boktav newsletter',
'boklic' => 'Receive the Boklic newsletter',
'bokncg' => 'Receive the Bokncg newsletter',
'bokpap' => 'Receive the Bokpap newsletter',
);

You can then use this data array to:

1. Print the appropriate checkboxes
2. Validate user input
3. Derive unchecked options

switch() and foreach() are your friends :)


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Another heredoc question
Next Topic: php filling in listbox value based on db record ??
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 11:56:17 GMT 2024

Total time taken to generate the page: 0.03936 seconds