Sep 12th, 2013, 12:50 PM
(This post was last modified: Sep 12th, 2013, 12:58 PM by michatmaster7.)
I admit I'm just getting around to this. I thought it would be a great addition to all my forms, because rather than have the form send a blank value, I could tell the form "if the checkbox is left unchecked, the send {some value}, otherwise send it's checked value."
Well. It half worked.
Now when the form is submitted, if the checkbox is left unchecked, it records the value from Ben's code above. However, if it IS checked, it always records a value of "1" - regardless of what the actual value is. This, of course, is not ideal.
I have most checkboxes set as text fields in the FT backend, but that shouldn't matter. So... is there a problem with the code above? Why is submitting a "1" when the box IS checked?
Example Code:
Well. It half worked.
Now when the form is submitted, if the checkbox is left unchecked, it records the value from Ben's code above. However, if it IS checked, it always records a value of "1" - regardless of what the actual value is. This, of course, is not ideal.
I have most checkboxes set as text fields in the FT backend, but that shouldn't matter. So... is there a problem with the code above? Why is submitting a "1" when the box IS checked?
Example Code:
PHP Code:
// ...
if (isset($_POST['submit_button_name']))
{
$_POST["cb_name"] = (isset($_POST["cb_name"])) ? isset($_POST["cb_name"]) : "None";
// ...
<input name="cb_name[]" type="checkbox" value="Value if selected." <?php if (@$fields["cb_name"] == "Value if selected.") echo "checked"; ?> />