adamci Posted September 8, 2008 Share Posted September 8, 2008 Hi, I have a shipping script that I'm trying to modify to my needs. Basically the script has you select your state or country from a drop down menu then takes the price attached to that state (zone) and fowards it to your shopping cart. What I want the script to do is take a ZIP CODE that the user inputs into a text box and search for the proper zone in the script to pass the price. I don't think anyone would want to scroll through hundreds of zip codes and select it! So if there is a way to modify this script to do that please let me know! THANKS! Here is the script: <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 = "xxxxxx"; $malsserver = "xxx"; $currency = "$"; // PART 2: UNITS PER ZONE $units_per_zone = "1-99999"; // PART 3: SHIPPING OPTIONS $option1 = "Alabama:1.00"; $option2 = "Arkansas:2.00"; // 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/123347-basic-script-help-probably-easy-but-im-clueless/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.