Checkboxes with HTML and PHP

Hey Guys,
I’m woking on a long contact form with several different fields. I have everything basically working but I get an All fields are required. message witch allows the email to go through the problem is I made check boxes with the same Name and different ID / Values but it will only show the one that was chosen last not all selected.

HTML
[php]

                   <p> 

I have a.








STAFF/EMPLOYEE RELATED
BANKRUPTCY
                  </form>[/php]

PHP
[php]<?php

// first clean up the input values
foreach($_POST as $key => $value) {
if(ini_get(‘magic_quotes_gpc’))
$_POST[$key] = stripslashes($_POST[$key]);

$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}

$ip=$_SERVER[‘REMOTE_ADDR’];
$email_to = “@.com”;
$email_subject = "Business Membership Form ";

$email_message .= “I have a case”.$_POST[“id”]."\n";

$email_message .= “Member ID #: “.$_POST[“id”].”\n”;

$email_message .= “Company Name: “.$_POST[“company”].”\n”;

$email_message .= “Authorized Representative: “.$_POST[“rep”].”\n”;

$email_message .= “Person Filling the Form: “.$_POST[“form”].”\n”;

$email_message .= “Best Way to Reach You: “.$_POST[“reach”].”\n”;

$email_message .= “Work Phone Number: “.$_POST[“wphone”].”\n”;

$email_message .= “Work Email: “.$_POST[“email”].”\n”;

$email_message .= “Issue: “.$_POST[“issue”].”\n”;

$userEmail = filter_var( $_POST[‘wemail’],FILTER_VALIDATE_EMAIL );

if (empty ($userEmail)) {}

//email headers

$headers = 'From: '.$_POST[“email”]."\r\n".

'Reply-To: '.$_POST[“email”]."\r\n" .

‘X-Mailer: PHP/’ . phpversion();

echo (mail($email_to, $email_subject, $email_message, $headers) ? "
":“

We’re sorry, something went wrong.

Please return to .

”);

$ip=$_SERVER[‘REMOTE_ADDR’];
$email_to = $_POST[“email”];
$email_subject = "Business Membership | ";

$email_message1 = "Thank you for contacting .

Please allow up to 48 hours for one of our representatives to respond.

Thank you,

";

//email headers

$headers = 'From: '.$_POST[“email”]."\r\n".

'Reply-To: '.$_POST[“email”]."\r\n" .

‘X-Mailer: PHP/’ . phpversion();

echo (mail($email_to, $email_subject, $email_message1, $headers) ? “”:"");

// Required field names
$required = array(‘name’, ‘email’);

// Loop over field names, make sure each one exists and is not empty
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}

if ($error) {
echo “All fields are required.”;
} else {
echo " ";
}

?>

[/php]

You are getting there. The processing form still needs work.

Example:

[php]

<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { foreach ($_POST['check'] as $k => $v) { echo "

$v

"; } } ?> <?php for ($i = 0; $i < 10; $i ++) { echo "

$i

"; } ?>

[/php]

Thanks for the help!
I cant seem to get it to work correctly though. With the code provided it will not show anything for that in the email. All the others show though. With the original code it will only show the last button selected.

Example:
[ ] Bob

[ul][li]Jack[/li][li]Jill[/li][/ul]

Email shows:
Jill

With the PHP provided it wouldn’t show up.

Is there an easy HTML fix for this? I got the drop downs to work perfect and at one time had a drop down that allowed multiple selections.

I also tried this but it doesnt show anything in the field.

This is within the form.
[php]C/C++

Java

PHP[/php]

[php] $email_message .= “Test: “.$_POST[“check_list[]”].”\n”;[/php]

I found this as a PHP code then modified it so it would hopefully work with my code.

[php]$_POST[“check_list[]”][/php]

This isn’t how you get the values. The code I posted demonstrated how to pull the array out from what gets passed in.

Here’s a way I grab an user’s input array :

[php] $check_list = filter_input(INPUT_POST, ‘check_list’, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);[/php]

Special Note: FILTER_DEFAULT doesn’t sanitize the user’s input (Think of it as water simply going through a pipe), but since check_list should only have default values (I’m assuming it is set up that way?) it really shouldn’t matter.

[member=72272]astonecipher[/member],

The curly braces are not needed here:

echo “

$i

”;

I know, I tend to do it for readability.

Sponsor our Newsletter | Privacy Policy | Terms of Service