Re: Protocol on handling empty checkbox values
| From: | Justin French | Date: | Wed, 21 Aug 2002 01:49:15 +0000 |
| Subject: | Re: Protocol on handling empty checkbox values | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-113396@lists.php.net to get a copy of this message | ||
Oooops!
Go back to isset() or emoty()
Justin
on 21/08/02 9:48 AM, David Yee (david@coolcomputing.com) wrote:
> Doh- just discovered that this won't work for updates (e.g. if value is
> already = 'Y' and you uncheck the box it'll stay as 'Y').
>
> David
>
>> To throw in a curve-ball, you can set the default value for your MySQL
>> column to 'N', which means that any value you DON'T write will be
>> 'N', and
>> those you do will be 'Y'.
>>
>>
>> Justin French
>>
>>
>>
>>
>>
>> on 17/08/02 4:24 AM, David Yee (david@coolcomputing.com) wrote:
>>
>>> Hi all. For a universal form script I'm writing I want to store a 'Y'
> in a
>>> table field if a checkbox is checked and an 'N' if it's not. The
> problem is
>>> that when the form is posted if the checkbox is not checked the checkbox
>>> variable is not passed. E.g.
>>>
>>> <form method=POST action=submit.php>
>>> <input type=checkbox name=my_checkbox_var value=Y>
>>> </form>
>>>
>>> If the checkbox is checked, I get $_POST['my_checkbox_var'] == 'Y',
>>> but
> if
>>> not $_POST['my_checkbox_var'] is not even set. So what I've been doing
> is
>>> putting the variable names of the checkbox fields into an array,
> serializing
>>> it, and then pass the string as a hidden input on the form. Then in the
>>> page that handles the POST I unserialize the array to determine if
> checkbox
>>> fields were passed and then handle accordingly. But I'm wondering is
> there
>>> a better way (or at least a standard way) of doing this?
>>>
>>> David
>>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>