Jump to content

Archived

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

mATOK

from 'on' to 1

Recommended Posts

Hey there, I have a form full of checkboxes that sends its input to an array.

I know that if a box is checked then the array reads 'on', otherwise I assume it will containe 'off'

I'd like to know how I can convert all of the on's to 1's and the off's to 0's

would I use strcmp for this or is there a built in php function?

Share this post


Link to post
Share on other sites
if the box is checked it will give whatever value you tell it to give

<input type=checkbox name=check1 value=heyheyhey>

also realize if a box is not checked it will not pass anything. So if you try to echo out a checkbox than was not checked you will get an error.

Ray

Share this post


Link to post
Share on other sites
thank you, I did not realize that you could set the value of a check box

so could I then use

<input type="checkbox" name="0" value="0" checked>

Share this post


Link to post
Share on other sites
no problem. Also I forgot to add, you can suppress the error by adding an @ in front of the variable.

Here is a quick example.
[code]<?php
if(isset($_POST['submit'])){
echo @$_POST['check1']."---".@$_POST['check2'];
} else {
?>
<form name=form method=POST action="">
  <input type=checkbox name=check1 value=3><br>
  <input type=checkbox name=check2 value=1><br>
  <input type=submit name=submit value=submit>
</form>
<?php
}
?>[/code]

Now if you only check one box you will just get a blank for the box that was not checked. If you take away the "@" in front of the $_POST variables you will get an error for the box that was not checked.

Just a little FYI for ya

Ray

Share this post


Link to post
Share on other sites

×

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.