Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this right??

Status
Not open for further replies.

Wulfgen

Technical User
Dec 31, 2004
283
US
I have a form with a few checkboxes in it - they are all type="checkbox" but each set has its own name/id. The php file works fine but if the user does not select a check box, the return email just leaves the [$nameofcheckbox] area empty..

I would rather have the email reflect that this or that checkbox was not used EG: No (Right now if a user checks the box, the email has the checkbox as Yes, but if not... empty - Rather it say No)

I've tried this:
///Checkbox Setups----------------
$yes = $no = "";
if (isset( $_POST['checkbox']))
{ ${$_POST['checkbox']} = "checked";} else {$yes = "checked";}

it actually works with radio butoons but not with checkboxes - any pointers on how I could accomplish this?

Thanks to all.........
 

You should use :

Code:
if ($_POST["cb"] == "yes) {

$checked = "checked=\"checked\"";

} else {

$checked = "";

}

...

echo"
<input type=\"checkbox\" name=\"cb\" value=\"yes\" " . $checked . ">
";
 
The echo part seems to break what I have - I have no other echo's going on, all its supposed to do is; where in the email format I have the checkbox name: ( $colors ) to be (if checked Yes if unchecked No)
 
The input element was just an example in case you wanted to have it checked according to its posted value.

Just use this then :

Code:
if ($_POST["your_cb"] == "your_cb_value") { ...; } else { ...; }
 
This is correct yes? -
Code:
if ($_POST["checkbox"] == "yes") { Yes; } else { No; }
 
If you replace "yes" and "no" by some real PHP code, then yes it is correct :)
 
you need to /should profile your checkboxes first using an array such as the following
Code:
$output = '';
$checkBoxes = array("apple", "banana", "carrot", "damson");
foreach ($checkBoxes as $checkBox){
 if (isset($_POST[$checkBox])){
  $option .= "checkbox $checkBox was selected<br/>/r/n"; 
 } else {
  $option .= "checkbox $checkBox was not selected<br/>/r/n";
 }
}
echo $output;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top