fatmikey Posted February 16, 2009 Share Posted February 16, 2009 I have a HTML page that simplay has a form, collects info from the user then using the Form Action= it calls a PHP script to parse the data collected, write to a file, email results etc. Works great, But.... Now I am going to collect credit card information and I have to change my Form Action to be an external secure website for credit card processing. The problem is, I now don't have any way to run my PHP script to parse the data entered by the user. It just bypasses my PHP and goes straight to the credit card company. Is there a way I can still collect data from a form, parse it using PHP and then send it via Form Action to an external website? Thanks. Quote Link to comment Share on other sites More sharing options...
drisate Posted February 16, 2009 Share Posted February 16, 2009 Yes thats what i was doing for my PayPal ipn script You post your data to a PHP page where you collect your stuff then you send it back to the good place using javascript document.myform.submit();put all your stuff into hidden imput boxes. Quote Link to comment Share on other sites More sharing options...
fatmikey Posted February 16, 2009 Author Share Posted February 16, 2009 I am fairly new to PHP and I need a little more detail in the answer above. I understand to keep my html the same and have it call my PHP, but I need an example in the PHP on how to do a form action using the javascript you mentioned by passing all the correct data. Thanks. Quote Link to comment Share on other sites More sharing options...
limitphp Posted February 16, 2009 Share Posted February 16, 2009 <script> function test(){ //do stuff document.myform.submit(); } </script> <form onSubmit='return false'> <input type='submit' onclick='test()'> </form> Quote Link to comment Share on other sites More sharing options...
drisate Posted February 16, 2009 Share Posted February 16, 2009 <script> function test(){ //do stuff document.myform.submit(); } </script> <form onSubmit='return false'> <input type='submit' onclick='test()'> </form> Nah that would not load on page load it would look a lot more like this <html> <head> <title>Test</title> <?php if($_POST['username'] == NULL){?> <script language="javascript"> function MyFormSubmit(){ document.myname.submit(); } </script> <?php } ?> </head> <body onload="MyFormSubmit()"> <FORM ACTION="http://localhost/test.php" METHOD="POST" name="myname" id="myname"> <INPUT TYPE="HIDDEN" NAME="username" id="username" VALUE="latheesan"> </FORM> </body> </html> Quote Link to comment Share on other sites More sharing options...
fatmikey Posted February 16, 2009 Author Share Posted February 16, 2009 So, does this mean you can mix html code and php code within the same html file? Or does the file have to be php to begin with? I guess I would just add my php code embeded into my html file where my form is then submit afterwards? Thanks again everyone Mikey Quote Link to comment Share on other sites More sharing options...
drisate Posted February 16, 2009 Share Posted February 16, 2009 Of corse you can mixe. You just need to follow 2 rules 1. PHP code must bigin with <?php and finish with ?> 2. The file must use the extention .php You can put any coding outside of <?php and ?> as long as it stuff you would normaly put inside a .htm, html, xml, xhtml, dhtml ... Quote Link to comment Share on other sites More sharing options...
fatmikey Posted February 17, 2009 Author Share Posted February 17, 2009 Sorry for such a newbie question, as you can tell I am new to PHP. This is very good news for me, so just to confirm, I can simply do a copy and paste of all my PHP code and paste it into my html code, here is an example of what I'm doing: <html> <head> <TITLE> <meta name=blah blah blah </head> <body background="images/bg.gif"> . . . <form action="test.php" method="POST" name="regform" id="regform"> <table <tr <td <input name="LastName" type="text" id="LastName5" size="25"> </tr> <input type="submit" name="submit" value="Submit"> </table> . <?php . . (my PHP code goes here) . ?> </body> </html> The only problem now is when I run this php file live it just skips to the end without displaying the form, what am I doing wrong? Thanks, Mikey Quote Link to comment Share on other sites More sharing options...
gevans Posted February 17, 2009 Share Posted February 17, 2009 Show your actual page code. Quote Link to comment Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 Yes as long as your page extention is .php This is what makes PHP so special :-) Quote Link to comment Share on other sites More sharing options...
fatmikey Posted February 17, 2009 Author Share Posted February 17, 2009 Here is the whole page code for mike.php It just jumps to then end and no form is displayed, instead it just displays my error page. Any suggestions on the order? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <TITLE>Ottawa Pole Fitness - Online Registration</TITLE> <meta name="description" content="Ottawa Pole Fitness Online Registration to learn Pole Fitness Lessons"> <meta name="keywords" content="ottawa, pole, fitness, women, private, lessons, tricks, fun, workshops, 1 on 1, excersize, dance, sexy, studio, westboro, woodroofe, carlingwood, workout"> <meta name="Classification" content="fitness, pole, westboro, ottawa, ontario, canada"> <meta name="copyright" content="2008 | Li Hewitt - All Rights Reserved"> <meta name="revisit-after" content="30 days"> <meta name="Author" content="Li Hewitt"> <meta name="Location" content="CA, ON, Ottawa"> <meta name="Language" content="en-us"> <meta name="robots" content="all"> <meta name="rating" content="General"> <meta http-equiv="reply-to" content="info@ottawapolefitness.com"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="css/OPF-style.css" rel="stylesheet" type="text/css"> </head> <body background="images/bg.gif"> <div align="center"><img src="images/Ottawa%20Pole%20Fitness%20Banner.gif" alt="Ottawa Pole Fitness" width="632" height="180" border="0"></div> <table width="630" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#990066"> <tr valign="bottom" bordercolor="#FFFFFF"> <td width="130" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="index.htm" target="_self" class="font-menu- active">Home</a></div></td> <td width="112" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="about.htm" target="_self" class="font-menu- active">About</a></div></td> <td width="105" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="classes.htm" target="_self" class="font-menu- active">Classes</a></div></td> <td width="130" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="schedule.htm" target="_self" class="font-menu- active">Schedule</a></div></td> <td width="153" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="contact.htm" target="_self" class="font-menu- active">Contact</a></div></td> </tr> <tr valign="bottom" bordercolor="#FFFFFF"> <td height="10" colspan="5" bgcolor="#FFFFFF"><div align="center"><img src="images/line.gif" width="628" height="2"></div></td> </tr> <tr bordercolor="#FFFFFF"> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="faq.htm" target="_self" class="font-menu-active">FAQ</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="gallery.htm" target="_self" class="font-menu-active">Gallery</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="parties.htm" target="_self" class="font-menu-active">Parties</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="prices.htm" target="_self" class="font-menu-active">Prices</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center" class="font-menu-static">Registration</div></td> </tr> <tr valign="middle" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="10" colspan="5"> <p align="center"><img src="images/line.gif" width="628" height="2" align="absmiddle"></p></td> </tr> <tr valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="420" colspan="5"> <blockquote> <p><br> <span class="font-norm-grey">If you would like to take a class please complete the form below. </span><span class="font-small-grey"><em>[Fields marked (</em></span><span class="font-norm-pink"><em>*</em></span><span class="font-small-grey"><em>) are required]. </em></span><span class="font-norm-grey">You can make your payment at your first class. We accept payment by cash or cheque payable to Ottawa Pole Fitness Inc.</span> <form action="registration.php" method="POST" name="regform" id="regform"> <table width="505" border="0" align="center"> <tr class="font-norm-grey"> <td width="157"> <p>First Name:<span class="font-norm-pink">* </span><br> <input name="FirstName" type="text" id="FirstName2" size="21"> <br> </p></td> <td width="181">Last Name:<span class="font-norm-pink">*</span> <br> <input name="LastName" type="text" id="LastName5" size="25"> </td> <td width="153" valign="top">Telephone:<span class="font-norm-pink">*</span><br> <input name="Telephone" type="text" id="Telephone5" size="12"> </td> </tr> <tr class="font-norm-grey"> <td>E-mail address:<span class="font-norm-pink">*</span> <br> <input name="Email" type="text" id="Email8" size="21"> </td> <td colspan="2"> Address:<br> <input name="Address" type="text" id="Address3" size="48"> </td> </tr> <tr class="font-norm-grey"> <td>Province:<br> <select name="Province" size="1" id="select"> <option>Ontario</option> <option>Quebec</option> <option>Alberta</option> <option>British Columbia</option> <option>Manitoba</option> <option>New Brunswick</option> <option>Newfoundland</option> <option>Northwest Territories</option> <option>Nunavut</option> <option>Nova Scotia</option> <option>Prince Edward Island</option> <option>Saskatchewan</option> <option>Yukon</option> </select> </td> <td>City:<br> <input name="City" type="text" id="City3" value="Ottawa" size="25"> </td> <td width="153" valign="top">Postal Code:<br> <input name="PostalCode" type="text" id="PostalCode2" size="10"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2"> </td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2">Select a class from the list below:<br> </td> <td width="153" valign="top"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2"><select name="Class" id="select2"> <option>Level 1 Thu Feb 19 (8:30pm) </option> <option>Level 1 Tues Mar 10 (6:30pm) </option> <option>Level 1 Tues Mar 10 (8:30pm) </option> <option>Level 1 Wed Mar 11 (7:30pm) </option> <option>Level 1 Thu Mar 12 (6:30pm) </option> <option>Level 1 Sat Mar 14 (1:30pm) </option> <option>Private Lesson (to be arranged)</option> <option>Semi-Private Group 2-3 participants (to be arranged)</option> <option>Semi-Private Group 4-6 participants (to be arranged)</option> <option>Redeem Gift Certificate (to be arranged)</option> </select> <br> </td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2">How did you hear about us? </td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2"><select name="How" id="select3"> <option>Web Search</option> <option>Sexapolooza</option> <option>Business Card</option> <option>Facebook</option> <option>Friend</option> <option>Email</option> <option>Other</option> </select></td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2">Additional Comments/Special Requests:</td> <td width="153"> </td> </tr> <tr> <td colspan="3"> <input name="Comments" type="text" id="Comments" size="75"> </td> </tr> </table> <p align="center"><span class="font-small-grey-centered"> </span> <input type="submit" name="submit" value="Submit"> </p> </form> <p class="font-small-grey-centered">Your privacy is important to us at Ottawa Pole Fitness. The information we collect is for our own purposes only and will not be given to anyone else. We use this information to keep a personal confidential file for everyone who registers with Ottawa Pole Fitness. We hate spam just as much as you do; this is why we will not distribute your information to anyone. If you have any concerns regarding our policy please contact us. <p class="font-small-grey-centered"><br> </blockquote></td> </tr> </table> <div align="center"><img src="images/Ottawa%20Pole%20Fitness%20Footer.gif" width="632" height="36"> </div> <?php // get posted data into local variables $Email = Trim(stripslashes($_POST['Email'])); $To = "register@ottawapolefitness.com\r\n"; $Subject = "Registration"; $Subject2 = "Registration Confirmation"; $FirstName = ucwords(Trim(stripslashes($_POST['FirstName']))); $LastName = ucwords(Trim(stripslashes($_POST['LastName']))); $Telephone = Trim(stripslashes($_POST['Telephone'])); $Address = Trim(stripslashes($_POST['Address'])); $City = Trim(stripslashes($_POST['City'])); $Province = ($_POST['Province']); $PostalCode = strtoupper(Trim(stripslashes($_POST['PostalCode']))); $PostalCode = ereg_replace("[^A-Za-z0-9]", "", $PostalCode); $PostalCode = substr($PostalCode,0,3) ." ". substr($PostalCode,3,3); $Class = ($_POST['Class']); $Level = ($_POST['Level']); $Date = ($_POST['Date']); $Time = Trim(stripslashes($_POST['Time'])); $How = Trim(stripslashes($_POST['How'])); $Comments = Trim(stripslashes($_POST['Comments'])); $Headers = "From: " . $FirstName . " " . $LastName . " <" . $Email . ">\r\n"; $Headers .= "Bcc: hewittm@gmail.com"; $Headers2 = "From: " . "Ottawa Pole Fitness <info@ottawapolefitness.com>\r\n"; $Daytime = time (); $File = "./meth/reglog.csv"; // validation $validationOK=true; if (Trim($FirstName)=="") { print "<meta http-equiv=\"refresh\" content=\"0;URL=err-name.htm\">"; exit; } else { $validationOK=true; } if (Trim($LastName)=="") { print "<meta http-equiv=\"refresh\" content=\"0;URL=err-last.htm\">"; exit; } else { $validationOK=true; } if (Trim($Email)=="") { print "<meta http-equiv=\"refresh\" content=\"0;URL=err-email.htm\">"; exit; } else { $validationOK=true;; } if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $Email)) { print "<meta http-equiv=\"refresh\" content=\"0;URL=err-email.htm\">"; exit; } else { $validationOK=true; } if (strlen($Telephone) < 10) { print "<meta http-equiv=\"refresh\" content=\"0;URL=err-tele.htm\">"; exit; } else { $validationOK=true; } if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // This code will strip out any commas and replace them with a space for the address and comments fields. function commasplit ($name) { $v1 = explode (",", $name) ; $name = "" ; foreach ($v1 as $t) { $name .= $t ; } return $name ; } $Address = commasplit($Address) ; $Comments = commasplit($Comments) ; // This code will format the telephone number of 555-555-5555 function phone_number($sPhone){ $sPhone = ereg_replace("[^0-9]",'',$sPhone); if(strlen($sPhone) != 10) return(False); $sArea = substr($sPhone,0,3); $sPrefix = substr($sPhone,3,3); $sNumber = substr($sPhone,6,4); $sPhone = $sArea."-".$sPrefix."-".$sNumber; return($sPhone); } $Telephone = phone_number($Telephone); // prepare email body text $Body = ""; $Body .= "Date: "; $Body .= date("d/m/Y",$Daytime); $Body .= "\n"; $Body .= "Time: "; $Body .= date("H:i",$Daytime); $Body .= "\n"; $Body .= "Name: " . $FirstName . " " . $LastName . "\n"; $Body .= "Telephone: "; $Body .= $Telephone; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Address: "; $Body .= $Address; $Body .= "\n"; $Body .= "City: "; $Body .= $City; $Body .= "\n"; $Body .= "Province: "; $Body .= $Province; $Body .= "\n"; $Body .= "PostalCode: "; $Body .= $PostalCode; $Body .= "\n"; $Body .= "Class: "; $Body .= $Class; $Body .= "\n"; $Body .= "How: "; $Body .= $How; $Body .= "\n"; $Body .= "Comments: "; $Body .= $Comments; $Body .= "\n"; // prepare email body text for confirmation $Msg = "Hi " . $FirstName . ","; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "Thank you for registering with Ottawa Pole Fitness. "; $Msg .= "A spot has now been confirmed for you to take a class. "; $Msg .= "You have selected " . $Class . ". "; $Msg .= "Remember to download complete a waiver http://ottawapolefitness.com/docs/Waiver.pdf "; $Msg .= "and bring it with you to your first class along with your payment. "; $Msg .= "We only accept cash or cheque payable to Ottawa Pole Fitness Inc. GST is included in all our prices. "; $Msg .= "We are located at 1066 Somerset St. W. at the intersection of Bayswater St. suite B-101 in the lower level. "; $Msg .= "Just take the elevator down one level. Be sure to bring a Yoga mat to class and "; $Msg .= "please arrive 5-10 minutes early to process your registration and payment."; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "I look forward to seeing you and have a great day!"; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "Li Hewitt"; $Msg .= "\n"; $Msg .= "613-371-3342"; $Msg .= "\n"; $Msg .= "www.ottawapolefitness.com"; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "[this is an automated confirmation email generated on " . date("d/m/Y",$Daytime) . "]"; // record registrations to a file $Handle = fopen($File, 'a'); $Data = date("d/m/Y",$Daytime) . ", "; $Data .= date("H:i",$Daytime) . ", "; $Data .= $FirstName . ", "; $Data .= $LastName . ", "; $Data .= $Telephone . ", "; $Data .= $Email . ", "; $Data .= $Address . ", "; $Data .= $City . ", "; $Data .= $Province . ", "; $Data .= $PostalCode . ", "; $Data .= $Class . ", "; $Data .= $How . "\n"; fwrite($Handle, $Data); fclose($Handle); if (mail($To, $Subject, $Body, $Headers)) { print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.htm\">"; } else { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } mail($Email, $Subject2, $Msg, $Headers2) ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 Hmm this is bad coding bro hehe You don't need to make an error page for every errors. Give me a few min and i will recode all of it hehe Quote Link to comment Share on other sites More sharing options...
fatmikey Posted February 17, 2009 Author Share Posted February 17, 2009 Ya I know, I'm open to any comments, I know it's bad coding but it works and I learned as I went. I only hope to aspire to the heights of you guys some day. I really appreciate your help. Mikey Quote Link to comment Share on other sites More sharing options...
fatmikey Posted February 17, 2009 Author Share Posted February 17, 2009 I have to change to form action to be my credit card company secure website to pass the form data to them once I've done my bit with the data by recording the data and sending emails etc. then I will pass it to the credit card company. Quote Link to comment Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 <?php if ($_POST){ // get posted data into local variables $Email = Trim(stripslashes($_POST['Email'])); $To = "register@ottawapolefitness.com\r\n"; $Subject = "Registration"; $Subject2 = "Registration Confirmation"; $FirstName = ucwords(Trim(stripslashes($_POST['FirstName']))); $LastName = ucwords(Trim(stripslashes($_POST['LastName']))); $Telephone = Trim(stripslashes($_POST['Telephone'])); $Address = Trim(stripslashes($_POST['Address'])); $City = Trim(stripslashes($_POST['City'])); $Province = ($_POST['Province']); $PostalCode = strtoupper(Trim(stripslashes($_POST['PostalCode']))); $PostalCode = ereg_replace("[^A-Za-z0-9]", "", $PostalCode); $PostalCode = substr($PostalCode,0,3) ." ". substr($PostalCode,3,3); $Class = ($_POST['Class']); $Level = ($_POST['Level']); $Date = ($_POST['Date']); $Time = Trim(stripslashes($_POST['Time'])); $How = Trim(stripslashes($_POST['How'])); $Comments = Trim(stripslashes($_POST['Comments'])); $Headers = "From: " . $FirstName . " " . $LastName . " <" . $Email . ">\r\n"; $Headers .= "Bcc: hewittm@gmail.com"; $Headers2 = "From: " . "Ottawa Pole Fitness <info@ottawapolefitness.com>\r\n"; $Daytime = time (); $File = "./meth/reglog.csv"; // validation $validationOK=true; if (Trim($FirstName)=="") {$error = $error."Your name is empty<br>";} if (Trim($LastName)=="") {$error = $error."Your last name is empty<br>";} if (Trim($Email)=="") {$error = $error."Your email is empty<br>";}else{ if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $Email)) {$error = $error."Your email is invalide<br>";}} if (strlen($Telephone) < 10) {$error = $error."Your telephone is empty<br>";} if (!$validationOK) {$error = $error."Please check the boxe!<br>";} } if ($error == ""){ // This code will strip out any commas and replace them with a space for the address and comments fields. function commasplit ($name) { $v1 = explode (",", $name) ; $name = "" ; foreach ($v1 as $t) { $name .= $t ; } return $name ; } $Address = commasplit($Address) ; $Comments = commasplit($Comments) ; // This code will format the telephone number of 555-555-5555 function phone_number($sPhone){ $sPhone = ereg_replace("[^0-9]",'',$sPhone); if(strlen($sPhone) != 10) return(False); $sArea = substr($sPhone,0,3); $sPrefix = substr($sPhone,3,3); $sNumber = substr($sPhone,6,4); $sPhone = $sArea."-".$sPrefix."-".$sNumber; return($sPhone); } $Telephone = phone_number($Telephone); // prepare email body text $Body = ""; $Body .= "Date: "; $Body .= date("d/m/Y",$Daytime); $Body .= "\n"; $Body .= "Time: "; $Body .= date("H:i",$Daytime); $Body .= "\n"; $Body .= "Name: " . $FirstName . " " . $LastName . "\n"; $Body .= "Telephone: "; $Body .= $Telephone; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Address: "; $Body .= $Address; $Body .= "\n"; $Body .= "City: "; $Body .= $City; $Body .= "\n"; $Body .= "Province: "; $Body .= $Province; $Body .= "\n"; $Body .= "PostalCode: "; $Body .= $PostalCode; $Body .= "\n"; $Body .= "Class: "; $Body .= $Class; $Body .= "\n"; $Body .= "How: "; $Body .= $How; $Body .= "\n"; $Body .= "Comments: "; $Body .= $Comments; $Body .= "\n"; // prepare email body text for confirmation $Msg = "Hi " . $FirstName . ","; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "Thank you for registering with Ottawa Pole Fitness. "; $Msg .= "A spot has now been confirmed for you to take a class. "; $Msg .= "You have selected " . $Class . ". "; $Msg .= "Remember to download complete a waiver http://ottawapolefitness.com/docs/Waiver.pdf "; $Msg .= "and bring it with you to your first class along with your payment. "; $Msg .= "We only accept cash or cheque payable to Ottawa Pole Fitness Inc. GST is included in all our prices. "; $Msg .= "We are located at 1066 Somerset St. W. at the intersection of Bayswater St. suite B-101 in the lower level. "; $Msg .= "Just take the elevator down one level. Be sure to bring a Yoga mat to class and "; $Msg .= "please arrive 5-10 minutes early to process your registration and payment."; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "I look forward to seeing you and have a great day!"; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "Li Hewitt"; $Msg .= "\n"; $Msg .= "613-371-3342"; $Msg .= "\n"; $Msg .= "www.ottawapolefitness.com"; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "[this is an automated confirmation email generated on " . date("d/m/Y",$Daytime) . "]"; // record registrations to a file $Handle = fopen($File, 'a'); $Data = date("d/m/Y",$Daytime) . ", "; $Data .= date("H:i",$Daytime) . ", "; $Data .= $FirstName . ", "; $Data .= $LastName . ", "; $Data .= $Telephone . ", "; $Data .= $Email . ", "; $Data .= $Address . ", "; $Data .= $City . ", "; $Data .= $Province . ", "; $Data .= $PostalCode . ", "; $Data .= $Class . ", "; $Data .= $How . "\n"; fwrite($Handle, $Data); fclose($Handle); if (mail($To, $Subject, $Body, $Headers)) { print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.htm\">"; } else { $error = $error."There has been an error sending out your data!<br>"; mail($Email, $Subject2, $Msg, $Headers2); } } // The form function form($error){ print (' <form action="registration.php" method="POST" name="regform" id="regform">'); if ($error!=""){ print (' <table width="505" border="0" align="center"> <tr class="font-norm-grey"> <td width="491">'.$error.'</td> </tr> </table>'); } print (' <table width="505" border="0" align="center"> <tr class="font-norm-grey"> <td>E-mail address:<span class="font-norm-pink">*</span> <br> <input name="Email" type="text" id="Email8" size="21"> </td> <td colspan="2"> Address:<br> <input name="Address" type="text" id="Address3" size="48"> </td> </tr> <tr class="font-norm-grey"> <td>Province:<br> <select name="Province" size="1" id="select"> <option>Ontario</option> <option>Quebec</option> <option>Alberta</option> <option>British Columbia</option> <option>Manitoba</option> <option>New Brunswick</option> <option>Newfoundland</option> <option>Northwest Territories</option> <option>Nunavut</option> <option>Nova Scotia</option> <option>Prince Edward Island</option> <option>Saskatchewan</option> <option>Yukon</option> </select> </td> <td>City:<br> <input name="City" type="text" id="City3" value="Ottawa" size="25"> </td> <td width="153" valign="top">Postal Code:<br> <input name="PostalCode" type="text" id="PostalCode2" size="10"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2"> </td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2">Select a class from the list below:<br> </td> <td width="153" valign="top"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2"><select name="Class" id="select2"> <option>Level 1 Thu Feb 19 (8:30pm) </option> <option>Level 1 Tues Mar 10 (6:30pm) </option> <option>Level 1 Tues Mar 10 (8:30pm) </option> <option>Level 1 Wed Mar 11 (7:30pm) </option> <option>Level 1 Thu Mar 12 (6:30pm) </option> <option>Level 1 Sat Mar 14 (1:30pm) </option> <option>Private Lesson (to be arranged)</option> <option>Semi-Private Group 2-3 participants (to be arranged)</option> <option>Semi-Private Group 4-6 participants (to be arranged)</option> <option>Redeem Gift Certificate (to be arranged)</option> </select> <br> </td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2">How did you hear about us? </td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2"><select name="How" id="select3"> <option>Web Search</option> <option>Sexapolooza</option> <option>Business Card</option> <option>Facebook</option> <option>Friend</option> <option>Email</option> <option>Other</option> </select></td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2">Additional Comments/Special Requests:</td> <td width="153"> </td> </tr> <tr> <td colspan="3"> <input name="Comments" type="text" id="Comments" size="75"> </td> </tr> </table> <p align="center"><span class="font-small-grey-centered"> </span> <input type="submit" name="submit" value="Submit"> </p> </form>'); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <TITLE>Ottawa Pole Fitness - Online Registration</TITLE> <meta name="description" content="Ottawa Pole Fitness Online Registration to learn Pole Fitness Lessons"> <meta name="keywords" content="ottawa, pole, fitness, women, private, lessons, tricks, fun, workshops, 1 on 1, excersize, dance, sexy, studio, westboro, woodroofe, carlingwood, workout"> <meta name="Classification" content="fitness, pole, westboro, ottawa, ontario, canada"> <meta name="copyright" content="2008 | Li Hewitt - All Rights Reserved"> <meta name="revisit-after" content="30 days"> <meta name="Author" content="Li Hewitt"> <meta name="Location" content="CA, ON, Ottawa"> <meta name="Language" content="en-us"> <meta name="robots" content="all"> <meta name="rating" content="General"> <meta http-equiv="reply-to" content="info@ottawapolefitness.com"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="css/OPF-style.css" rel="stylesheet" type="text/css"> </head> <body background="images/bg.gif"> <div align="center"><img src="images/Ottawa%20Pole%20Fitness%20Banner.gif" alt="Ottawa Pole Fitness" width="632" height="180" border="0"></div> <table width="630" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#990066"> <tr valign="bottom" bordercolor="#FFFFFF"> <td width="130" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="index.htm" target="_self" class="font-menu- active">Home</a></div></td> <td width="112" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="about.htm" target="_self" class="font-menu- active">About</a></div></td> <td width="105" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="classes.htm" target="_self" class="font-menu- active">Classes</a></div></td> <td width="130" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="schedule.htm" target="_self" class="font-menu- active">Schedule</a></div></td> <td width="153" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="contact.htm" target="_self" class="font-menu- active">Contact</a></div></td> </tr> <tr valign="bottom" bordercolor="#FFFFFF"> <td height="10" colspan="5" bgcolor="#FFFFFF"><div align="center"><img src="images/line.gif" width="628" height="2"></div></td> </tr> <tr bordercolor="#FFFFFF"> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="faq.htm" target="_self" class="font-menu-active"> FAQ</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="gallery.htm" target="_self" class="font-menu-active"> Gallery</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="parties.htm" target="_self" class="font-menu-active"> Parties</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="prices.htm" target="_self" class="font-menu-active"> Prices</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center" class="font-menu-static"> Registration</div></td> </tr> <tr valign="middle" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="10" colspan="5"> <p align="center"><img src="images/line.gif" width="628" height="2" align="absmiddle"></p></td> </tr> <tr valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="420" colspan="5"> <blockquote> <p><br> <span class="font-norm-grey">If you would like to take a class please complete the form below. </span><span class="font-small-grey"><em> [Fields marked (</em></span><span class="font-norm-pink"><em>*</em></span><span class="font-small-grey"><em>) are required]. </em></span><span class="font-norm-grey">You can make your payment at your first class. We accept payment by cash or cheque payable to Ottawa Pole Fitness Inc.</span> <?php echo form($error); ?> <p class="font-small-grey-centered">Your privacy is important to us at Ottawa Pole Fitness. The information we collect is for our own purposes only and will not be given to anyone else. We use this information to keep a personal confidential file for everyone who registers with Ottawa Pole Fitness. We hate spam just as much as you do; this is why we will not distribute your information to anyone. If you have any concerns regarding our policy please contact us. <p class="font-small-grey-centered"><br> </blockquote></td> </tr> </table> <div align="center"><img src="images/Ottawa%20Pole%20Fitness%20Footer.gif" width="632" height="36"> </div> </body> </html> i did not test the code so there might be small errors... try it out and repport them to me in this topic Quote Link to comment Share on other sites More sharing options...
fatmikey Posted February 17, 2009 Author Share Posted February 17, 2009 Wow, thanks drisate. I tested the code and it errored off and cleared the page, so I had to comment out the thankyou page so I can see the error, this is what is displayed: Warning: fwrite(): supplied argument is not a valid stream resource in /home/content/h/e/w/hewittme/html/test/test.php on line 146 Warning: fclose(): supplied argument is not a valid stream resource in /home/content/h/e/w/hewittme/html/test/test.php on line 147 No recipient addresses found in header Just curious, the form looks a lot smaller, did you by chance remove some fields just to show me the example? No problem, I can add then back in just asking. I now have the form asking for input so I will test it now. Thanks. Quote Link to comment Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 try this <?php if ($_POST){ // get posted data into local variables $Email = Trim(stripslashes($_POST['Email'])); $To = "register@ottawapolefitness.com\r\n"; $Subject = "Registration"; $Subject2 = "Registration Confirmation"; $FirstName = ucwords(Trim(stripslashes($_POST['FirstName']))); $LastName = ucwords(Trim(stripslashes($_POST['LastName']))); $Telephone = Trim(stripslashes($_POST['Telephone'])); $Address = Trim(stripslashes($_POST['Address'])); $City = Trim(stripslashes($_POST['City'])); $Province = ($_POST['Province']); $PostalCode = strtoupper(Trim(stripslashes($_POST['PostalCode']))); $PostalCode = ereg_replace("[^A-Za-z0-9]", "", $PostalCode); $PostalCode = substr($PostalCode,0,3) ." ". substr($PostalCode,3,3); $Class = ($_POST['Class']); $Level = ($_POST['Level']); $Date = ($_POST['Date']); $Time = Trim(stripslashes($_POST['Time'])); $How = Trim(stripslashes($_POST['How'])); $Comments = Trim(stripslashes($_POST['Comments'])); $Headers = "From: " . $FirstName . " " . $LastName . " <" . $Email . ">\r\n"; $Headers .= "Bcc: hewittm@gmail.com"; $Headers2 = "From: " . "Ottawa Pole Fitness <info@ottawapolefitness.com>\r\n"; $Daytime = time (); $File = "./meth/reglog.csv"; // validation $validationOK=true; if (Trim($FirstName)=="") {$error = $error."Your name is empty<br>";} if (Trim($LastName)=="") {$error = $error."Your last name is empty<br>";} if (Trim($Email)=="") {$error = $error."Your email is empty<br>";}else{ if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $Email)) {$error = $error."Your email is invalide<br>";}} if (strlen($Telephone) < 10) {$error = $error."Your telephone is empty<br>";} if (!$validationOK) {$error = $error."Please check the boxe!<br>";} if ($error == ""){ // This code will strip out any commas and replace them with a space for the address and comments fields. function commasplit ($name) { $v1 = explode (",", $name) ; $name = "" ; foreach ($v1 as $t) { $name .= $t ; } return $name ; } $Address = commasplit($Address) ; $Comments = commasplit($Comments) ; // This code will format the telephone number of 555-555-5555 function phone_number($sPhone){ $sPhone = ereg_replace("[^0-9]",'',$sPhone); if(strlen($sPhone) != 10) return(False); $sArea = substr($sPhone,0,3); $sPrefix = substr($sPhone,3,3); $sNumber = substr($sPhone,6,4); $sPhone = $sArea."-".$sPrefix."-".$sNumber; return($sPhone); } $Telephone = phone_number($Telephone); // prepare email body text $Body = ""; $Body .= "Date: "; $Body .= date("d/m/Y",$Daytime); $Body .= "\n"; $Body .= "Time: "; $Body .= date("H:i",$Daytime); $Body .= "\n"; $Body .= "Name: " . $FirstName . " " . $LastName . "\n"; $Body .= "Telephone: "; $Body .= $Telephone; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Address: "; $Body .= $Address; $Body .= "\n"; $Body .= "City: "; $Body .= $City; $Body .= "\n"; $Body .= "Province: "; $Body .= $Province; $Body .= "\n"; $Body .= "PostalCode: "; $Body .= $PostalCode; $Body .= "\n"; $Body .= "Class: "; $Body .= $Class; $Body .= "\n"; $Body .= "How: "; $Body .= $How; $Body .= "\n"; $Body .= "Comments: "; $Body .= $Comments; $Body .= "\n"; // prepare email body text for confirmation $Msg = "Hi " . $FirstName . ","; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "Thank you for registering with Ottawa Pole Fitness. "; $Msg .= "A spot has now been confirmed for you to take a class. "; $Msg .= "You have selected " . $Class . ". "; $Msg .= "Remember to download complete a waiver http://ottawapolefitness.com/docs/Waiver.pdf "; $Msg .= "and bring it with you to your first class along with your payment. "; $Msg .= "We only accept cash or cheque payable to Ottawa Pole Fitness Inc. GST is included in all our prices. "; $Msg .= "We are located at 1066 Somerset St. W. at the intersection of Bayswater St. suite B-101 in the lower level. "; $Msg .= "Just take the elevator down one level. Be sure to bring a Yoga mat to class and "; $Msg .= "please arrive 5-10 minutes early to process your registration and payment."; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "I look forward to seeing you and have a great day!"; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "Li Hewitt"; $Msg .= "\n"; $Msg .= "613-371-3342"; $Msg .= "\n"; $Msg .= "www.ottawapolefitness.com"; $Msg .= "\n"; $Msg .= "\n"; $Msg .= "[this is an automated confirmation email generated on " . date("d/m/Y",$Daytime) . "]"; // record registrations to a file $Handle = fopen($File, 'a'); $Data = date("d/m/Y",$Daytime) . ", "; $Data .= date("H:i",$Daytime) . ", "; $Data .= $FirstName . ", "; $Data .= $LastName . ", "; $Data .= $Telephone . ", "; $Data .= $Email . ", "; $Data .= $Address . ", "; $Data .= $City . ", "; $Data .= $Province . ", "; $Data .= $PostalCode . ", "; $Data .= $Class . ", "; $Data .= $How . "\n"; fwrite($Handle, $Data); fclose($Handle); if (mail($To, $Subject, $Body, $Headers)) { print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.htm\">"; } else { $error = $error."There has been an error sending out your data!<br>"; mail($Email, $Subject2, $Msg, $Headers2); } } } // The form function form($error){ print (' <form action="registration.php" method="POST" name="regform" id="regform">'); if ($error!=""){ print (' <table width="505" border="0" align="center"> <tr class="font-norm-grey"> <td width="491">'.$error.'</td> </tr> </table>'); } print (' <table width="505" border="0" align="center"> <tr class="font-norm-grey"> <td>E-mail address:<span class="font-norm-pink">*</span> <br> <input name="Email" type="text" id="Email8" size="21"> </td> <td colspan="2"> Address:<br> <input name="Address" type="text" id="Address3" size="48"> </td> </tr> <tr class="font-norm-grey"> <td>Province:<br> <select name="Province" size="1" id="select"> <option>Ontario</option> <option>Quebec</option> <option>Alberta</option> <option>British Columbia</option> <option>Manitoba</option> <option>New Brunswick</option> <option>Newfoundland</option> <option>Northwest Territories</option> <option>Nunavut</option> <option>Nova Scotia</option> <option>Prince Edward Island</option> <option>Saskatchewan</option> <option>Yukon</option> </select> </td> <td>City:<br> <input name="City" type="text" id="City3" value="Ottawa" size="25"> </td> <td width="153" valign="top">Postal Code:<br> <input name="PostalCode" type="text" id="PostalCode2" size="10"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2"> </td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2">Select a class from the list below:<br> </td> <td width="153" valign="top"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2"><select name="Class" id="select2"> <option>Level 1 Thu Feb 19 (8:30pm) </option> <option>Level 1 Tues Mar 10 (6:30pm) </option> <option>Level 1 Tues Mar 10 (8:30pm) </option> <option>Level 1 Wed Mar 11 (7:30pm) </option> <option>Level 1 Thu Mar 12 (6:30pm) </option> <option>Level 1 Sat Mar 14 (1:30pm) </option> <option>Private Lesson (to be arranged)</option> <option>Semi-Private Group 2-3 participants (to be arranged)</option> <option>Semi-Private Group 4-6 participants (to be arranged)</option> <option>Redeem Gift Certificate (to be arranged)</option> </select> <br> </td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2">How did you hear about us? </td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2"><select name="How" id="select3"> <option>Web Search</option> <option>Sexapolooza</option> <option>Business Card</option> <option>Facebook</option> <option>Friend</option> <option>Email</option> <option>Other</option> </select></td> <td width="153"> </td> </tr> <tr class="font-norm-grey"> <td colspan="2">Additional Comments/Special Requests:</td> <td width="153"> </td> </tr> <tr> <td colspan="3"> <input name="Comments" type="text" id="Comments" size="75"> </td> </tr> </table> <p align="center"><span class="font-small-grey-centered"> </span> <input type="submit" name="submit" value="Submit"> </p> </form>'); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <TITLE>Ottawa Pole Fitness - Online Registration</TITLE> <meta name="description" content="Ottawa Pole Fitness Online Registration to learn Pole Fitness Lessons"> <meta name="keywords" content="ottawa, pole, fitness, women, private, lessons, tricks, fun, workshops, 1 on 1, excersize, dance, sexy, studio, westboro, woodroofe, carlingwood, workout"> <meta name="Classification" content="fitness, pole, westboro, ottawa, ontario, canada"> <meta name="copyright" content="2008 | Li Hewitt - All Rights Reserved"> <meta name="revisit-after" content="30 days"> <meta name="Author" content="Li Hewitt"> <meta name="Location" content="CA, ON, Ottawa"> <meta name="Language" content="en-us"> <meta name="robots" content="all"> <meta name="rating" content="General"> <meta http-equiv="reply-to" content="info@ottawapolefitness.com"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="css/OPF-style.css" rel="stylesheet" type="text/css"> </head> <body background="images/bg.gif"> <div align="center"><img src="images/Ottawa%20Pole%20Fitness%20Banner.gif" alt="Ottawa Pole Fitness" width="632" height="180" border="0"></div> <table width="630" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#990066"> <tr valign="bottom" bordercolor="#FFFFFF"> <td width="130" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="index.htm" target="_self" class="font-menu- active">Home</a></div></td> <td width="112" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="about.htm" target="_self" class="font-menu- active">About</a></div></td> <td width="105" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="classes.htm" target="_self" class="font-menu- active">Classes</a></div></td> <td width="130" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="schedule.htm" target="_self" class="font-menu- active">Schedule</a></div></td> <td width="153" height="23" bgcolor="#FFFFFF"> <div align="center"><a href="contact.htm" target="_self" class="font-menu- active">Contact</a></div></td> </tr> <tr valign="bottom" bordercolor="#FFFFFF"> <td height="10" colspan="5" bgcolor="#FFFFFF"><div align="center"><img src="images/line.gif" width="628" height="2"></div></td> </tr> <tr bordercolor="#FFFFFF"> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="faq.htm" target="_self" class="font-menu-active"> FAQ</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="gallery.htm" target="_self" class="font-menu-active"> Gallery</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="parties.htm" target="_self" class="font-menu-active"> Parties</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center"><a href="prices.htm" target="_self" class="font-menu-active"> Prices</a></div></td> <td height="20" bgcolor="#FFFFFF"> <div align="center" class="font-menu-static"> Registration</div></td> </tr> <tr valign="middle" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="10" colspan="5"> <p align="center"><img src="images/line.gif" width="628" height="2" align="absmiddle"></p></td> </tr> <tr valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="420" colspan="5"> <blockquote> <p><br> <span class="font-norm-grey">If you would like to take a class please complete the form below. </span><span class="font-small-grey"><em> [Fields marked (</em></span><span class="font-norm-pink"><em>*</em></span><span class="font-small-grey"><em>) are required]. </em></span><span class="font-norm-grey">You can make your payment at your first class. We accept payment by cash or cheque payable to Ottawa Pole Fitness Inc.</span> <?php echo form($error); ?> <p class="font-small-grey-centered">Your privacy is important to us at Ottawa Pole Fitness. The information we collect is for our own purposes only and will not be given to anyone else. We use this information to keep a personal confidential file for everyone who registers with Ottawa Pole Fitness. We hate spam just as much as you do; this is why we will not distribute your information to anyone. If you have any concerns regarding our policy please contact us. <p class="font-small-grey-centered"><br> </blockquote></td> </tr> </table> <div align="center"><img src="images/Ottawa%20Pole%20Fitness%20Footer.gif" width="632" height="36"> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
fatmikey Posted February 17, 2009 Author Share Posted February 17, 2009 Looing good, very nice code, I really appreciate all the help. I think I can take it from here and iron out any kinks and also try and get my head around the code better. Very different from what I'm used to, which is very simple bad code, lol. I may be back if I run into any troubles with this new code. Thanks Again! Mikey Quote Link to comment Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 np bro take care ;-) 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.