sent in these useful web store hacks....
We frequently get orders submitted with an empty cart. I have
corrected this with the following piece of code:
# In web_store_order_lib.pl replace the
# sub display_order-form with the following
# Start as normal
sub display_order_form {
local($line);
local($subtotal);
local($total_quantity);
local($total_measured_quantity);
local($text_of_cart);
local($hidden_fields_for_cart);
# This is the extra bit
if (-z $sc_cart_path) {
print qq!
#Insert your HTML error message page here
!;
} else {
# That is the end of the extra bit, but
# note the extra bracket near the end of the sub
# Now insert the rest of the sub
open (ORDERFORM, "$sc_html_order_form_path") ||
&file_open_error("$sc_html_order_form_path",
"Display Order Form File
Error",__FILE__,__LINE__);
while (<ORDERFORM) {
$line = $_;
if ($line =~ /<FORM/i) {
print qq!
<FORM METHOD = "post" ACTION =
"$sc_order_script_url"
<INPUT TYPE = "hidden" NAME = "page"
VALUE = "$form_data{'page'}"
<INPUT TYPE = "hidden" NAME = "cart_id"
VALUE = "$form_data{'cart_id'}"\n!;
$line = "";
} # End of If Form tag found
if ($line =~ /<h2cart.*contents.*h2/i) {
($subtotal,
$total_quantity,
$total_measured_quantity,
$text_of_cart) =
&display_cart_table("orderform");
$text_of_cart =
&display_calculations($subtotal,"before",
$total_measured_quantity,$text_of_cart);
$line = "";
}
print $line;
} # End of Parsing Order Form
} # Now insert the extra bracket
} # End of display_order_form
In both of the applications I have implemented it would be useful to
perform a check on email addresses submitted to see if they are in a valid
format. The code may look something like this, which I have copied from
formmail.cgi:
sub check_email {
$email = $_[0];
if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
$email !~
/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) {
carry on with script;
}
else {
print "Invalid email address";
}
}