myotch Posted April 27, 2010 Share Posted April 27, 2010 guess I am a brand new PHP enthusiast. Been working with it off and on for less than a year. This problem has come up from my own site I've been working on. Customer creates an order by filling out a form. Simple form, but kinda long. I need the form to go 1) go to me in an email, and 2) go to a confirmation/payment page. So, on ordermystuff.php, the form is coded thusly: <form id="buyform" name="buyform1" method="post" action="confirmdata.php"> (real form names and pages renamed for this purpose) The confirmdata.php page is formatted this way: You have ordered the <strong><?php echo $size ?>-sized MyotchWidgets in the <?php echo $template ?> design......(boring stuff)...Your MyotchWidgets will be shipped to <?php echo $name ?>, <?php echo $address ?> <?php echo $saddress2 ?>,<?php echo $cityy ?>,<?php echo $state ?>,<?php echo $zip ?> ...and the paypal, which works nicely, is coded like this: <?php if ($size == "BigMamma") { echo (include("includes/OmartheTentmaker_Paypal.php")); } else if ($size == "RegularJane") { echo (include("includes/SuzyQ_Paypal.php")); } else if ($size == "SkinnyMinnie") { echo (include("includes/LetMeBuyYouaBurger_Paypal.php")); } else if ($size == "SuperSkinny") { echo (include("includes/HeroineAddictorSupermodel_Paypal.php")); } else { echo ("Did you even pick a widget, $fname ?)"); } ?> So... In the form action, I did use the form script from my hosting company when initially developing the form, and it worked nicely. I had to change to confirmdata.php when developing the Paypal buttons. I've tried using the form action form script AND redirect, but it didn't bring the information forward like it should have. So, how do I get the form data to a confirmation page with the needed paypal "includes" AND to my email? Quote Link to comment Share on other sites More sharing options...
trq Posted April 27, 2010 Share Posted April 27, 2010 So, how do I get the form data to a confirmation page with the needed paypal "includes" AND to my email? The easiest way would be to put them all in the script that your form submits too. [ot] include does not actually return any output, so there is no need to echo it. echo (include("includes/OmartheTentmaker_Paypal.php")); should be.... include "includes/OmartheTentmaker_Paypal.php"; Note that echo and include don't need braces either. [/ot] Quote Link to comment Share on other sites More sharing options...
myotch Posted April 27, 2010 Author Share Posted April 27, 2010 So, how do I get the form data to a confirmation page with the needed paypal "includes" AND to my email? The easiest way would be to put them all in the script that your form submits too. [ot] include does not actually return any output, so there is no need to echo it. echo (include("includes/OmartheTentmaker_Paypal.php")); should be.... include "includes/OmartheTentmaker_Paypal.php"; Note that echo and include don't need braces either. [/ot] Good stuff. Though my "includes php's" were in fact being echoed in, your way slims down the code and works! So, how do I go about creating this script? is it as simple as putting in: <action="hostingform.pfp"> <action="confirmationpage.php"> into a process.php file, and pointing the form to that file in its own action? Quote Link to comment Share on other sites More sharing options...
trq Posted April 27, 2010 Share Posted April 27, 2010 You need to combine both scripts into one file and then point your form's action at that. Quote Link to comment Share on other sites More sharing options...
myotch Posted April 27, 2010 Author Share Posted April 27, 2010 You need to combine both scripts into one file and then point your form's action at that. OK - this is good stuff. I can put both scripts into one file, and pint the form to it. Check. I'm not really asking for someone to write the script, but....how do I write the script? Kinda new to this and this is the deepest I've gotten into php....any kind of coding for that matter. I'm an artist and would rather contemplate what would look good as a logo or on a business card. Any instructions on the web? With my limited vocabulary in such matters, I've managed to find a step-by-step.....writing in PERL. Five minutes in, my head asploded. Quote Link to comment Share on other sites More sharing options...
trq Posted April 27, 2010 Share Posted April 27, 2010 Why not post both the scripts that you have here and we can see if they'll need to be changed to work together? Quote Link to comment Share on other sites More sharing options...
myotch Posted April 27, 2010 Author Share Posted April 27, 2010 Why not post both the scripts that you have here and we can see if they'll need to be changed to work together? OK - the first one is a standard godaddy script which processes the form and mails it to where I point the server to mail it to. <?php $request_method = $_SERVER["REQUEST_METHOD"]; if($request_method == "GET"){ $query_vars = $_GET; } elseif ($request_method == "POST"){ $query_vars = $_POST; } reset($query_vars); $t = date("U"); $file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t; $fp = fopen($file,"w"); while (list ($key, $val) = each ($query_vars)) { fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\n"); fputs($fp,"$val\n"); fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\n"); if ($key == "redirect") { $landing_page = $val;} } fclose($fp); if ($landing_page != ""){ header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page"); } else { header("Location: http://".$_SERVER["HTTP_HOST"]."/"); } ?> The second is just a direct path to confirmation.php, where all the form field values are set to "$" variables. From the research I've done, I will not be able to edit gdforms.php, GoDaddy's proprieatary cgi's, nor will I be able to attach new cgi with my current hosting plan. Independently, the different actions work flawlessly and as intended. It's trying to make them both work at the same time. Quote Link to comment Share on other sites More sharing options...
myotch Posted April 27, 2010 Author Share Posted April 27, 2010 OK - got some clarification from GoDaddy. I can create a cgi and put it in the MySQL database. I just have no idea how to create a PERL script. Is there a php way of doing things? a javascript, maybe? Quote Link to comment Share on other sites More sharing options...
trq Posted April 27, 2010 Share Posted April 27, 2010 PHP is quite capable of entering data into a database if that is your question. Quote Link to comment Share on other sites More sharing options...
myotch Posted April 28, 2010 Author Share Posted April 28, 2010 PHP is quite capable of entering data into a database if that is your question. Well, no. Though I probably do need a database system for this. I wanted the order just to go straight into email, and be called to a confirmation type page while showing the appropriate Paypal button from the includes file. (I have 4 price codes for my 4 "sizes"). OK - what about this for a workaround: (Order form) --> (confirmation page) Confirmation page holds all the called data from the from within it's own form. The action of the confirmation form is to email, but the redirect target is itself a php code, something to the effect of: <input type=hidden name=redirect value= { <?php if $size == "big_mamma" "OmartheTentmaker_Paypal.php"; ?> /> ...possibly using the GET method to obscure my payment page address. What do you think? Quote Link to comment Share on other sites More sharing options...
myotch Posted April 29, 2010 Author Share Posted April 29, 2010 ok. Heres my workaround that is giving me just one last little headache. Here's my form on the orderproduct.php page: <form id="MyMagicalCart" name="MyMagicalCart" method="post" action="confirmyourorder.php"> <h1 class="style10">Pick-A-Widget</h1> <table width="549" border="0"> <tr bgcolor="#F14C4C"> <td colspan="4"><blockquote> <p><span class="style12">Step 1: Pick Your Card Size</span></p> </blockquote></td> </tr> <tr> <td width="89"><input type="radio" name="rad_size" id="Large" value="Large" /> </tr> [...] <input name="ShipZip" type="text" id="ShipZip" size="10" /></td> </tr> <tr> <td><div align="center"> <p class="style7"><em><strong>Please Double-Check Your Entries for Accuracy,<br /> Spelling, and Grammar. Minidoss cannot be held responsible for<br /> any errors submitted by customers.</strong></em></p> <p> <input type="submit" name="button" id="button" value="I Would Like to Buy my Widget now" /> Confirmyourorder.php puts the form selections and texts into ($) variable format like this: <?php $size = $_POST[rad_size]; [...] $shipzip = $_POST[shipZip]; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted April 29, 2010 Share Posted April 29, 2010 And? Quote Link to comment Share on other sites More sharing options...
myotch Posted April 29, 2010 Author Share Posted April 29, 2010 And? LOL - Sorry - I accidentally hit enter before finishing. let's try this: here's the email I get, which is missing all the user-made variables: subject: Minidoss Order Confirm_and_Pay: Confirm and Pay [this is my submit button - ed.] size:: [...] ship-zip:: ----- This e-mail was generated from a form submission on your website. here's the code from the original form: PHP Code: <form id="MyCart" name="MyCart" method="post" action="confirm.php"> here's where I establish my variables (i have this on both my orderpage.php and my confirmationpage.php) PHP Code: <?php $size = $_GET[rad_size]; [...] $shipzip = $_GET[shipZip]; ?> and here's the code from my confirm.php form PHP Code: <form id="MyCart" name="MyCart" method="post" action="/cgi/webformmailer.php"/> <?php if ($size == "Large") { echo '<input type="hidden" name=" redirect" value = "Payment_PP_Large.php">' ; } else if ($size == "Medium") { echo '<input type="hidden" name=" redirect" value = "Payment_PP_Medium.php">' ; } else if ($size == "Small") { echo '<input type="hidden" name=" redirect" value = "Payment_PP_Small.php">' ; } else if ($size == "Tiny") { echo '<input type="hidden" name=" redirect" value = "Payment_PP_Tiny">' ; } ?> In the form, I have a hidden table which I am trying to get the variables to go into. Here's some various ways I've tried to code it: <input name="Confirm and Pay" type="submit" id="Confirm and Pay" value="Confirm and Pay" /> </p> <p class="style15"> </p> <table style=display:none width="200" border="0"> <tr> <td>size</td> <td><input type="text" name ="size:" value="<?php echo $_POST[$size];?>"></td> </tr>... <input name="Confirm and Pay" type="submit" id="Confirm and Pay" value="Confirm and Pay" /> </p> <p class="style15"> </p> <table style=display:none width="200" border="0"> <tr> <td>size</td> <td><input type="text" name ="size:" value="$size"></td> </tr>... The problem is that everything works correctly except the email I am getting back, which does not contain the customer-created field values. Quote Link to comment Share on other sites More sharing options...
myotch Posted April 29, 2010 Author Share Posted April 29, 2010 doubleposted Quote Link to comment Share on other sites More sharing options...
trq Posted April 29, 2010 Share Posted April 29, 2010 And where is the code that sends the email? Quote Link to comment Share on other sites More sharing options...
myotch Posted April 29, 2010 Author Share Posted April 29, 2010 And where is the code that sends the email? In the form on confirm page, the action is "/cgi/webformmailer.php" If I put this as the action on the order page form, it sends me all the customer's information. If I put it in the confirmation page form with the hidden table and a visible confirm-submit button, it sends me form variable names and no input. So, I'm guessing, either I'm not calling the information correctly in the confirmation form, or the fact that the form is hidden is "hiding" the information from submitting. People use hidden form fields all the time, so I'm deducing that the confirmation form is not pulling in the customer-input data. Quote Link to comment Share on other sites More sharing options...
trq Posted April 30, 2010 Share Posted April 30, 2010 Can't help without seeing the relevant code. Quote Link to comment Share on other sites More sharing options...
myotch Posted April 30, 2010 Author Share Posted April 30, 2010 Can't help without seeing the relevant code. I think this is everything. Thanks for taking a look at this. Ordering php page: <form id="MyCart" name="MyCart" method="post" action="confirmation.php"> [...(nothing here but some design stuff)...] <p><span class="style12">Step 1: Pick Your Stuff</span></p> <tr> <td width="89"><input type="radio" name="rad_size" id="Small" value="Small" /> [...(a bunch more inputs. Texts, radials, textfields)...] <input name="ShipZip" type="text" id="ShipZip" size="10" /></td> </tr> [...] <input type="submit" name="button" id="button" value="I Would Like to Buy my Stuff now" /> </table> <?php $size = $_GET[rad_size]; [...(all the inputs from the form)...] $shipzip = $_GET[shipZip]; ?> </form> Confirmation page: (This is the part they are reading to confirm) <h1><span class="style13">Confirmation for <?php echo $fname ?></span><br /></h1> <p class="style11">You have ordered the <strong><?php echo $size ?>-sized blah blah blah </strong></p> [...more called variables in sentence form)...] <p class="style11">Your stuff will be shipped to: [...] <?php echo $shipzip ?></p> Now, under this, in the body still, I have the form values in a hidden table. <form id="MyCart" name="MyCart" method="post" action="/cgi/webformmailer.php"/> <input type="hidden" name="subject" value="an order for you, sir" /> <?php if ($size == "Small") { echo '<input type="hidden" name=" redirect" value = "Payment_PP_Small.php">' ; } [...(the rest of the sizes going to the rest of the payment pages)...] <table style=display:none width="200" border="0"> <tr> <td>size</td> <td><input type="text" name ="size:" value="<?php echo $_POST[$size];?>"></td> </tr> [...(the rest of the input types and called variables)...] <td><input type="text" name="ship-zip:" value="<?php echo $_POST[$shipzip]; ?>" /></td> </tr> </table> <p> <input name="Confirm and Pay" type="submit" id="Confirm and Pay" value="Confirm and Pay" /> </p> </form> And, of course, the webformmailer.php from Godaddy. <?php if ( !isset($_SERVER['SPI'])) { die(); } if (!isset($_SERVER['DOCUMENT_ROOT'])) { echo("CRITICAL: we seem to be running outside of the norm.\n"); header("Location: http://".$_SERVER["HTTP_HOST"]."/"); die("CRITICAL: Document root unavailable.\n"); } $request_method = $_SERVER["REQUEST_METHOD"]; if($request_method == "GET") { $query_vars = $_GET; } elseif ($request_method == "POST") { $query_vars = $_POST; } reset($query_vars); function customsort($a,$b) { // $a is array for form vars, $b is comma seperated case sensitive field order // this is case sensitive -- good idea to hrc that. $data = array(); if ( strstr($b,',') == FALSE ) { $b = $b.","; } $ordering = split(',',$b); foreach ($ordering as $orderitem) { if ( ($orderitem != null) && ($orderitem != "") ) { if (isset($a[$orderitem])) { $data[$orderitem] = $a[$orderitem]; } } } foreach ($a as $key=>$val) { $data[$key] = $a[$key]; } return $data; } function xmlentities($string) { return str_replace ( array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $string); } $t = date("U"); $formhomedir = preg_replace('/.*\/home\/content/','',$_SERVER['DOCUMENT_ROOT']); $formhomedir = explode('/',$formhomedir); if (count($formhomedir) <= 4) { $formhome="/home/content/".$formhomedir[1]."/".$formhomedir[2]."/data/"; } else { $formhome="/home/content/".$formhomedir[1]."/".$formhomedir[2]."/".$formhomedir[3]."/".$formhomedir[4]."/data/"; } $file_order = ".default"; $file_format = ".text"; $file_interval = ".15m"; $field_order = ""; if (isset($query_vars['form_order'])) { if ($query_vars['form_order'] != "alpha") { $field_order=$query_vars['form_order']; $file_order=".custom"; $query_vars = customsort($query_vars,$field_order); } else { switch ($query_vars['form_order']) { case "alpha": uksort($query_vars,'strnatcasecmp'); $file_order=".alpha"; break; default: $file_order=".default"; break; } } } if (isset($query_vars['form_format'])) { switch ($query_vars['form_format']) { case "csv": $file_format = ".csv"; break; case "html": $file_format = ".html"; break; case "xml": $file_format = ".xml"; break; case "text": case "default": default: $file_format = ".text"; break; } } if (isset($query_vars['form_delivery'])) { switch ($query_vars['form_delivery']) { case "hourly": $file_interval = ".60m"; break; case "hourly_digest": $file_interval = ".60mc"; break; case "daily": $file_interval = ".24h"; break; case "daily_digest": $file_interval = ".24hc"; break; case "digest": $file_interval = ".15mc"; break; case "default": default: $file_interval = ".15m"; break; } } $file = $formhome."form_".$t.$file_order.$file_format.$file_interval; $fp = fopen($file,"w"); reset($query_vars); switch ($file_format) { case ".csv": $csvkeys = ""; $csvvals= ""; $firsttime = ""; while (list ($key, $val) = each ($query_vars)) { if ( ($key == "form_order") || ($key == "form_format") || ($key == "form_delivery") || ($key == "redirect") ) { } else { if ($csvkeys != "") { $firsttime=","; } $tmpkey=escapeshellcmd($key); $csvkeys = $csvkeys.$firsttime."'".$tmpkey."'"; $tmpval=escapeshellcmd($val); $csvvals = $csvvals.$firsttime."'".$tmpval."'"; } } fputs($fp,"$csvkeys\n"); fputs($fp,"$csvvals\n"); break; case ".html": fputs($fp,"<table border=\"1\" cellspacing=\"1\" cellpadding=\"2\">\n"); break; case ".xml": fputs($fp,"<form>\n"); break; } reset($query_vars); while (list ($key, $val) = each ($query_vars)) { if ($key == "redirect") { $landing_page = $val; } if ( ($key == "form_order") || ($key == "form_format") || ($key == "form_delivery") || ($key == "redirect") ) { } else { switch ($file_format) { case ".html": fputs($fp,"\t<tr>\n"); fputs($fp,"\t\t<td><b>$key</b></td>\n"); fputs($fp,"\t\t<td>$val</td>\n"); fputs($fp,"\t</tr>\n"); break; case ".csv": // content is already output break; case ".xml": fputs($fp,"\t<field>\n"); fputs($fp,"\t\t<fieldname>".xmlentities($key)."</fieldname>\n"); fputs($fp,"\t\t<fieldvalue>".xmlentities($val)."</fieldvalue>\n"); fputs($fp,"\t</field>\n"); break; case ".text": default: fputs($fp,$key.": ".$val."\n"); break; } } } switch ($file_format) { case ".html": fputs($fp,"</table>\n"); break; case ".xml": fputs($fp,"</form>\n"); break; } fclose($fp); if ($landing_page != "") { header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page"); } else { header("Location: http://".$_SERVER["HTTP_HOST"]."/"); } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted April 30, 2010 Share Posted April 30, 2010 Sorry, but there is nothing in webformmailer.php that actually sends an email. Quote Link to comment Share on other sites More sharing options...
myotch Posted April 30, 2010 Author Share Posted April 30, 2010 Sorry, but there is nothing in webformmailer.php that actually sends an email. Right - it goes to the server - through my root, I'm guessing, which directs it to my email. This is pretty standard Godaddy proprietary-script kind of stuff. If I point to that script on my order page form, I get emailed all the information the customer puts in the shopping cart. The script is fine. However, if I put it in the form with the hidden table on my confirmation page, I just get the field names, not the customer-input stuff. I'm thinking I formatted the confirmation page form wrong in respect to getting the $-type variables (should it be "$name", [$name], or <?php $_POST[$name];?> or something else entirely? Quote Link to comment Share on other sites More sharing options...
myotch Posted April 30, 2010 Author Share Posted April 30, 2010 double post - sorry, my 'puter's slow Quote Link to comment Share on other sites More sharing options...
trq Posted April 30, 2010 Share Posted April 30, 2010 Ah, now I see the process. These.... value="<?php echo $_POST[$shipzip]; ?>" should be..... value="<?php echo $_POST['ShipZip']; ?>" as an example. Quote Link to comment Share on other sites More sharing options...
myotch Posted April 30, 2010 Author Share Posted April 30, 2010 ...and mark this one as "SOLVED!". Write the tutorial! Hurrah! Hazzah! Thorpe, you are awesome! Put yourself in for a raise and your band MM9 rocks, too! Now I can getting back to what I do best....the art stuff. 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.