happyhart Posted August 21, 2011 Share Posted August 21, 2011 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 = '[email protected]'; $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 <[email protected]>' . "\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> Quote Link to comment https://forums.phpfreaks.com/topic/245394-trying-to-process-a-form-w-multiple-checkboxes-then-redirect-to-a-thank-you/ Share on other sites More sharing options...
voip03 Posted August 22, 2011 Share Posted August 22, 2011 You need to validate the check Box. if(!empty($_REQUEST['interest'])) { $imploded_interest = implode(',',$interest); } Quote Link to comment https://forums.phpfreaks.com/topic/245394-trying-to-process-a-form-w-multiple-checkboxes-then-redirect-to-a-thank-you/#findComment-1260406 Share on other sites More sharing options...
happyhart Posted August 22, 2011 Author Share Posted August 22, 2011 @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.. Quote Link to comment https://forums.phpfreaks.com/topic/245394-trying-to-process-a-form-w-multiple-checkboxes-then-redirect-to-a-thank-you/#findComment-1260504 Share on other sites More sharing options...
voip03 Posted August 22, 2011 Share Posted August 22, 2011 Have you tried 1st code then try this code if(!empty($_REQUEST['interest'])) { $imploded_interest = implode(',',$interest); } else { $imploded_interest =0; } Quote Link to comment https://forums.phpfreaks.com/topic/245394-trying-to-process-a-form-w-multiple-checkboxes-then-redirect-to-a-thank-you/#findComment-1260538 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.