Hi,
I'm having some issues with checkboxes. When I submit the form and the email is sent, the check box area is empty. There is no information listed. When I tried to change the code, it would only show one of the options and not all that have been picked. Now when email is received it says Services Required: Array.

I'd appreciate any help!

Code is below:

Name: <input type="text" name="Name" size="50" class="name">  

 Business/Organisation: <input type="text" name="BusinessName" size="50" class="BusinessName">  

 Contact Number: <input type="text" name="ContactPhone" size="50">  
*Email: <input type="text" name="Email" size="50">   
                Services Required (tick as many as required):                               

<input type="checkbox" name="ServicesRequired" value="CustomWebsiteDesign" /> Custom Website Design  

 <input type="checkbox" name="ServicesRequired" value="Ecommerce" /> E-Commerce  
<input type="checkbox" name="ServicesRequired" value="TemplateDesign" /> Template Design  

              <input type="checkbox" name="ServicesRequired" value="HostingDomain" /> Hosting/Domain  

                <input type="checkbox" name="ServicesRequired" value="WebDevelopment" /> Web Development  

                  

    <input type="checkbox" name="ServicesRequired" value="Photography" /> Photography  

  

 Are there any sites you want your website to be similar to?  <input type="text" name="SimilarSites" size="50" >   

34 Will own artwork be supplied? (Logos, images etc) <input type="text" name="OwnArtworkSupplied" size="50">  

   

36 Will you want to update the website content yourself? <input type="text" name="UpdateOwnContent" size="50">  

  

38 Do you have a time frame? <input type="text" name="TimeFrame" size="50">  

 

40 Do you have a budget you need to work with? <input type="text" name="Budget" size="50">  

          

 <textarea rows="8" cols="40" name="Details"></textarea>   

    

   <input type="submit" class="submitquotebutton" name="submit" value="submit!">  

       

    </form>
<?php
/* Set e-mail recipient */
$myemail  = "info@purpleblaze.com.au";

/* Check all form inputs using check_input function */
$Name    = check_input($_POST['Name'], "Enter your name");
$BusinessName = check_input($_POST['BusinessName']);
$ContactPhone    = check_input($_POST['ContactPhone'], "Enter your contact number");
$Email    = check_input($_POST['Email']);
$ServicesRequired = $_POST['ServicesRequired']; if(is_array($ServicesRequired)){    $message .= "Type of Service needed:" .implode(", ",$ServicesRequired). "\n";}
$SimilarSites = check_input($_POST['SimilarSites']);
$OwnArtworkSupplied = check_input($_POST['OwnArtworkSupplied']);
$Pages = check_input($_POST['Pages']);
$TimeFrame = check_input($_POST['TimeFrame']);
$Details = check_input($_POST['Details'], "Write your enquiry");



/* 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: $Name 
Business Name: $BusinessName
Contact Number: $ContactPhone
E-mail: $Email
Services Required: $ServicesRequired
Websites similar to what you want: $SimilarSites
Is own artwork supplied: $OwnArtworkSupplied
What pages are required and how many? $Pages
Do you want to update your own content? $UpdateOwnContent
Is there a time frame? $TimeFrame
Do you have a budget? $Budget


Enquiry:
$Details

End of message
";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: thanks.php');
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();
}
?>

Recommended Answers

All 2 Replies

pretty sure you have to make your names an array.

<input type="checkbox" name="ServicesRequired[]" value="CustomWebsiteDesign" /> Custom Website Design

Thanks for the reply. I've now changed them to arrays a little while ago but im still getting the same problem :S

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.