Jump to content

Does php checkbox inputs hate the number "0" (Zero) as a value?


Demonic

Recommended Posts

For some reason if say you set a input value to zero the value will output nothing when trying to echo, is this a bug or what?  If you set the checkbox value to a negative or a positive greater then zero it displays the number fine.  Just wondering, I found a work around using -1 and converting -1 to zero, but was wondering if this is normal for php to do?

You would need to post your code. Is there a chance nothing was checked (which would give a null instead of a value) or that you are using the empty() function to test the value (zero is considered to be empty)?

I don't have the code handy with me on the fly( I'm at school ), but yeah this happened to me few times, say having an array of checkbox's

 

<input name='del[]' value='0' />

<input name='del[]' value='1' />

<input name='del[]' value='2' />

<input name='del[]' value='3' />

<input name='del[]' value='4' />

 

Then when you go to check if a value is "set" and only the first checkbox is checked, nothing would be checked even if it was, so you really can't "typecast"(@the first post) the input value since it defeats the purpose of isseting the value if the value would tell the browser input "0" is always set, see what I'm talking about.

We would need to see your code. Either your form is not correct or your code that is echoing the value is not correct.

 

Using an input like this -

 

<input type="checkbox" name='del[]' value='0' />

 

Echos a zero using this code when the first checkbox is checked -

 

echo $_POST['del'][0];

 

Nothing checked or a wrong variable name would give a NULL and echo nothing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.