hello... Building a website for my local area of NA; & need lots of forms...learned form coding on my own...testing the site on one of my music site servers...my first form is basic, but covers all the info I need returned...(click on the 'GROUP ANNIVERSARY FORM' link...top right): http://www.moonjams.net/events5.html So...When info is entered in all fields; & the SUBMIT button is hit...the info is sent to my e-mail address; & the thank you page pops up. Trouble is, in the e-mail I receive...I'm only getting data from two fields...the 'time' of the anniversary and the 'event description', which are the last two fields. Here is the form page code: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Burlington County Area of NA - Events5</title> <style type="text/css"> <!-- .style6 { font-family: "Garamond Premr Pro Smbd"; font-size: 26px; } .style7 { font-family: "Garamond Premr Pro Smbd"; font-size: 36px; } --> body { background-image: url(SAM_5626-II.jpg); } </style> <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script> </head> <body> <div id="Layer1" style="position:relative; width:840px; height:4000px; margin: 0 auto; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000;"> <div id="Layer3" style="position:absolute; left:0px; top:0px; width:840px; height:132px; z-index:1; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000;"></div> <div id="Layer4" style="position:absolute; left:3px; top:3px; width:194px; height:150px; z-index:1"><img src="John-Woolman-House-II.gif" width="194" height="150"></div> <div id="Layer5" class="style6" style="position:absolute; left:191px; top:12px; width:654px; height:39px; z-index:1">BURLINGTON COUNTY AREA of Narcotics Anonymous </div> <div id="Layer6" class="style7" style="position:absolute; left:172px; top:52px; width:646px; height:44px; z-index:1"> <div align="center">UPCOMING EVENTS</div> </div> <div id="Layer7" style="position:absolute; left:172px; top:106px; width:646px; height:34px; z-index:1"> <div align="center" class="style4"><a href="BurlCoNA-II.htm" class="style4">HOME </a> | <a href="https://www.facebook.com/BCANA-Unity-1417196201831284">UNITY</a> | <a href="asc-docs.htm">ASC DOCS</a> | <a href="contact.htm">CONTACT</a> | <a href="#GroupAnniversaryForm">GROUP ANNIVERSARY FORM</a> </div> </div> <div id="Layer2" style="position:absolute; left:120px; top:160px; width:600px; height:750px; z-index:1; border-style: solid; border-width: 1px"><img src="11thANN002.png" width="600" height="750"></div> <div id="GroupAnniversaryForm" style="position:absolute; left:175px; top:3240px; width:470px; height:530px; z-index:1; border-style: solid; border-width: 1px; padding: 10px"> <h2>Group Anniversary Form: </h2> <form method="post" name="eventsinfoform" action="events-form-to-email.php"> <p> <label for='message'>Home Group Name:</label> <br> <textarea name="message" rows="1" cols="50"></textarea> </p> <p> <label for='message'>Home Group Address:</label> <br> <textarea name="message" rows="1" cols="50"></textarea> </p> <p> <label for='name'># of Years Celebrating: </label> <input type="text" name="name"> </p> <p> <label for='name'>Anniversary Day & Date: </label> <input type="text" name="name"> </p> <p> <label for='name'>Anniversary Time: </label> <input type="text" name="name"> </p> <label for='message'>Briefly Decribe the Event:</label> <br> <textarea name="message" rows="10" cols="50"></textarea><br> <input type="submit" name='submit' value="SUBMIT"> <br><br> Thank you! </form> <script language="JavaScript"> var frmvalidator = new Validator("eventsinfoform"); frmvalidator.addValidation("message","req","Please provide the name of your Home Group"); frmvalidator.addValidation("message","req","Please provide the address of your Home Group"); frmvalidator.addValidation("name","req","Please provide the # of years your Home Group is clebrating"); frmvalidator.addValidation("name","req","Please provide the Day and Date of the event"); frmvalidator.addValidation("name","req","Please provide the Time of the event"); frmvalidator.addValidation("message","req","Please briefly describe the event"); </script> </div> </div> </body> </html> HTML: ...& here's the PHP page: <?php if(!isset($_POST['submit'])) { echo "error; you need to submit the form!"; } $message = $_POST['message']; $message = $_POST['message']; $name = $_POST['name']; $name = $_POST['name']; $name = $_POST['name']; $message = $_POST['message']; if(empty($message)||empty($name)) { echo "Home Group Name and all relative info is mandatory!"; exit; } $email_from = ' '; $email_subject = "Events Page New Form Submission"; $email_body = "You have received Events information from $name.\n". "Here is the message:\n $message". $to = "mark4man@comcast.net"; $headers = "From: $email_from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to,$email_subject,$email_body,$headers); header('Location: thank-you.html'); 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> <html> <head> <meta charset="utf-8"> <title>Events - PHP</title> </head> <body> </body> </html> PHP: can anyone please help?...(I've almost got this)...thanx, mark4man
You're going to kick yourself These fields all have the same "name" <p> <label for='name'># of Years Celebrating: </label> <input type="text" name="name"> </p> <p> <label for='name'>Anniversary Day & Date: </label> <input type="text" name="name"> </p> <p> <label for='name'>Anniversary Time: </label> <input type="text" name="name"> </p> PHP: and then when you process them... sadly computers aren't mind readers, these all need to be different. $name = $_POST['name']; $name = $_POST['name']; $name = $_POST['name']; PHP: I'm betting you've looked through it a million times and just been too close to it all.
sarahk... thanx very much...!!!...& yes, I know. Also, the two message fields have the same names as well. I had thought that may be the problem, so I did try 7 different names (for the 7 different form fields), but it didn't work because...not being a coder...I have no idea which part of the snippet to customize [& the informational I got the code from...(I think it was from LinkedIn) wasn't specific as to how to exactly customize your own fields]. If you could just give me one 'name' example & one 'message' example, I would be eternally grateful. thanx again, mark4man
Also the for="" attribute points at ID's, not names. ID's are for client-side, names are for server side, don't confuse the two. ALSO what in blazes makes a label and input a GRAMMATICAL paragraph? You also seem to be using some form of JavaScripted validation which was NEVER a good idea and we no longer even NEED thanks to HTML 5. NOT that you shouldn't have a server-side scripting off fallback handler in place ANYWAYS given how popular blocking scripting is or how any two-bit script-kiddy can brush that aside. Also that sea of div with static style in the markup is truly terrifying! Don't do that! Oh and your escape sequence checks are redundant. You only really need to be checking for /r and /n... and even the return code for that is silly since: return preg_match($inject,$str)); Code (markup): would be functionally identical in 99% of usage scenarios.
Here's the code: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Burlington County Area of NA - Events5</title> <style type="text/css"> <!-- .style6 { font-family: "Garamond Premr Pro Smbd"; font-size: 26px; } .style7 { font-family: "Garamond Premr Pro Smbd"; font-size: 36px; } --> body { background-image: url(SAM_5626-II.jpg); } </style> <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script> </head> <body> <div id="Layer1" style="position:relative; width:840px; height:4000px; margin: 0 auto; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000;"> <div id="Layer3" style="position:absolute; left:0px; top:0px; width:840px; height:132px; z-index:1; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000;"></div> <div id="Layer4" style="position:absolute; left:3px; top:3px; width:194px; height:150px; z-index:1"><img src="John-Woolman-House-II.gif" width="194" height="150"></div> <div id="Layer5" class="style6" style="position:absolute; left:191px; top:12px; width:654px; height:39px; z-index:1">BURLINGTON COUNTY AREA of Narcotics Anonymous </div> <div id="Layer6" class="style7" style="position:absolute; left:172px; top:52px; width:646px; height:44px; z-index:1"> <div align="center">UPCOMING EVENTS</div> </div> <div id="Layer7" style="position:absolute; left:172px; top:106px; width:646px; height:34px; z-index:1"> <div align="center" class="style4"><a href="BurlCoNA-II.htm" class="style4">HOME </a> | <a href="https://www.facebook.com/BCANA-Unity-1417196201831284">UNITY</a> | <a href="asc-docs.htm">ASC DOCS</a> | <a href="contact.htm">CONTACT</a> | <a href="#GroupAnniversaryForm">GROUP ANNIVERSARY FORM</a> </div> </div> <div id="Layer2" style="position:absolute; left:120px; top:160px; width:600px; height:750px; z-index:1; border-style: solid; border-width: 1px"><img src="11thANN002.png" width="600" height="750"></div> <div id="GroupAnniversaryForm" style="position:absolute; left:175px; top:3240px; width:470px; height:530px; z-index:1; border-style: solid; border-width: 1px; padding: 10px"> <h2>Group Anniversary Form: </h2> <form method="post" name="eventsinfoform" action="events-form-to-email.php"> <p> <label for='message'>Home Group Name:</label> <br> <textarea name="message_home_group_name" rows="1" cols="50"></textarea> </p> <p> <label for='message'>Home Group Address:</label> <br> <textarea name="message_home_group_address" rows="1" cols="50"></textarea> </p> <p> <label for='name'># of Years Celebrating: </label> <input type="text" name="years_celebrating"> </p> <p> <label for='name'>Anniversary Day & Date: </label> <input type="text" name="day_date"> </p> <p> <label for='name'>Anniversary Time: </label> <input type="text" name="time_celebration"> </p> <label for='message'>Briefly Describe the Event:</label> <br> <textarea name="message_event_description" rows="10" cols="50"></textarea><br> <input type="submit" name='submit' value="SUBMIT"> <br><br> Thank you! </form> <script language="JavaScript"> var frmvalidator = new Validator("eventsinfoform"); frmvalidator.addValidation("message","req","Please provide the name of your Home Group"); frmvalidator.addValidation("message","req","Please provide the address of your Home Group"); frmvalidator.addValidation("name","req","Please provide the # of years your Home Group is clebrating"); frmvalidator.addValidation("name","req","Please provide the Day and Date of the event"); frmvalidator.addValidation("name","req","Please provide the Time of the event"); frmvalidator.addValidation("message","req","Please briefly describe the event"); </script> </div> </div> </body> </html> PHP: HTML: ...& here's the PHP page: <?php if(!isset($_POST['submit'])) { echo "error; you need to submit the form!"; exit(); } $message_home_group_name = $_POST["message_home_group_name"]; $message_home_group_address = $_POST["message_home_group_address"]; $years_celebrating = $_POST["years_celebrating"]; $day_date = $_POST["day_date"]; $time_celebration = $_POST["time_celebration"]; $message_event_description = $_POST["message_event_description"]; if(empty( $message_home_group_name )||empty($message_home_group_address )) { echo "Home Group Name and all relative info is mandatory!"; exit; } $email_from = ' '; $email_subject = "Events Page New Form Submission"; $email_body = "You have received Events information from $message_home_group_name.\n".$message_home_group_address."\n". "Celebrating years: ".$years_celebrating ."\n". "Celebrating on: ".$day_date ."\n". "Time of celebration: ".$time_celebration ."\n". "Event description: ".$message_event_description ; $to = "mark4man@comcast.net"; $headers = "From: $email_from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to,$email_subject,$email_body,$headers); header('Location: thank-you.html'); 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> <html> <head> <meta charset="utf-8"> <title>Events - PHP</title> </head> <body> </body> </html> PHP:
I'd suggest don't use this script. You are sending a form submission to "just anyone" in the neighbourhood... any spammer can just enter whatever they like and send it... (automated) Use an image verification at the least, if possible for you. Limit the characters in the "message" boxes.
JEET... THANX so very much...you are wonderful...(haven't tried them yet, but thanx a million anyway...I'm certain they'll work). Also: Are you referring to both the scripts in the head AND body (or...are they the same?)...(&...can I just remove those snippets completely?) thanx again, mark4man
I'm referring to the PHP script. Anyone can just post directly to that PHP code page, completing bypassing your JS checks...
Oh man...thanx but really lost now...if the PHP code (or script as you say) doesn't go on it's own page, where does it go...on the form page? And if so, where? mark4man
JEET...(message 2)... I tried your pages...& they worked...except that...if the form wasn't filled out completely, the echo error wasn't working. So...I looked at the difference between my original and yours; &...after the 1st echo error snippet, you had added: exit;...so as to read: { echo "error; you need to submit the form!"; exit; } PHP: mine didn't have: exit;, so I took it out...& now it works, except for...if you leave info out of any field, it works...but if you leave info out of any field except for the 2nd (Home Group Address), it doesn't work. I suspect it has something to do w/ this snippet: if(empty( $message_home_group_name )||empty($message_home_group_address )) } PHP: not having all the field names? thanx, mark4man
Why not try existing (free) scripts that already have recaptcha / captcha? http://reusableforms.com/d/b/php-contact-form-with-validation-and-recaptcha http://www.vasplus.info/tutorial/105/
SOLVED...I added all the field names to this snippet: if(empty( $message_home_group_name )||empty($message_home_group_address )) } PHP: & it works like a charm. thanx to everyone who helped...JEET & the entire crew...very much appreciated! mark4man