I have a situation where i do need unchecked radio button value. Is it possible to send unchecked radio button value through form in php? If yes, then can you please explain?
I have solved it. I have sent both radio button values in hidden field and as well as radio button values. On receiving page, I have compare checked value with hidden field value and so I got unchecked value. Thanks for all who responded to my question.
<input type="hidden" name="myField" value="false" />
<input type="checkbox" name="myField" value="true" />
both fields have the same name, if the checkbox isn't checked, the hidden field will be submitted, if the checkbox is checked, it will virtually override the the hidden field.
On a side note, are your sure radio buttons wouldn't be better suited to your needs, you will be able to see the definite answer for each questions, whereas checkboxes are more for submitted only the selected checkboxes. Failing that you could always assume that all checkboxes that were not submitted as checked, could be assumed to be unchecked.
Create sample.php file and paste below code and run it.
<?php
echo "<pre>";
if(isset($_POST['numbers']) && isset($_POST['unchecked']))
{
$checked_items = $_POST['numbers'];
$unchecked_items = array_diff($_POST['unchecked'],$_POST['numbers']);
echo 'Checked Item<br/>';print_r($checked_items);
echo '<br/><br/>Unchecked Items<br/>';print_r($unchecked_items);
}
?>
<form name='frmname' action='' method='post'>
<input type='radio' name='numbers[]' value='one'/>One
<input type='radio' name='numbers[]' value='two' />Two
<input type='radio' name='numbers[]' value='three' />Three
<input type='hidden' name='unchecked[]' value='one' />
<input type='hidden' name='unchecked[]' value='two' />
<input type='hidden' name='unchecked[]' value='three' />
<input type='submit' name='submit' value='Submit' />
</form>
I have solved it. I have sent both radio button values in hidden field and as well as radio button values. On receiving page, I have compare checked value with hidden field value and so I got unchecked value. Thanks for all who responded to my question.
© 2022 - 2024 — McMap. All rights reserved.