Hi All,

I have a PHP code to display table data with a column of checkboxes used to click to mark the test case as Blocked. I am trying to save the state of checkbox after it is submitted, but I am unable to do so.
Please help!

echo "<form id =\"blockform\" method=\"post\" action=\"\">";
echo "<form id=\"checkbox\" class=\"check2\" method = \"post\">";
$checked = "";
if(isset($_POST['Blocked[]'])) {
$checked = 'checked="checked"';
}
echo "<td $Blocked><input type =\"checkbox\" name=\"Blocked[]\" value=\"checkblock\" onclick=\"showMsg('div1')\" $checked/></td>";             

echo "<input type=\"submit\" value=\"Submit\" class=\"button\" name=\"edit_tc\" onclick=\"myFunction(form)\" style=\"position:fixed; height:25px ; width:150px; bottom:25px; right:200px;\"/>";
echo "</form>";
echo "</form>";

Recommended Answers

All 5 Replies

change your checkbox name to name="checkblock"

Why do you have a form inside a form? That makes no sense.. you should only have one.

My bad. I have removed it.
I have changed the name also, but it is not working. Please help.

@diafol, request your expertise here.
Thanks.

Member Avatar for diafol

Gabriel has the expertise to help you if he still wants to. There are a number of contributors that frequent the PHP forum whose ability is greater than mine. Thanks.

Try this condition

if(isset($_POST['Blocked'])) {
$checked = 'checked="checked"';
}

I refactored the little bit of code gave.. This should work for you. if not, you need to post more code so we can see where you are going wrong.

 <form id="blockform" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" />
    <table>
        <tr>
            <td>
                <input type="checkbox" name="checkblock" value="checkblock" onclick="showMsg('div');" <?php if(isset($_POST['checkblock'])){echo 'checked="checked"';} ?> />
            </td>
        </tr>
        <tr>
            <td>
                <input class="button" type="submit" name="submit" value="Submit"  onclick="myFunction(form);" style="position:fixed; height:25px; width:150px; bottom:25px; right:200px;" />
            </td>
        </tr>
    </table>
</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.