Jump to content

Recommended Posts

Hey Everyone, been a while. I need some help with an easy one. I'm brain farting and blanking out. Someone please help.

 

HTML form that has checkboxes:

 

<form ...>

<input name="check1" type="checkbox" value="Value 1">

</form>

 

 

PHP Code

 

$post_check1= $_POST["check1"];

$body .= "check1: ".$post_check1."\n";

 

The form doesn't return the value when checked. What I am missing? I know it's something simple. Please help. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/210881-checkboxes/
Share on other sites

There's at least 6+ different things that could be wrong with your form or your php code.

 

You would need to post all the form and the php code from the start of the file up through the $body .= "check1: ".$post_check1."\n"; statement for anyone to have a chance at helping you.

Link to comment
https://forums.phpfreaks.com/topic/210881-checkboxes/#findComment-1099917
Share on other sites

Here is the HTML Form:

 

<form method=post action="pass.php">
<table align="center">    
<tr><td colspan="5">What kind of color would you like?</td></tr>
    <tr align="center">
    <td align="center">Black</td>
    <td align="center">White</td>
    <td align="center">Blue</td>
    <td align="center">Red</td>
    <td align="center">Green</td>
    </tr>
        <tr align="center">
    <td align="center"><input name="checkbox1" type="checkbox" value="Black"></td>
    <td align="center"><input name="checkbox2" type="checkbox" value="White"></td>
    <td align="center"><input name="checkbox3" type="checkbox" value="Blue"></td>
    <td align="center"><input name="checkbox4" type="checkbox" value="Red"></td>
    <td align="center"><input name="checkbox5" type="checkbox" value="Green"></td>
    </tr>

                      <td colspan="5"><div align="center">
                        <input type="submit" value="Send Color Choice" />
                        <input type="reset" name="Reset" value="Clear Form">
                      </div></td>
                    </tr>
</table>
               <input type="hidden" name="next_url" value="size.htm">
               <input type="hidden" name="subject" value="Color Choice">
                </form>

 

Here is the PHP form that processes the Form.

 


<?php
$post_checkbox1 = $_POST["checkbox1"];
$post_checkbox2 = $_POST["checkbox2"];
$post_checkbox3 = $_POST["checkbox3"];
$post_checkbox4 = $_POST["checkbox4"];
$post_checkbox5 = $_POST["checkbox5"];

$body .= "Black: ".$post_checkbox1."\n";
$body .= "White: ".$post_checkbox2."\n";
$body .= "Blue: ".$post_checkbox3."\n";
$body .= "Red: ".$post_checkbox4."\n";
$body .= "Green: ".$post_checkbox5."\n";

$body .="\n";

  mail( "email@domain.com", "Color Choice", $body, $message, "From: <email@domain.com>");
?>


 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/210881-checkboxes/#findComment-1099926
Share on other sites

The form doesn't return the value when checked.

 

The code you posted does.

 

BTW, your mail() function call is incorrect. You have an extra parameter in the list.

 

Perhaps if you posted the actual code that has the problem and actually told us what problem you are having with it?

Link to comment
https://forums.phpfreaks.com/topic/210881-checkboxes/#findComment-1099931
Share on other sites

That is the actually code.

 

When I process the form, If I check the box or don't check the box, the output in the email is the same, nothing.

 

I shouldn't say nothing, if I check black, the output in the email is "Black:    ", if I don't check it, the output is "Black:    "

 

I want a user to be able to check black and the email output is "Black: Yes"

 

How do you post a check or unchecked value in an email?

Link to comment
https://forums.phpfreaks.com/topic/210881-checkboxes/#findComment-1099937
Share on other sites

A checkbox will only send its value if its is checked. The code you have posted is the correct way for retrieving the value from checkboxes. You will not be able to get the value from an unchecked checkbox

 

Add the following to your code

echo "<pre>" . print_r($_POST, true) . "</pre>";

 

Submit your form with the checkboxes checked and post the output here.

 

 

Link to comment
https://forums.phpfreaks.com/topic/210881-checkboxes/#findComment-1099940
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.