Jump to content

from 'on' to 1


mATOK

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?
Link to comment
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

Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.