radical hacks Web Store Hack 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 {


# 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") ||
       "Display Order Form File

   while (<ORDERFORM) {
     $line = $_;

     if ($line =~ /<FORM/i) {
       print qq!
       <FORM METHOD = "post" ACTION =
       <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) {

        $text_of_cart) =

        $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";