kevinirish Posted March 22, 2010 Share Posted March 22, 2010 New to PHP and cannot find help anywhere, Is there any easy way to email the page content or Javascript results within .php form. I have designed a website with a JavaScript shopping cart (SimpleCart.js), when finished making purchases the user is directed to the Shopping Cart page to fill in their details and email their order using a .php form. I cannot get the shipping cart items to add into the email. Here is the html for the Order form: <code> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Online Order Form</title> <link href="css/orderform.css" rel="stylesheet" type="text/css" /> <style> body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #333333; } a { font-family: Arial, Helvetica, sans-serif; font-weight: bold; } .itemContainer{ width:100%; float:left; } .itemContainer div{ float:left; margin: 5px 20px 5px 20px ; } .itemContainer a{ text-decoration:none; } .simpleCart_items{font-family: Arial; font-size: 12px; color: #333333; } .simpleCart_total{font-family: Arial; font-size: 12px; color: #333333; } </style> <script type="text/javascript" src="simpleCart.js"></script> <script type="text/javascript"> simpleCart.email = "info@hightech.ie"; simpleCart.checkoutTo = PayPal; simpleCart.currency = EUR; simpleCart.cartHeaders = [ "decrement_noHeader" , "Quantity_noHeader" , "increment_noHeader" , "remove_noHeader" , "Price_noHeader" , "Total_noHeader" , "Name_noHeader" ]; </script> <script language="JavaScript" type="text/JavaScript"> <!-- function MM_reloadPage(init) { //reloads the window if Nav4 resized if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); } MM_reloadPage(true); function MM_validateForm() { //v4.0 if (document.getElementById){ var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args); if (val) { nm=val.name; if ((val=val.value)!="") { if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); if (p<1 || p==(val.length-1)) errors+='- '+nm+' Must Contain an Email Address.\n'; } else if (test!='R') { num = parseFloat(val); if (isNaN(val)) errors+='- '+nm+' Must Contain a Valid Phone Number.\n'; if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1); if (num<min || max<num) errors+='- '+nm+' Must Contain a Number Between '+min+' and '+max+'.\n'; } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' Is Required.\n'; } } if (errors){ alert('Please Complete All Required Fields:\n'+errors); } document.MM_returnValue = (errors ==''); } } //--> </script> </head> <body> <div id="Layer1" style="position:absolute; left:677px; top:362px; width:143px; height:132px; z-index:1; layer-background-color: #CCCC99; border: 1px none #000000;"> <p>Cart: <span class="simpleCart_total"></span> (<span class="simpleCart_quantity"></span> items) <br /> </p> <p>SubTotal: <span class="simpleCart_total"></span> <br /> Delivery: <span class="simpleCart_shippingCost"></span> </p> <p> -----------------------------<br /> Final Total: <span class="simpleCart_finalTotal"></span></p> </div> <div id="Layer2" style="position:absolute; left:677px; top:498px; width:143px; height:100px; z-index:2; background-color: #CCCC99; layer-background-color: #CCCC99; border: 1px none #000000;"> <p><a href="javascript:;" class="simpleCart_empty">Clear Menu</a></p> <p><a href="orderform.htm" target="_self">Update Cart </a></p> <p><a href="javascript:;" class="simpleCart_checkout">Pay by C/Card or PayPal</a> </p> </div> <div id="Layer3" style="position:absolute; left:15px; top:361px; width:649px; height:28px; z-index:3"> <table width="647" border="0"> <tr bgcolor="#652D8A" class="style21"> <td width="35"><div align="center"><span class="style27"><strong>Less</strong></span></div></td> <td width="41"><div align="center"><span class="style27"><strong>Qty</strong></span></div></td> <td width="37"><div align="center"><span class="style27"><strong> Add </strong></span></div></td> <td width="87"><div align="center"><span class="style27"><strong>Remove item</strong></span></div></td> <td width="67"><div align="center"><span class="style27"><strong>Unit Price </strong></span></div></td> <td width="93" bgcolor="#652D8A"><div align="center"><span class="style27"><strong>Unit Total </strong></span></div></td> <td width="257"><div align="center"><span class="style27"><strong>Item Description</strong></span></div></td> </tr> </table> </div> <form action="form_order.php" method="post" name="contact" onsubmit="MM_validateForm('email','','RisEmail');return document.MM_returnValue" value="Submit" /> <div id="Layer4" style="position:absolute; left:18px; top:89px; width:406px; height:239px; z-index:4; background-color: #B01F15; layer-background-color: #B01F15; border: 1px none #000000;"> <div align="center"></div> <br /> <table width="362" height="154" border="0" align="center"> <tr> <td width="82" height="17"><span class="style27"><strong>Name:</strong></span></td> <td width="270"><input name="name" type="text" id="name" /></td> </tr> <tr> <td height="17"><span class="style27"><strong>Address:</strong></span></td> <td><input name="address" type="text" id="address" size="35" required="yes" /></td> </tr> <tr> <td height="17"> </td> <td><input name="address2" type="text" id="address2" size="35" /></td> </tr> <tr> <td height="17"><span class="style27"><strong>City / County: </strong></span></td> <td><input name="city_county" type="text" id="city_county" required="yes" /></td> </tr> <tr> <td height="17"> </td> <td> </td> </tr> <tr> <td height="17"><span class="style27"><strong>Email: </strong></span></td> <td><input name="email" type="text" id="email" size="30" required="yes" /></td> </tr> <tr> <td height="17"><span class="style27"><strong>Contact no:</strong></span></td> <td><input name="contactno" type="text" id="contactno" required="yes" /></td> </tr> <tr> <td height="17"><span class="style27"><strong>Mobile no:</strong></span></td> <td><input name="mobile" type="text" id="mobile" /></td> </tr> </table> </div> <div id="Layer6" style="position:absolute; left:436px; top:88px; width:385px; height:84px; z-index:6; background-color: #B01F15; layer-background-color: #B01F15; border: 1px none #000000;"> <br /> <table width="288" border="0" align="center"> <tr> <td width="92" height="18"><span class="style27"><strong>Delivery date: </strong></span> </td> <td width="186"> <div align="left"> <input name="delivery_date" type="text" id="delivery_date" required="yes" /> </div></td> </tr> <tr> <td><span class="style27"><strong>Preferred time:</strong></span></td> <td> <div align="left"> <input name="time" type="text" id="time" required="yes" /> </div></td> </tr> </table> </div> <div id="Layer8" style="position:absolute; left:18px; top:340px; width:794px; height:21px; z-index:8" class="style35 style21"><strong>My Menu </strong></div> </p> <div id="cart" class="simpleCart_items" style="position:absolute; left:11px; top:389px; width:660px; height:39px; z-index:5;"> </div> </p> <br /> <div id="Layer5" style="position:absolute; left:677px; top:598px; width:143px; height:39px; z-index:5; background-color: #CCCC99; layer-background-color: #CCCC99; border: 1px none #000000;"> <div align="left"> <input name="Submit" type="submit" value="Email Order" class="send" onClick="MM_validateForm('name','','R','contactno','','R','email','','RisEmail','delivery_date','','R');return document.MM_returnValue;" > </div> </div> </body> </html> </code> Here is the PHP (orderform.php): <php> <?php // Creates fields from form data $name=$_REQUEST['name']; $email=$_REQUEST['email']; $contactno=$_REQUEST['contactno']; $address=$_REQUEST['address']; $address2=$_REQUEST['address2']; $city_county=$_REQUEST['city_county']; $delivery_date=$_REQUEST['delivery_date']; $delivery_time=$_REQUEST['delivery_time']; $mobile=$_REQUEST['mobile']; $cart=$_REQUEST['cart']; //Send Email to form owner $pfw_header = "From: $email\n" . "Reply-To: $email\n"; $pfw_subject = "Party Food 2u - website order \n"; $pfw_email_to = "info@hightech.ie \n"; $pfw_message = "Name: $name \n" ."Email: $email \n" ."Contact no: $contactno \n" ."Mobile number: $mobile \n" ."Address: $address \n" .": $address2 \n" ."City/County: $city_county \n" ."Delivery date: $delivery_date \n" ."Cart: $cart \n" ."Preferred time: $delivery_time \n"; $mail=mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header, $contents) ; if ($mail==0) { header( "Location: /order_problem.htm" ); } elseif (empty($email) || empty($name) || empty($address)) { header( "Location: /order_problem.htm" ); } else { header( "Location: /order_thankyou.htm" ); } ?> </php> 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.