ok, I have to say right off, I am way over my head here, so any help will be greatly appreciated...
I have found the greatest php order form. It is so simple and clean, it is lovely, and it does almost everything I need. But I don't have the php knowledge to do the last little bit of tweaking that I need. The code is from dyn-web (http://www.dyn-web.com/scripts/orderform/). The order form link in the third paragraph takes you to their original. Using their code, I put the form on our pages. (http://www.fish-news.com/cfn/forms/corder/form.php) I didn't like how the shipping worked since it isn't based on the quantity that is ordered, so I embedded the shipping costs into the prices. But now I've screwed myself. The tax in the original form worked perfectly, it no longer does, because the shipping is included. The tax is now figured on the total ordered, including subscriptions which also should not be taxed. If I could change the tax computation so that when the Maine box is checked, it takes the number of tshirts orderded x $14.95 + the number of sweatshirts x $24.95 x .05 to figure the amount of the sales tax, I think I'd have it made. I believe the sales tax computation is somewhere in the order_fns.php file, and I think I can almost find it, but I don't know how to change it. I've written to the Dynamic Web people, but I'm afraid they are gone for the weekend and I've got to have this up and running by Monday night at the latest. Is it possible to do what I'm suggesting? I've copied the order_fns file before, sorry for the bandwith hogging, but I'm hoping that someone with php knowledge can look and say "change this__ to this ___. Thanks for any help that can be given. Leslie order_fns.php <?php // array elements: product code, product name, unit price // product code should contain no spaces, only letters, numbers // and underscores (first character should not be number) $products = array ( array ("scfn_1", "1-yr subscription, Commercial Fisheries News", 19.95), array ("c-1", "Long-sleeve t-shirt $14.95 + $5 shipping", 19.95), array ("c-2", "Hooded sweatshirt - $24.95 + $9 shipping", 33.95) ); // optional: sales tax and shipping options, i.e., if you do not include the variables // the relevant portions of the form will not be generated and code will still work fine $state = "Maine"; $cur_sales_tax = .05; // state sales tax // No need to edit below this line ?> <script type="text/javascript"> /************************************************************************* This code is from Dynamic Web Coding at www.dyn-web.com Copyright 2002-4 by Sharon Paine See Terms of Use at www.dyn-web.com/bus/terms.html regarding conditions under which you may use this code. This notice must be retained in the code as is! Visit www.dyn-web.com/scripts/orderform/ for the complete source code *************************************************************************/ var products = new Array(); // hold product codes for use in doTotals <?php $num_products = count($products); for ($row=0; $row<$num_products; $row++) : ?> products[<?php echo $row ?>] = "<?php echo $products[$row][0] ?>"; <?php endfor; ?> function getProductTotal(field, form) { if (field.value=="") field.value=0; if ( !isPosInt(form, field, field.value) ) return; else { var product = field.name.slice(0, field.name.lastIndexOf("_") ); var price = form[product + "_price"].value; var amt = field.value * price; form[product + "_tot"].value= formatDecimal(amt); doTotals(form); } } function doTotals(form) { var sub_tot_amt=0, tax_amt=0, g_tot_amt=0; for (var i=0; i < <?php echo $num_products ?>; i++) { var cur_field = form[ products[i] + "_qty" ]; if ( !isPosInt(form, cur_field, cur_field.value) ) return; else sub_tot_amt += parseFloat(cur_field.value) * parseFloat( form[ products[i] + "_price" ].value ); } form.sub_tot.value = formatDecimal(sub_tot_amt, 2); if ( form.sales_tax && form.sales_tax.checked ) { tax_amt = <?php echo isset($cur_sales_tax)? $cur_sales_tax: 0 ?> * sub_tot_amt; form.tax_amt.value = formatDecimal(tax_amt); } if (sub_tot_amt==0) g_tot_amt=0; else g_tot_amt = sub_tot_amt + tax_amt + <?php echo ( isset($ship_options) && !empty($ship_options) )? 'parseFloat(form.ship_amt.value)': 0 ?>; form.grand_tot.value = formatDecimal(g_tot_amt); } function inspectOptions(btn, field, form) { field.value = formatDecimal(btn.value); if (form.sub_tot.value > 0) doTotals(form); } function doSalesTax(field,form) { if (field.checked) form.tax_amt.value = formatDecimal( <?php echo isset($cur_sales_tax)? $cur_sales_tax: 0 ?> * form.sub_tot.value ); else form.tax_amt.value = 0; if (form.sub_tot.value > 0) doTotals(form); } function finalCheck(form) { // final check of quantity entries' validity for (var i=0; i < <?php echo $num_products ?>; i++) { var cur_field = form[ products[i] + "_qty" ]; if ( !isPosInt(form, cur_field, cur_field.value) ) return; } // check if a quantity entered if (form.grand_tot.value == 0) { alert("You haven't ordered anything."); return false; } else { if ( !isValidEmail(form, form.email, form.email.value) ) return; form.submit(); } } function checkValue(field) { if (field.value == 0) field.value = ""; } function reCheckValue(field) { if (field.value == "") field.value = 0; } // ie needs delay function setFocus(fld) { fld.focus(); fld.select(); } function isPosInt(frm,fld,val) { var re = /^\d+$/ if ( !re.test(val) ) { alert("Please enter whole numbers only."); if ( document.forms[frm.name] ) { // protect ns4 in case of nesting setTimeout("setFocus(document.forms['"+frm.name+"'].elements['"+fld.name+"'])", 100); } else { fld.focus(); fld.select(); } return false; } else return true; } function isValidEmail(frm,fld,entry) { var re = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i; if (!re.test(entry)) { alert("The email address is not valid.") if ( document.forms[frm.name] ) { // protect ns4 in case of nesting setTimeout("setFocus(document.forms['"+frm.name+"'].elements['"+fld.name+"'])",100); } else { fld.focus(); fld.select(); } return false; } else return true; } // format val to n number of decimal places // modified version of Danny Goodman's (JS Bible) function formatDecimal(val, n) { n = n || 2; var str = "" + Math.round ( parseFloat(val) * Math.pow(10, n) ); while (str.length <= n) str = "0" + str; var pt = str.length - n; return str.slice(0,pt) + "." + str.slice(pt); } </script>
