deziner76hd Posted October 17, 2010 Share Posted October 17, 2010 Below is my code. I am having an issue with the form printing the Gender to an e-mail that it sends. I can't figure out what I am missing. Everything else works fine. I also need to have a list of check boxes that more than one can be selected like What kind of music do you like? Rock Pop ETC Any help with this would be greatly appreciated Thank you Gary Code below ----------------------------------------------------------------------------------------- <?php $your_email ='email@emailaddress.com';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_q1 = $_POST['q1']; $user_message = $_POST['message']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "\n The captcha code does not match!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Full Name: $name\n". "Email: $visitor_email \n". "Gender: $gender \n". "Q1: $visitor_q1 \n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); header('Location: thank-you.html'); } } // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> <META name="description" content="Voice Lessons with Richard Fink IV world wide via Skype and iChat. Vocal studio located near Rochester NY."> <META name="keywords" content="rates, cost, vocal, teacher, coach, voice, private, lessons, rochester, ny, skype, ichat, new york city, los angels, las vegas, nyc, la, artist, pop, r&b, rock, country, metal"> <META NAME="GENERATOR" Content="Visual Page 2.0 for Windows"> <TITLE>Frequently Asked Questions | Vocal Coach | Castle Nine Vocal Studios</TITLE> <style type="text/css"> <!-- body,td,th { color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: medium; } body { background-color: #FFFFFF; } .style9 {font-size: 14px} .style18 {font-size: 25px; color: #330033; } .style20 {font-size: 24px} .style21 { font-size: 12px; font-style: italic; } .style23 {color: #000000} .style10 {color: #330033} .style11 { color: #330033; font-weight: bold; } --> </style> <style> label,a, body { font-family : Arial, Helvetica, sans-serif; font-size : 12px; } .err { font-family : Verdana, Helvetica, sans-serif; font-size : 12px; color: red; } </style> <script type="text/JavaScript"> <!-- function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script> <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script> </HEAD> <BODY LINK="#330066" VLINK="#330066" ALINK="red" onLoad="MM_preloadImages('images/pdalinkbio2.jpg','images/pdalinkhome2.jpg','images/pdalinkvocal2.jpg','images/pdalinkphotos2.jpg','images/pdalinktest2.jpg','images/pdalinkfaq2.jpg')"> <CENTER> <table border="0" align="center" cellpadding="5"> <tr> <td width="647" height="817" bgcolor="#CCCCCC"><table width="647" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="647" align="center" valign="top" bgcolor="#FFFFFF"><div align="center"><img src="images/pdaheading.jpg" width="647" height="158"><a href="http://www.richardiv.com/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image11','','images/pdalinkhome2.jpg',1)"><img src="images/pdalinkhome.jpg" name="Image11" width="61" height="16" border="0"></a><a href="http://www.richardiv.com/richardfinkiv.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image10','','images/pdalinkbio2.jpg',1)"><img src="images/pdalinkbio.jpg" name="Image10" width="110" height="16" border="0"></a><a href="http://www.richardiv.com/voicelessons.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image12','','images/pdalinkvocal2.jpg',1)"><img src="images/pdalinkvocal.jpg" name="Image12" width="145" height="16" border="0"></a><a href="http://www.richardiv.com/photos.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image13','','images/pdalinkphotos2.jpg',1)"><img src="images/pdalinkphotos.jpg" width="146" height="16" border="0"></a><a href="http://www.richardiv.com/testimonials.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image14','','images/pdalinktest2.jpg',1)"><img src="images/pdalinktest.jpg" name="Image14" width="130" height="16" border="0"></a><a href="http://www.richardiv.com/faq.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image15','','images/pdalinkfaq2.jpg',1)"><img src="images/pdalinkfaq.jpg" name="Image15" width="55" height="16" border="0"></a><span class="style18"><br> </span><br> </div></td> </tr> <tr> <td height="601" bgcolor="#FFFFFF"><table width="644" border="0" align="center" cellpadding="5"> <tr> <td width="630" height="597"><p align="justify" class="style9"><span class="style18"><span class="style20"><span class="style23"><?php if(!empty($errors)){ echo "<p class='err'>".nl2br($errors)."</p>"; } ?> <div id='contact_form_errorloc' class='err'></div> <form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <p> <label for='name'>Full Name: </label><br> <input type="text" name="name" value='<?php echo htmlentities($name) ?>'> </p> <p> <label for='email'>Email: </label><br> <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'> <p> <p> <label for='q1'>Q1: </label><br> <input type="text" name="q1" value='<?php echo htmlentities($visitor_q1) ?>'> <p> <p> <label for='gender'>Male: </label> <input type="radio" name="Gender" value='<?php echo htmlentities($male) ?>'/> <br /> <label for='Gender'>Female:</label> <input type="radio" name="Gender" value='<?php echo htmlentities($female) ?>'/> <br /> </p> <p> <label for='message'>Message:</label> <br> <textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea> </p> <p> <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br> <label for='message'>Enter the code above here :</label><br> <input id="6_letters_code" name="6_letters_code" type="text"><br> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p> <input type="submit" value="Submit" name='submit'> </form></i><br> <br> <br> <br> </p> </td> </tr> </table> </td> </tr> <tr> <td><img src="images/pdabase.jpg" width="647" height="48" border="0" usemap="#Map2"></td> </tr> </table> </td> </tr> </table> </CENTER> <map name="Map"><area shape="rect" coords="514,43,633,70" href="richard_fink_iv/voicelessons.htm"> <area shape="rect" coords="514,74,637,96" href="richard_fink_iv/photo.htm"> <area shape="rect" coords="529,101,637,124" href="richard_fink_iv/testimonials.htm"> <area shape="rect" coords="581,128,638,150" href="richard_fink_iv/faq.htm"> <area shape="rect" coords="152,52,462,113" href="richard_fink_iv/mobileindex.html"> </map> <map name="Map2"><area shape="rect" coords="462,7,503,46" href="http://www.facebook.com/pages/Richard-Fink-IV-Vocal-Coach/165219796824660"> <area shape="rect" coords="509,5,550,47" href="http://www.myspace.com/richardfinkiv"> <area shape="rect" coords="558,6,596,48" href="http://www.twitter.com/richardfinkiv"> <area shape="rect" coords="607,6,647,47" href="http://www.youtube.com/richardfinkiv"> </map> <map name="Map3"><area shape="rect" coords="-5,-1,129,67" href="http://www.skype.com"> <area shape="rect" coords="135,1,213,77" href="http://www.apple.com"> </map> <map name="Map4"><area shape="rect" coords="497,16,647,151" href="index.html"> </map> <script language="JavaScript"> // Code for validating the form // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml // for details var frmvalidator = new Validator("contact_form"); //remove the following two lines if you like error message box popups frmvalidator.EnableOnPageErrorDisplaySingleBox(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("name","req","Please provide your name"); frmvalidator.addValidation("email","req","Please provide your email"); frmvalidator.addValidation("email","email","Please enter a valid email address"); </script> <script language='JavaScript' type='text/javascript'> function refreshCaptcha() { var img = document.images['captchaimg']; img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000; } </script> </BODY> </HTML> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2010 Share Posted October 18, 2010 you don't define $gender, so it is not set. Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 18, 2010 Author Share Posted October 18, 2010 Where do I have to define it? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2010 Share Posted October 18, 2010 before you put it in the email message. i suggest the same place you define the other values that you put into the email. Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 18, 2010 Author Share Posted October 18, 2010 Ok I have defined it here like so and it still will not process it when the email is sent //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Full Name: $name\n". "Email: $visitor_email \n". "Gender: $gender \n". "Language: $lang \n". "Q1: $visitor_q1 \n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); header('Location: thank-you.html'); } } -------------------------------------------------------------- Here is what is returned A user gary submitted the contact form: Full Name: gary Email: gwthsjkh@jkskd.com Gender: Language: Q1: the ands Message: test IP: 74.74.118.219 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2010 Share Posted October 18, 2010 no, you haven't defined $gender. you haven't set it equal to anything. you probably need to do this: $gender = $_POST['Gender']; Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 18, 2010 Author Share Posted October 18, 2010 php is new to me and i;m not very good at it yet. I was able to piece this togher with snippets of code but now I am stuck and have no idea where to put $gender = $_POST['Gender']; I tried putting it in several places I thought would work but no luck Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 18, 2010 Author Share Posted October 18, 2010 Any detailed help for a newbie would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
objnoob Posted October 18, 2010 Share Posted October 18, 2010 Define it at the same place you define the rest of the submitted information... Right Around Here: $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_q1 = $_POST['q1']; $user_message = $_POST['message']; Quote Link to comment Share on other sites More sharing options...
chintansshah Posted October 18, 2010 Share Posted October 18, 2010 <label for='gender'>Male: </label> <input type="radio" name="Gender" value='<?php echo htmlentities($male) ?>'/> <br /> <label for='Gender'>Female:</label> <input type="radio" name="Gender" value='<?php echo htmlentities($female) ?>'/> <br /> I think, in above code, value is not assigned to $male or $female, Please check from where you assign your value. Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 18, 2010 Author Share Posted October 18, 2010 Thank you for that insight. I have it so it prints to the email but it only prints ,male Somewhere i think i need an if else statement but I don't know where it would go I tried putting one in the code above the header but it gave me errors This is what my sent email is printing at this point The choice of male and female is not correct A user gary submitted the contact form: Full Name: gary Email: test@testing.com Gender: ,male Language: Q1: an ans Message: test IP: 74.74.118.219 Code above header <?php $your_email ='gwhite@dezinezone2002.com';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_q1 = $_POST['q1']; $user_message = $_POST['message']; $gender = $_POST['gender']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "\n The captcha code does not match!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Full Name: $name\n". "Email: $visitor_email \n". "Gender: $female,male \n". "Language: $lang \n". "Q1: $visitor_q1 \n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); header('Location: thank-you.html'); } } // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?> Code in header <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script> php in body <?php if(!empty($errors)){ echo "<p class='err'>".nl2br($errors)."</p>"; } ?> Form in body <form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <p> <label for='name'>Full Name: </label><br> <input type="text" name="name" value='<?php echo htmlentities($name) ?>'> </p> <p> <label for='email'>Email: </label><br> <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'> <p> <p> <label for='q1'>Q1: </label><br> <input type="text" name="q1" value='<?php echo htmlentities($visitor_q1) ?>'> <p> <p> <label for='Gender'>Male: </label> <input type="radio" name="gender" value='<?php echo htmlentities($male) ?>'/> <br /> <label for='Gender'>Female:</label> <input type="radio" name="gender" value='<?php echo htmlentities($female) ?>'/> <br /> </p> <p>I speak the following languages: </p> <p> <input type="checkbox" name="lang" value='<?php echo htmlentities($en) ?>'/> English<br /> <input type="checkbox" name="lang" value='<?php echo htmlentities($fr) ?>'/> Français<br /> <input type="checkbox" name="lang" value='<?php echo htmlentities($es) ?>'/> Español<br /> </p> <p>My preferred language is: </p> <p> <input type="radio" name="pref" value="en" checked> English<br /> <input type="radio" name="pref" value="fr"> Français<br /> <input type="radio" name="pref" value="es"> Español<br /> </p> <p> <label for='message'>Message:</label> <br> <textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea> </p> <p> <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br> <label for='message'>Enter the code above here :</label><br> <input id="6_letters_code" name="6_letters_code" type="text"><br> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p> <input type="submit" value="Submit" name='submit'> </form> validation in body <script language="JavaScript"> // Code for validating the form // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml // for details var frmvalidator = new Validator("contact_form"); //remove the following two lines if you like error message box popups frmvalidator.EnableOnPageErrorDisplaySingleBox(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("name","req","Please provide your name"); frmvalidator.addValidation("email","req","Please provide your email"); frmvalidator.addValidation("email","email","Please enter a valid email address"); </script> <script language='JavaScript' type='text/javascript'> function refreshCaptcha() { var img = document.images['captchaimg']; img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000; } </script> This is the entire page <?php $your_email ='gwhite@dezinezone2002.com';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_q1 = $_POST['q1']; $user_message = $_POST['message']; $gender = $_POST['gender']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "\n The captcha code does not match!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Full Name: $name\n". "Email: $visitor_email \n". "Gender: $female,male \n". "Language: $lang \n". "Q1: $visitor_q1 \n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); header('Location: thank-you.html'); } } // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> <META name="description" content="Voice Lessons with Richard Fink IV world wide via Skype and iChat. Vocal studio located near Rochester NY."> <META name="keywords" content="rates, cost, vocal, teacher, coach, voice, private, lessons, rochester, ny, skype, ichat, new york city, los angels, las vegas, nyc, la, artist, pop, r&b, rock, country, metal"> <META NAME="GENERATOR" Content="Visual Page 2.0 for Windows"> <TITLE>Frequently Asked Questions | Vocal Coach | Castle Nine Vocal Studios</TITLE> <style type="text/css"> <!-- body,td,th { color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: medium; } body { background-color: #FFFFFF; } .style9 {font-size: 14px} .style18 {font-size: 25px; color: #330033; } .style20 {font-size: 24px} .style21 { font-size: 12px; font-style: italic; } .style23 {color: #000000} .style10 {color: #330033} .style11 { color: #330033; font-weight: bold; } --> </style> <style> label,a, body { font-family : Arial, Helvetica, sans-serif; font-size : 12px; } .err { font-family : Verdana, Helvetica, sans-serif; font-size : 12px; color: red; } </style> <script type="text/JavaScript"> <!-- function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script> <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script> </HEAD> <BODY LINK="#330066" VLINK="#330066" ALINK="red" onLoad="MM_preloadImages('images/pdalinkbio2.jpg','images/pdalinkhome2.jpg','images/pdalinkvocal2.jpg','images/pdalinkphotos2.jpg','images/pdalinktest2.jpg','images/pdalinkfaq2.jpg')"> <CENTER> <table border="0" align="center" cellpadding="5"> <tr> <td width="647" height="817" bgcolor="#CCCCCC"><table width="647" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="647" align="center" valign="top" bgcolor="#FFFFFF"><div align="center"><img src="images/pdaheading.jpg" width="647" height="158"><a href="http://www.richardiv.com/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image11','','images/pdalinkhome2.jpg',1)"><img src="images/pdalinkhome.jpg" name="Image11" width="61" height="16" border="0"></a><a href="http://www.richardiv.com/richardfinkiv.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image10','','images/pdalinkbio2.jpg',1)"><img src="images/pdalinkbio.jpg" name="Image10" width="110" height="16" border="0"></a><a href="http://www.richardiv.com/voicelessons.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image12','','images/pdalinkvocal2.jpg',1)"><img src="images/pdalinkvocal.jpg" name="Image12" width="145" height="16" border="0"></a><a href="http://www.richardiv.com/photos.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image13','','images/pdalinkphotos2.jpg',1)"><img src="images/pdalinkphotos.jpg" width="146" height="16" border="0"></a><a href="http://www.richardiv.com/testimonials.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image14','','images/pdalinktest2.jpg',1)"><img src="images/pdalinktest.jpg" name="Image14" width="130" height="16" border="0"></a><a href="http://www.richardiv.com/faq.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image15','','images/pdalinkfaq2.jpg',1)"><img src="images/pdalinkfaq.jpg" name="Image15" width="55" height="16" border="0"></a><span class="style18"><br> </span><br> </div></td> </tr> <tr> <td height="601" bgcolor="#FFFFFF"><table width="644" border="0" align="center" cellpadding="5"> <tr> <td width="630" height="597"><p align="justify" class="style9"><span class="style18"><span class="style20"><span class="style23"> <?php if(!empty($errors)){ echo "<p class='err'>".nl2br($errors)."</p>"; } ?> <div id='contact_form_errorloc' class='err'></div> <form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <p> <label for='name'>Full Name: </label><br> <input type="text" name="name" value='<?php echo htmlentities($name) ?>'> </p> <p> <label for='email'>Email: </label><br> <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'> <p> <p> <label for='q1'>Q1: </label><br> <input type="text" name="q1" value='<?php echo htmlentities($visitor_q1) ?>'> <p> <p> <label for='Gender'>Male: </label> <input type="radio" name="gender" value='<?php echo htmlentities($male) ?>'/> <br /> <label for='Gender'>Female:</label> <input type="radio" name="gender" value='<?php echo htmlentities($female) ?>'/> <br /> </p> <p>I speak the following languages: </p> <p> <input type="checkbox" name="lang" value='<?php echo htmlentities($en) ?>'/> English<br /> <input type="checkbox" name="lang" value='<?php echo htmlentities($fr) ?>'/> Français<br /> <input type="checkbox" name="lang" value='<?php echo htmlentities($es) ?>'/> Español<br /> </p> <p>My preferred language is: </p> <p> <input type="radio" name="pref" value="en" checked> English<br /> <input type="radio" name="pref" value="fr"> Français<br /> <input type="radio" name="pref" value="es"> Español<br /> </p> <p> <label for='message'>Message:</label> <br> <textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea> </p> <p> <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br> <label for='message'>Enter the code above here :</label><br> <input id="6_letters_code" name="6_letters_code" type="text"><br> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p> <input type="submit" value="Submit" name='submit'> </form></i><br> <br> <br> <br> </p> </td> </tr> </table> </td> </tr> <tr> <td><img src="images/pdabase.jpg" width="647" height="48" border="0" usemap="#Map2"></td> </tr> </table> </td> </tr> </table> </CENTER> <map name="Map"><area shape="rect" coords="514,43,633,70" href="richard_fink_iv/voicelessons.htm"> <area shape="rect" coords="514,74,637,96" href="richard_fink_iv/photo.htm"> <area shape="rect" coords="529,101,637,124" href="richard_fink_iv/testimonials.htm"> <area shape="rect" coords="581,128,638,150" href="richard_fink_iv/faq.htm"> <area shape="rect" coords="152,52,462,113" href="richard_fink_iv/mobileindex.html"> </map> <map name="Map2"><area shape="rect" coords="462,7,503,46" href="http://www.facebook.com/pages/Richard-Fink-IV-Vocal-Coach/165219796824660"> <area shape="rect" coords="509,5,550,47" href="http://www.myspace.com/richardfinkiv"> <area shape="rect" coords="558,6,596,48" href="http://www.twitter.com/richardfinkiv"> <area shape="rect" coords="607,6,647,47" href="http://www.youtube.com/richardfinkiv"> </map> <map name="Map3"><area shape="rect" coords="-5,-1,129,67" href="http://www.skype.com"> <area shape="rect" coords="135,1,213,77" href="http://www.apple.com"> </map> <map name="Map4"><area shape="rect" coords="497,16,647,151" href="index.html"> </map> <script language="JavaScript"> // Code for validating the form // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml // for details var frmvalidator = new Validator("contact_form"); //remove the following two lines if you like error message box popups frmvalidator.EnableOnPageErrorDisplaySingleBox(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("name","req","Please provide your name"); frmvalidator.addValidation("email","req","Please provide your email"); frmvalidator.addValidation("email","email","Please enter a valid email address"); </script> <script language='JavaScript' type='text/javascript'> function refreshCaptcha() { var img = document.images['captchaimg']; img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000; } </script> </BODY> </HTML> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 18, 2010 Share Posted October 18, 2010 Just so I understand your thinking, why are you using this: value='<?php echo htmlentities($male) ?>'/> to set a value for the radio buttons and checkboxes? Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 18, 2010 Author Share Posted October 18, 2010 Because I really don't understand how to make the radio buttons work and I was following with the existing code. I think this is where I would need some type of if else statement Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 18, 2010 Share Posted October 18, 2010 OK, that's what I was wondering. There isn't any need to make the value of radio buttons dynamic in this case. Usually that is done so a form field retains its value if the form is submitted (making the form "sticky"). Assuming that's the case here, try making these changes. The value of the gender radio button selection will then be available in $_POST['gender'], and can be dealt with like any other variable. <label for='gender'>Male: </label> <input type="radio" name="Gender" value="male" <?php echo $_POST['gender'] == 'male' ? 'selected="selected"' : ''; ?>/> <br /> <label for='Gender'>Female:</label> <input type="radio" name="Gender" value="female" <?php echo $_POST['gender'] == 'female' ? 'selected="selected"' : ''; ?>/> EDIT: I had a typo in the above that I just corrected . . . Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 18, 2010 Author Share Posted October 18, 2010 Ok I still can't get this to print to the e-mail correctly. Could you please take a look at my code again to see what I am missing? Thank you Result in email A user SMS ME submitted the contact form: Full Name: SMS ME Email: gwhite@dezinezone2002.com Gender: Language: Q1: an answer Message: mn,b IP: 74.74.118.219 Code above header <?php $your_email ='gwhite@dezinezone2002.com';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_q1 = $_POST['q1']; $user_message = $_POST['message']; $gender = $_POST['gender']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "\n The captcha code does not match!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Full Name: $name\n". "Email: $visitor_email \n". "Gender: $male \n". "Language: $lang \n". "Q1: $visitor_q1 \n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); header('Location: thank-you.html'); } } // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?> The Form <form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <p> <label for='name'>Full Name: </label><br> <input type="text" name="name" value='<?php echo htmlentities($name) ?>'> </p> <p> <label for='email'>Email: </label><br> <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'> <p> <p> <label for='q1'>Q1: </label><br> <input type="text" name="q1" value='<?php echo htmlentities($visitor_q1) ?>'> <p> <label for='gender'>Male: </label> <input type="radio" name="Gender" value="male" <?php echo $_POST['gender'] == 'male' ? 'selected="selected"' : ''; ?>/> <br /> <label for='Gender'>Female:</label> <input type="radio" name="Gender" value="female" <?php echo $_POST['gender'] == 'female' ? 'selected="selected"' : ''; ?>/> <p>I speak the following languages: </p> <p> <input type="checkbox" name="lang" value='<?php echo htmlentities($en) ?>'/> English<br /> <input type="checkbox" name="lang" value='<?php echo htmlentities($fr) ?>'/> Français<br /> <input type="checkbox" name="lang" value='<?php echo htmlentities($es) ?>'/> Español<br /> </p> <p>My preferred language is: </p> <p> <input type="radio" name="pref" value="en" checked> English<br /> <input type="radio" name="pref" value="fr"> Français<br /> <input type="radio" name="pref" value="es"> Español<br /> </p> <p> <label for='message'>Message:</label> <br> <textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea> </p> <p> <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br> <label for='message'>Enter the code above here :</label><br> <input id="6_letters_code" name="6_letters_code" type="text"><br> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p> <input type="submit" value="Submit" name='submit'> </form> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 18, 2010 Share Posted October 18, 2010 "Gender: $male \n". should be "Gender: $gender \n". Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 18, 2010 Author Share Posted October 18, 2010 I tried that previously and it still didn't work. I just changed it back again and I still can't get it to print to e-mail Thank you for all the help you have given me so far. I really do appreciate it. Here is the test form I am using http://www.richardiv.com/test2.php A user SMS ME submitted the contact form: Full Name: SMS ME Email: test@testing.com Gender: Language: Q1: an answer Message: gn IP: 74.74.118.219 Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 18, 2010 Author Share Posted October 18, 2010 It Works! I had a capital G instead of lower case in name="gender" <input type="radio" name="gender" value="female" <?php echo $_POST['gender'] == 'female' ? I need to set up the check boxes. Will they get set up the same as the radio buttons except with different values? You can't imagine how much I appreciate all your help. This also gives me some insight on how php works. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2010 Share Posted October 18, 2010 no, you haven't defined $gender. you haven't set it equal to anything. you probably need to do this: $gender = $_POST['Gender']; Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 18, 2010 Author Share Posted October 18, 2010 Radio buttons work great! I'm starting to understand somewhat how this works. I have a 100 hours in something that should take a couple but hopefully I will retain the basic concepts. I tried to incorporate the same code into check boxes but it didn't work. Should it work and I just have something small wrong in the syntax or is it an entirely different type of code I should be using for check boxes? Above head <?php $your_email ='gwhite@dezinezone2002.com';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_q1 = $_POST['q1']; $user_message = $_POST['message']; $gender = $_POST['gender']; $language = $_POST['lang']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "\n The captcha code does not match!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Full Name: $name\n". "Email: $visitor_email \n". "Gender: $gender \n". "Language: $lang \n". "Q1: $visitor_q1 \n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); header('Location: thank-you.html'); } } // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?> In Form <p> <input type="checkbox" name="language" value="en" <?php echo $_POST['lang'] == 'en' ? 'selected="selected"' : ''; ?>/> English<br /> <input type="checkbox" name="language" value="fr" <?php echo $_POST['lang'] == 'fr' ? 'selected="selected"' : ''; ?>/> Français<br /> <input type="checkbox" name="language" value="es" <?php echo $_POST['lang'] == 'es' ? 'selected="selected"' : ''; ?>/> Español<br /> </p> Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 19, 2010 Author Share Posted October 19, 2010 Ok When I choose all 3 English French and Spanish it only returns Spanish I t only returns the last one I choose. Can anyone see where I am missing something to make it choose all the check boxes and print them? Thank you for your help Result A user gary submitted the contact form: Full Name: gary Email: gwhite@dezinezone2002.com Gender: male Language: es Q1: an answer Message: fdsd IP: 74.74.118.219 Above header <?php $your_email ='gwhite@dezinezone2002.com';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_q1 = $_POST['q1']; $user_message = $_POST['message']; $gender = $_POST['gender']; $language = $_POST['lang']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "\n The captcha code does not match!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Full Name: $name\n". "Email: $visitor_email \n". "Gender: $gender \n". "Language: $lang \n". "Q1: $visitor_q1 \n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); header('Location: thank-you.html'); } } // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?> In form <p>I speak the following languages: </p> <p> <input type="checkbox" name="lang" value="en" <?php echo $_POST['lang'] == 'en' ? 'selected="selected"' : ''; ?>/> English<br /> <input type="checkbox" name="lang" value="fr" <?php echo $_POST['lang'] == 'fr' ? 'selected="selected"' : ''; ?>/> Français<br /> <input type="checkbox" name="lang" value="es" <?php echo $_POST['lang'] == 'es' ? 'selected="selected"' : ''; ?>/> Español<br /> </p> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 19, 2010 Share Posted October 19, 2010 You can't name them all the same unless you set them up as an array. name="language[]" then loop through them to display the ones that are checked. Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 19, 2010 Author Share Posted October 19, 2010 I am not familiar with how I would write an array. Could you show me what I need to do or point me in the direction of a good tutorial? Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 19, 2010 Author Share Posted October 19, 2010 Ok Here is my array $lang[] = "English"; $lang[] = "Français"; $lang[] = "Español"; Quote Link to comment Share on other sites More sharing options...
deziner76hd Posted October 19, 2010 Author Share Posted October 19, 2010 Am I headed in the correct direction? <?php echo $_POST[$lang[]] = "English" ? 'selected="selected"' : ''; ?>/ $lang[] = "Français"; $lang[] = "Español"; 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.