Jump to content

trying to process a form w multiple checkboxes then redirect to a thank you


happyhart

Recommended Posts

Can someone please help? I am simply trying to email process a form with checkboxes and then redirect to a thank you page.  It works fine as long as at least one checkbox is checked. It breaks if no checkboxes are checked using the implode function to list the "interests". I'm getting this error (and no redirect to my thank you page): Warning: implode() [function.implode]: Invalid arguments passed...

 

<?php

if (isset($_REQUEST['submit']))

{

$email = $_REQUEST['email'];

$firstName = $_REQUEST['firstName'];

$lastName = $_REQUEST['lastName'];

$address = $_REQUEST['address'];

$city = $_REQUEST['city'];

$state = $_REQUEST['state'];

$zipcode = $_REQUEST['zipcode'];

$homePhone = $_REQUEST['homePhone'];

$cellPhone = $_REQUEST['cellPhone'];

$interest = $_REQUEST['interest'];

$imploded_interest = implode(',',$interest);

$comments = $_REQUEST['comments'];

$to  = 'myemailhere@yahoo.com';

$subject = 'Volunteer Signup';

$message = "

<html>

<head>

<title>Volunteer Signup</title>

</head>

<body>

<p>Hello,<br/>A visitor has submitted the following information from the volunteer page:</p>

<p><b>$firstName $lastName</b><br/>

$address<br/>

$city, $state $zipcode<br/><br/>

Home Phone: $homePhone<br/>

Cell Phone: $cellPhone<br/>

Email: <strong>$email</strong><br/><br/>

I would like to help in the following ways:<br/>

$imploded_interest

</p><br/>

<p>$firstName would also like share the following comments:<br/>

<q><i>$comments</i></q>

</p>

</body>

</html>

";

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: Volunteer Signup <myemailhere@yahoo.com>' . "\r\n";

mail($to, $subject, $message, $headers);

}

?>

<!DOCTYPE html>

<html lang="en">

<head>

<title>Volunteer</title>

</head>

<body>

<form id="VolunteerForm" method="post" action="thankyou.php">

        <table>

                        <tr>

                            <td style="width:150px;">Email Address:</td>

                                <td><input name="email" type="text" id="email" /></td>

                                <td style="width:320px;" class="padtr"><strong>Ways I can help:</strong></td>

                        </tr>

                                <tr>

                            <td>First Name:</td>

                                <td><input name="firstName" type="text" id="firstName" /></td>

                                <td class="padtr"><input name="interest[]" value="yard-sign" type="checkbox"/>

Put a yard sign in my yard</td>

                            </tr>

                            <tr>

                            <td>Last Name:</td>

                                <td><input name="lastName" type="text" id="lastName" /></td>

                                <td class="padtr"><input name="interest[]" value="fundraiser-at-home" type="checkbox" />

Host a fundraiser at my home</td>

                            </tr>

                            <tr>

                            <td>Address:</td>

                                <td><input name="address" type="text" id="address" /></td>

                                <td class="padtr"><input name="interest[]" value="phone-calls" type="checkbox" />

                                Make phone calls to friends and family</td>

                            </tr>

                            <tr>

                            <td>City:</td>

                                <td><input name="city" type="text" id="city" /></td>

                                <td class="padtr"><input name="interest[]" value="mailings" type="checkbox" />

                                Help with mailings</td>

                            </tr>

                            <tr>

                            <td>State:</td>

                                <td><input name="state" type="text" id="state" /></td>

                                <td class="padtr"><input name="interest[]" value="doors-literature" type="checkbox" />

                                  Help knock on doors and distribute literature</td>

                            </tr>

                            <tr>

                            <td>Zip Code:</td>

                                <td><input name="zipcode" type="text" id="zipcode" /></td>

                                <td class="padtr"><input name="interest[]" value="donate" type="checkbox" />

                                  Make a donation</td>

                            </tr>

                            <tr>

                            <td>Home Phone:</td>

                                <td><input name="homePhone" type="text" id="homephone" /></td>

                                <td class="padtr"><input name="interest[]" value="endorsement" type="checkbox" />

                                Use my name as an endorsement</td>

                            </tr>

                            <tr>

                            <td>Cell Phone:</td>

                                <td><input name="cellPhone" type="text" id="cellphone" /></td>

                                <td class="padtr"><input name="interest[]" value="newsletter" type="checkbox" />

                                Sign up for our newsletter</td>

                            </tr>

                            <tr>

                              <td>Comments:</td>

  <td><textarea name="comments" id="comments" rows="5" cols="17"></textarea></td>

                              <td> </td>

                            </tr>

                            <tr>

      <td> </td>

      <td> </td>

                                <td>     <input type="submit" name="submit" id="submit" value="Submit Now" />  <input type="reset" name="reset" id="reset" value="Clear Form" /></td>

                            </tr>

                        </table>

                        </form>

</body>

</html>

Link to comment
Share on other sites

@voip, thanks for taking the time to help me. I haven't added validation partially because I don't fully understand how to wrap it all together  but mostly because the client wants the form to go through even if nothing is checked. Is there a way to secretly pass a value to the variable "interest" if nothing is checked? That is what I tried to do with the hidden input field. As you can see, I'm very new at this..

Link to comment
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.