Re: [PHP] Protocol on handling empty checkbox values

2002-08-20 Thread Justin French

Oooops!

Go back to isset() or emoty()

Justin




on 21/08/02 9:48 AM, David Yee ([EMAIL PROTECTED]) 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 ([EMAIL PROTECTED]) 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.
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 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
>> 
>> 
> 


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




Re: [PHP] Protocol on handling empty checkbox values

2002-08-20 Thread David Yee

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 ([EMAIL PROTECTED]) 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.
> >
> > 
> > 
> > 
> >
> > 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
>
>


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




Re: [PHP] Protocol on handling empty checkbox values

2002-08-17 Thread Jason Wong

On Saturday 17 August 2002 17:40, David Yee wrote:
> > It's not PHP's fault -- it's the CGI/POST specs.  The browser is not
>
> sending
>
> > it through, because that's what it was told to do :)
>
> Ah- got it.  That would make sense since it's the browser that's send the
> form data to the server, and if it doesn't chose to  I wonder why the
> CGI/POST specs are like that- there's probably a good reason?

One advantage is that it saves some bandwidth.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Although the moon is smaller than the earth, it is farther away.
*/


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




Re: [PHP] Protocol on handling empty checkbox values

2002-08-17 Thread David Yee

> It's not PHP's fault -- it's the CGI/POST specs.  The browser is not
sending
> it through, because that's what it was told to do :)
>


Ah- got it.  That would make sense since it's the browser that's send the
form data to the server, and if it doesn't chose to  I wonder why the
CGI/POST specs are like that- there's probably a good reason?

David


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




Re: [PHP] Protocol on handling empty checkbox values

2002-08-16 Thread Justin French

on 17/08/02 3:19 PM, David Yee ([EMAIL PROTECTED]) wrote:

> Great idea!  Actually after I posted the question I thought of the same
> thing :-).  This is probably the most elegant way.  I am curious though why
> PHP doesn't just create the variable anyways and just assign it a null value
> if the box is not checked.

It's not PHP's fault -- it's the CGI/POST specs.  The browser is not sending
it through, because that's what it was told to do :)

Justin French


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




Re: [PHP] Protocol on handling empty checkbox values

2002-08-16 Thread David Yee

> I'd use an array on some way, but the other option is to see if the var is
> set, else set it to N
>
> if(isset($_POST['my_checkbox_var'])) {
> $_POST['my_checkbox_var'] = 'N';
> }
>
>
> Probably what I'd do is create an array for the possible checkbox values,
> then USE THAT ARRAY to build the form.  Then I can re-use the array on the
> validation script, checking that each element isset()... if they aren't,
set
> them to 'N'.

Yes that's what I was doing- because the form has other elements other than
checkboxes I have to distinguish between the checkboxes and the others and
hence a separate array for checkboxes.

> 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'.

Great idea!  Actually after I posted the question I thought of the same
thing :-).  This is probably the most elegant way.  I am curious though why
PHP doesn't just create the variable anyways and just assign it a null value
if the box is not checked.

David


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




Re: [PHP] Protocol on handling empty checkbox values

2002-08-16 Thread Justin French

I'd use an array on some way, but the other option is to see if the var is
set, else set it to N

if(isset($_POST['my_checkbox_var'])) {
$_POST['my_checkbox_var'] = 'N';
}


Probably what I'd do is create an array for the possible checkbox values,
then USE THAT ARRAY to build the form.  Then I can re-use the array on the
validation script, checking that each element isset()... if they aren't, set
them to 'N'.


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 ([EMAIL PROTECTED]) 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.
> 
> 
> 
> 
> 
> 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




Re: [PHP] Protocol on handling empty checkbox values

2002-08-16 Thread James Green

On Fri, 2002-08-16 at 19:24, David Yee 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.
> 
> 
> 
> 
> 
> 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?

I'll assume here that you're dynamically building the table and thus the
checkboxes, which is why you cannot know whether a checkbox exists on
the form or not.

If this is true, I would get a variable $loop, set it to 0, then on
outputting every checkbox, append this value to the checkbox's name.
Then you have predicatable checkbox names.

When you have finished drawing the checkboxes, note in a hidden input
field the $loop value so you know what maximum possible checkbox number
is.

On receiveing the POST, do a for loop, and perform an if
(isset($_POST["checkbox_number_$loop"])) then you know if it's set or
not.

I think that just about covers it. Apologies if I have
misread/misinterpreted what you have asked.

James Green





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




[PHP] Protocol on handling empty checkbox values

2002-08-16 Thread David Yee

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.





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