AJW Posted February 20, 2010 Share Posted February 20, 2010 I'm building a registration form that allows the user to enter some basic information, select the program that they're registering for, then enter the number of attendees for that particular program. The form will make sure that they've entered an email address. (and, later, it will make sure that they've provided a correct answer to a ReCaptcha once I've set one up) If they have, the form results will be emailed to the site owner and a generic "thank you!" message will be generated for the user if the email has been successful. What I'm trying to figure out is how to tell PHP to examine the array of checkboxes that correspond to the programs, and, if it finds that one is checked, to then look at the corresponding "attendees" box and output the number of attendees for that program. I don't really know PHP, so all the code I've got so far is pretty much a hodgepodge of code from various tutorials. I apologize for the mess. <?php function spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } if (isset($_REQUEST['regemail'])) {//if "email" is filled out, proceed //check if the email address is invalid $mailcheck = spamcheck($_REQUEST['regemail']); if ($mailcheck==FALSE) { echo "Invalid email address. Please re-enter and try again."; } else //if "email" is filled out, send email { //Header information $subject = $name." Registration"; $email = "email@email.com" ; //send email $name = $_POST['Name'] ; $organization = $_POST['Organization'] ; $street = $_POST['Street'] ; $city = $_POST['Street'] ; $state = $_POST['State'] ; $zip = $_POST['Zip'] ; $phone = $_POST['Phone'] ; $fax = $_POST['Fax'] ; $regemail = $_POST['Email'] ; $project= implode(",",$_POST['project']); $attendees= array('$p1attend','$p2attend','$p3attend','$p4attend','$YLTattend'); foreach($attendees as $guests) { echo $guests, ' '; } $p1attend= $_POST['P1-attendees']; $p2attend= $_POST['P2-attendees']; $p3attend= $_POST['P3-attendees']; $p4attend= $_POST['P4-attendees']; $YLTattend= $_POST['YLT-attendees']; $message= $name." is registering for ".$project.". There are ".$guests." \nOrganization (If Applicable): " .$organization. "\nEmail Address: ".$regemail." \nMailing Address: ".$street." \t".$city."\t".$state."\t".$zip. "\nPhone Number: ".$phone."\nFax: ".$fax. mail($email, $subject, $message); } } ?> <form action="<txp:site_url/>php/submit.php" method="post"> <table> <tr> <td><label>Name</label></td> <td><input name="Name" type="text" size="25"/></td> </tr> <tr> <td><label>Organization</label></td> <td><input name="Organization" type="text" size="25"/></td> </tr> <tr> <td><label>Street</label></td> <td><input name="Street" type="text" size="25"/></td> </tr> <tr> <td><label>City</label></td> <td><input name="City" type="text" maxlength="4" size=25"/></td> <td><label>State</label></td> <td><input name="State" type="text" /></td> <td><label>Zip</label></td> <td><input name="Zip" type="text" maxlength="5" size="5" /></td> </tr> <tr> <td><label>Phone #</label></td> <td><input name="Phone" type="text" maxlength="13" size="13" /></td> <td><label>Fax #</label></td> <td><input name="Fax" type="text" maxlength="13" size="13" /></td> </tr> <tr> <td><label>Email</label></td> <td><input name="Email" type="text" size="25"/></td> </tr> </table> <table> <thead> <tr> <th><em>Check Below</em></th> <th>Program</th> <th>Time</th> <th>Location</th> <th># of Attendees</th> </tr> </thead> <tbody> <tr> <td><input type="checkbox" NAME="project[]" value="P1" /></td> <td> BASIC COMPONENTS of the GRANT PROPOSAL <br/> <small><strong>March 18, 2010</strong></small> </td> <td>6:30 PM – 8:30 PM</td> <td>Health Partners</td> <td><input name="P1-attendees" type="text" maxlength="2" size="2"></td> </tr> <tr> <td><input type="checkbox" NAME="project[]" value="P1" /></td> <td> WRITING GRANT PROPOSAL GOALS & OBJECTIVES<br/> <small><strong>April 15, 2010</strong></small> </td> <td>6:30 PM – 8:30 PM</td> <td>Health Partners</td> <td><input name="P2-attendees" type="text" maxlength="2" size="2"></td> </tr> <tr> <td><input type="checkbox" NAME="project[]" value="P2" /></td> <td> WRITING BUDGETS & LOCATING FUNDERS<br/> <small><strong>May 20, 2010</strong></small> </td> <td>6:30 PM – 8:30 PM</td> <td>Health Partners</td> <td><input name="P3-attendees" type="text" maxlength="2" size="2"></td> </tr> <tr> <td><input type="checkbox" NAME="project[]" value="P3" /></td> <td> FORMING A 501c3 NON PROFIT ORGANIZATION<br/> <small><strong>May 22, 2010</strong></small> </td> <td>10:00 AM- 1:00 PM</td> <td>Health Partners</td> <td><input name="P4-attendees" type="text" maxlength="2" size="2"></td> </tr> <tr> <td><input type="checkbox" NAME="project[]" value="YLT" /></td> <td> YOUTH LEADERSHIP TRAINING<br/> <small><strong>January 23, 2010 </strong></small> </td> <td>10:00 AM- 1:00 PM</td> <td> </td> <td><input name="YLT-attendees" type="text" maxlength="2" size="2"></td> </tr> </tbody> </table> <br /> <label>Additional Comments</label><br/> <textarea></textarea> <br/> <input type="image" src="<txp:site_url/>images/register-red.png" value="Submit" /> </form> Quote Link to comment Share on other sites More sharing options...
battlesiege Posted February 20, 2010 Share Posted February 20, 2010 here is some code to loop over your checked projects and for each one that is checked will output the value of the checkbox and the corresponding attendees foreach($_POST['project'] as $project) { // $project = whatever is in the value attr e.g. P1,P2,P3 // $_POST[$project . '-attendees'] = e.g. $_POST['P1-attendees'] = what ever you enter into the attendee input echo $project . ' - ' . $_POST[$project . '-attendees'] . '<br />'; } --- Your code may be a bit of a hodgepodge but I've certainly seen far worse. Keep at it and you get the hang in no time Quote Link to comment Share on other sites More sharing options...
AJW Posted February 21, 2010 Author Share Posted February 21, 2010 Thanks! I tested the form on the site; even though I turned on error reporting in the PHP file, all I'm getting is a blank page after I hit "submit, and nothing is being sent to my inbox. Any suggestions? <?php ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); function spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } if (isset($_REQUEST['email'])) {//if "email" is filled out, proceed //check if the email address is invalid $mailcheck = spamcheck($_REQUEST['email']); if ($mailcheck==FALSE) { echo "Invalid email address. Please re-enter and try again."; } else //if "email" is filled out, send email { //Header information $subject = $name." Registration"; $email = "email@email.com" ; //send email $name = $_POST['Name'] ; $organization = $_POST['Organization'] ; $street = $_POST['Street'] ; $city = $_POST['Street'] ; $state = $_POST['State'] ; $zip = $_POST['Zip'] ; $phone = $_POST['Phone'] ; $fax = $_POST['Fax'] ; $regemail = $_POST['Email'] ; foreach($_POST['project'] as $project) { // $project = whatever is in the value attr e.g. P1,P2,P3 // $_POST[$project . '-attendees'] = e.g. $_POST['P1-attendees'] = what ever you enter into the attendee input echo $project . ' - ' . $_POST[$project . '-attendees'] . '<br />'; } $message= $name." is registering for ".$project." \nOrganization (If Applicable): " .$organization." \nEmail Address: ".$regemail." \nMailing Address: ".$street." \t ".$city." \t ".$state." \t ".$zip." \nPhone Number: ".$phone."\nFax: ".$fax. mail($email, $subject, $message); echo 'Thank you for registering for a BLCE program!'; } } ?> Quote Link to comment Share on other sites More sharing options...
battlesiege Posted February 22, 2010 Share Posted February 22, 2010 Thats probably because all you have done is create a function, you then need to execute it where it is required Quote Link to comment 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.