Jump to content

how to submit a checkbox


Paul-D

Recommended Posts

Hi I have added a checkbox to a for [Bold]

When submitted to the update php I get 

echo $Bold;

On if it is ticked and 

Warning: Undefined array key "Bold" in /vhost/d/e/s/desmond-otoole.co.uk/www/bank2/StatementEntryUpdate.php on line 31

if it is not. Can someone help please.

<code

        if($direction == "Update")
        {
        $SE_MyReason = $_POST['Reason']; // Keep the default regardless
        $SE_Money_In = $_POST['MoneyIn'];
        $SE_Money_Out = $_POST['MoneyOut'];
        $SE_DD_Entry = $_POST['DD_Entry'];
        $SE_MM_Entry = $_POST['MM_Entry'];
        $SE_YYYY_Entry = $_POST['YYYY_Entry'];
        $Comment = $_POST['Comment'];  
        $Bold = $_POST['Bold'];          <--- Line 31
        
        echo $Bold; 
        exit;

</code>

 

Link to comment
Share on other sites

11 hours ago, Paul-D said:

I used if set = 1 else 0.

Posted returns 'On'' not a 1.

Thanks.

 

Yes, this is based on the value property of the checkbox.  

The important concept to remember is what Barand described:  an unchecked checkbox will not exist in the $_POST.  This is why Barand's code to utilize the null coalesce operator is generally speaking a best practice in PHP form handling where checkboxes are involved.

Link to comment
Share on other sites

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.