Re: Anyone?
| From: | Lars Torben Wilson | Date: | Mon, 06 Nov 2000 04:11:01 +0000 |
| Subject: | Re: Anyone? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23838@lists.php.net to get a copy of this message | ||
Website4S@aol.com writes:
> Hi,
>
> I have a form that has a number of checkboxes under the title Languages, so
> it`s a multiple selection thing. Is it possible to store them in a
> varchar(50) named Lang
>
> At the moment I can only get the last one checked to be stored and any others
> checked just dissapear somewhere.
>
> Anyone know whats going wrong?
>
> Ade
The browser doesn't set variables for checkboxes which aren't
checked. My favourite way around it is to set up an associative array
of input name/value pairs (with all defaulting to empty) and run a
function to automatically print out the checkboxes. Then when the form
is submitted, you just loop over this array, checking each one against
the submitted form variables; when you get a match, that checkbox is
checked; otherwise, it's not.
There are lots of code snippets around with functions to generate
lists of checkboxes (or selects, or whatever) from arrays. I can't
remember where right at the moment, but you could have a look at the
code/tips sections on http://www.zend.com, http://px.sklar.com,
etc.
Good luck,
Torben
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+