Jump to content

Checkboxes and radio boxes not working right i think


flashpointdevon

Recommended Posts

Im using chrome.

 

Shouldt these have a 1 value only if checked? I tried without assigning value and with, I cant get it to work right. Same for radio boxes. I tried googling this and to my surprise I could not find anything relevant. How do I get a 0 for not checked and a 1 for checked? Thanks in advance im sure someone knows this

 

				<input type="checkbox" name="test_clean" id="test_clean" value="1" />
			<label for="test_clean">Test Clean</label>
			<input type="checkbox" name="test_works" id="test_works" value="1" />
			<label for="test_works">Test Works</label>
			<input type="checkbox" name="test_parts" id="test_parts" value="1" />
			<label for="test_parts">Test Parts</label>
			<input type="checkbox" name="test_volume" id="test_volume" value="1" />
			<label for="test_volume">Test Volume</label>
			<input type="checkbox" name="test_damage" id="test_damage" value="1" />
			<label for="test_damage">Test Damage</label>
			<input type="checkbox" name="shipped" id="shipped" value="1" />
			<label for="shipped">Shipped</label>

Link to comment
Share on other sites

How do I get a 0 for not checked and a 1 for checked?

By starting with a 0 for every possible checkbox and then setting each to 1 if they've been submitted. That's because unchecked boxes are not sent to PHP.

$checkboxes = array(
"test_clean" => 0,
"test_works" => 0,
"test_parts" => 0,
"test_volume" => 0,
"test_damage" => 0,
"shipped" => 0
);

foreach ($checkboxes as $key => &$value) {
if (!empty($_POST[$key])) $value = $_POST[$key];
}
unset($value);

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.