adamci Posted September 10, 2008 Share Posted September 10, 2008 Hello, I don't know much about PHP and I would really appreciate it if someone out there could help me with my question. I have PHP shopping cart script that basically has a user select something (50 States in this case) from a drop-down menu and then takes the shipping price associated with that selection and passes it on to another script. All I want to do is get rid of the drop-down box and replace it with a text input field. From their I would like the user to type in their 5 digit zipcode. Then I would just need the script to take that zip code and find its match inside the script and basically get the shipping price the same way compared to having a drop-down with hundreds of zipcodes. I'm guessing the editing must come in the //CREATE ZONE LIST section Here is the complete code: <script language="php"> // FREE Mals-E Option 8 Shipping Script // Copyright 2004 OptionCart.com // Shopping cart catalogs for Mals-E users // PART 1: MALS INFO AND CURRENCY $malsid = "xxxxx"; $malsserver = "xxx"; $currency = "$"; // PART 2: UNITS PER ZONE $units_per_zone = ""; // PART 3: SHIPPING OPTIONS $option1 = "Alabama"; $option2 = "Arizona"; $option3 = "Arkansas"; $option4 = "California"; // PART 4: ADDITIONAL FEES $fee1 = "First Additional Item:5.00"; $fee2 = "Second Additional Item:6.00"; $fee3 = "Third Additional Item:7.00"; // PART 5: MULTIPLY BY UNITS? (Y or N) $multiply_by_units = "Y"; // PART 6: MINIMUM CHARGE BEFORE ADDITIONAL FEES $minimum = 0; // PART 7: MAXIMUM CHARGE BEFORE ADDITIONAL FEES $maximum = 0; // PART 8: HANDLING CHARGE BEFORE MIN, MAX, ADDITIONAL FEES $handling = 5; // PART 9: DISPLAY PRICES (Y or N) $display_prices = "Y"; // PART 10: USE PRICES OR UNITS? (prices or units) $set_input = "units"; // ------------------------------------------------ if ($set_input != "units") $units = $value; // CREATE ZONE LIST $opt_list = "Select a zone below:<br>"; $opt_list .= "<select size=\"1\" name=\"zone\">"; for ($i = 1;;++$i) { $optname = "${"option$i"}"; if (empty($optname)) break; // CONFIGURE THIS ZONES AMOUNT $splitopt = explode(":", $optname); $upzcheck = "${"units_per_zone$i"}"; if (!empty($upzcheck)) $unitsperzone = $upzcheck; else $unitsperzone = $units_per_zone; $unitlist = explode(",", $unitsperzone); $feelist = explode(",", $splitopt[1]); for ($u=0; $u < count($unitlist); ++$u) { $unitset = explode("-", $unitlist[$u]); if ($unitset[0] <= $units AND $units <= $unitset[1]) $optfee = "$feelist[$u]"; } if ($multiply_by_units == "Y") $totalshipping = $units * $optfee; else $totalshipping = $optfee; $totalshipping = $totalshipping + $handling; if ($minimum > 0 AND $totalshipping < $minimum) $totalshipping = $minimum; if ($maximum > 0 AND $totalshipping > $maximum) $totalshipping = $maximum; $totalshipping = number_format($totalshipping, 2); // CREATE DROP DOWN $opt_list .= "<option "; if ($i == 1) $opt_list .= "selected "; $opt_list .= "value=\"$splitopt[0]~$totalshipping\">$splitopt[0]"; if ($display_prices == "Y") $opt_list .= " $currency$totalshipping"; $opt_list .= "</option>"; } $opt_list .= "</select><br>"; // IF OPTION 1 ONLY, DO NOT USE DROP DOWN BOX if (empty($option2)) { $opt_list = "<b>$splitopt[0]"; if ($display_prices == "Y") $opt_list .= " $currency$totalshipping"; $opt_list .= "</b><br>"; $opt_list .= "<input type=\"hidden\" name=\"zone\" value=\"$splitopt[0]~$totalshipping\">"; } // IF THE FORM HAS BEEN PROCESSED OR ONLY ONE ZONE if ($_POST[mode] == "calculate" OR (empty($option2) AND empty($fee1) AND empty($fee2) AND empty($fee3))) { // IF ONLY ONE OPTION AND NO ADDL FEES if (empty($option2) AND empty($fee1) AND empty($fee2) AND empty($fee3)) $zone_val = "$splitopt[0]~$totalshipping"; else { $zone_val = $_POST[zone]; $prod_1_val = $_POST[productpr1]; $prod_2_val = $_POST[productpr2]; $prod_3_val = $_POST[productpr3]; } $shipinfo = explode("~", $zone_val); $shipopts = $shipinfo[0]; $shiptotal = str_replace(",", "", $shipinfo[1]); // If additional items are posted, use product add form $additional = ""; if ($prod_1_val) $additional .= "&productpr1=" .$prod_1_val ."&qty1=1"; if ($prod_2_val) $additional .= "&productpr2=" .$prod_2_val ."&qty2=1"; if ($prod_3_val) $additional .= "&productpr3=" .$prod_3_val ."&qty3=1"; if (empty($additional)) $malsurl = "http://$malsserver.aitsafe.com/cf/review.cfm?"; else $malsurl = "http://$malsserver.aitsafe.com/cf/addmulti.cfm?"; $malsurl .="userid=$malsid$additional&shipping=$shiptotal&shipopts=$shipopts"; if ($return) $malsurl .= "&return=$return"; $errormsg = "<p align=\"center\">Your shipping: $shiptotal.<br><a href=\"$malsurl\">Update shipping in cart</a>.</p>"; @header("Location: $malsurl"); die ("$errormsg"); } </script> <html> <head> <title>Shipping Calculator</title> </head> <body> <!-- START OPTIONAL HTML HEADER //--> <!-- END OPTIONAL HTML HEADER //--> <form method="POST" action="shipping.php"><p align="center"> <?php // DISPLAY ZONES echo "$opt_list"; // DISPLAY ADDL FEES for ($i = 1;;++$i) { $addl = "${"fee$i"}"; if (empty($addl)) break; $splitaddl = explode(":", $addl); echo "<input type=\"checkbox\" name=\"productpr$i\" value=\"$addl\"> "; echo "$splitaddl[0]"; if ($display_prices == "Y") echo " $currency$splitaddl[1]"; echo "<br>"; } echo "<input type=\"hidden\" value=\"$return\" name=\"return\">"; echo "<input type=\"hidden\" value=\"$units\" name=\"units\">"; ?> <input type="hidden" value="calculate" name="mode"> <input type="submit" value="Calculate Shipping" name="submit"> </form> <!-- START OPTIONAL HTML FOOTER //--> <!-- END OPTIONAL HTML FOOTER //--> </body> </html> Link to comment https://forums.phpfreaks.com/topic/123536-changing-drop-down-to-text-input-field-urgent/ Share on other sites More sharing options...
vicodin Posted September 10, 2008 Share Posted September 10, 2008 For it all to happen on one page without it being reloaded you would need another language besides PHP. something like Javascript or AJAX, If you were to do it with php you would need to create a input box and have a submit and transfer all the variables over to another page and on that page have it go to the database and referance that zipcode and then calculate whatever you need to calculate Link to comment https://forums.phpfreaks.com/topic/123536-changing-drop-down-to-text-input-field-urgent/#findComment-638081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.