Jump to content

Recommended Posts

Hi there, I am having trouble getting an answer to what I thought was a simple problem.  I am not php coder, and am dabbling in it for a client to get a form to email solution for them.  The form is working great to my email: except! -  the checkboxes are causing me hours of searching the internet.  All I want is for their value to sent to the email (only the ones that are checked)

 

here is the part of the html form for the checkboxes... - Thanks for you assistance.

 

 

  <input name="product[]" type="checkbox" id="wallart" value="Wall Art" />
      Wall Art<br>
        <input name="product[]" type="checkbox" id="mobile" value="Mobile" />
        Mobile
        <br>
        <input name="product[]" type="checkbox" id="blkboard" value="Blackboard decals" />
        Blk Board Decals
        <br>
        <input name="product[]" type="checkbox" id="screens" value="Screens" />
        Screens
        <br>
        <input name="product[]" type="checkbox" id="letnum" value="Letnum" />
        Acrylic Letters & Numbers <br>
        <input name="product[]" type="checkbox" id="shapes" value="Shapes" />
      Acrylic shapes

 

here is the whole of the PHP file:

 

<?php
/* Set e-mail recipient */
$myemail  = "mywebdots@gmail.com";

/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$subject  = check_input($_POST['subject'], "Write a subject");
$email    = check_input($_POST['email']);
$address  = check_input($_POST['address']);
$product   = check_input($_POST['product']);
$screens  = check_input($_POST['screens']);

$how_find = check_input($_POST['how']);
$from = check_input($_POST['email']);
$comments = check_input($_POST['comments'], "Write your comments");

print '<pre>';
print_r($_POST);
print '</pre>';

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
    show_error("E-mail address not valid");
}



/* Let's prepare the message for the e-mail */
$message = "Hello!, 

Your contact form has been submitted by:

Name: $yourname
E-mail: $email
Address: $address

Which products I am interested in?; 

$message .= "<ul>";
foreach($_POST['product'] as $key=>$val){
    $message .= "<li>".$val."</li>";
}
$message .= "</ul>";



How did he/she find it? $how_find

Comments:
$comments

End of message
";

/* Send the message using mail() function */
mail($myemail, $subject, $message, "From: $from");

/* Redirect visitor to the thank you page */
header('Location: thanks.htm');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError)
{
?>
    <html>
    <body>

    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>

    </body>
    </html>
<?php
exit();
}
?>

change to

<?php

/* Set e-mail recipient */

$myemail  = "mywebdots@gmail.com";

 

/* Check all form inputs using check_input function */

$yourname = check_input($_POST['yourname'], "Enter your name");

$subject  = check_input($_POST['subject'], "Write a subject");

$email    = check_input($_POST['email']);

$address  = check_input($_POST['address']);

$product  = check_input($_POST['product']);

$screens  = check_input($_POST['screens']);

 

$how_find = check_input($_POST['how']);

$from = check_input($_POST['email']);

$comments = check_input($_POST['comments'], "Write your comments");

 

print '<pre>';

print_r($_POST);

print '</pre>';

 

/* If e-mail is not valid show error message */

if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))

{

    show_error("E-mail address not valid");

}

 

 

 

/* Let's prepare the message for the e-mail */

$message = "Hello!,

 

Your contact form has been submitted by:

 

Name: $yourname

E-mail: $email

Address: $address

 

Which products I am interested in?"; // add "

 

$message .= "<ul>";

foreach($_POST['product'] as $key=>$val){

    $message .= "<li>".$val."</li>";

}

$message .= "</ul>";

 

// add next line

$message .= "

How did he/she find it? $how_find

 

Comments:

$comments

 

End of message

";

 

/* Send the message using mail() function */

mail($myemail, $subject, $message, "From: $from");

 

/* Redirect visitor to the thank you page */

header('Location: thanks.htm');

exit();

 

/* Functions we used */

function check_input($data, $problem='')

{

    $data = trim($data);

    $data = stripslashes($data);

    $data = htmlspecialchars($data);

    if ($problem && strlen($data) == 0)

    {

        show_error($problem);

    }

    return $data;

}

 

function show_error($myError)

{

?>

    <html>

    <body>

 

    <b>Please correct the following error:</b><br />

    <?php echo $myError; ?>

 

    </body>

    </html>

<?php

exit();

}

?>f/code]

 

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.