Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Only submit positive results in order form

    Hi everybody

    I would like to be able to make it so that an order form only submits positive results.

    I have modified this form http://www.mcfedries.com/JavaScript/OrderTotals.asp for my friends website. She has 50 different products that she makes (different sizes and colors). The form submits results for things ordered but also for things not ordered.

    PROD_yellow_3.00=
    PROD_green_3.00=
    PROD_blue_3.00=
    PROD_red_3.00=1
    PROD_purple_3.00=

    As you can see the only thing ordered is the $3.00 red product. But all the other ones not ordered show up in the form results. Is there a way to only send results of items actually ordered?

    I have looked at other order forms and they also send all results not just positive ones.

    Thank you.

    My javascript experience: none, only able to modify things.

    (And I wanted to ask this question on the site that has the sample order form but something wasn't working and I couldn't join.)

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by Beeble View Post
    As you can see the only thing ordered is the $3.00 red product. But all the other ones not ordered show up in the form results. Is there a way to only send results of items actually ordered?
    Submitting the form willl submit all the form elements whether filled in or not, but it would be possible to filter out blanks on the server using ASP code. Suggest you contact the author.

    This script is Copyright (c) Paul McFedries and
    Logophilia Limited (http://www.mcfedries.com/).


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    New to the CF scene
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the clear cut answer.
    I will look into that ASP thing.

    The only way I could find to contact the author of the script is to join his forum and as mentioned in my OP something on his site wasn't working. It wouldn't accept my registration and then locked me out from trying again. I'll try again on another computer when I can.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,641 Times in 4,603 Posts
    Yeah, it's trivial to do this in the ASP code, but I think Philip just assumed that the server-side code is written in ASP.

    You don't say if the *actual* <FORM> you are using does submit to ASP or not. So...

    In the actual <form> you are using, what is the ACTION= ???

    ***********

    Doing this in the JS code would *NOT* be difficult.

    You'd just add code to the <form onsubmit="...here..."> that would simply set all the blank or zero quantity fields to be DISABLED, and disabled fields don't get submitted to the server.
    Last edited by Old Pedant; 08-14-2010 at 03:05 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Old Pedant, that disable idea of yours looks very promising. I have to say I have no idea of what to actually do, but after a small amount of research it looks like I've got to put disabled=true; somewhere.

    The form is only on my computer at this stage with form results opening up in an email so that I can test it easily.

    But when things are ready I'm going to do something with a cgi bin thing using NMS FormMail. Not because I'm wedded to cgi but because I found instructions on how to do it. If I'm coming across as a moron it's because my abilities don't go beyond html and css. This is what it says in the form mail instructions:
    <form action="http://www.your_site.com/cgi-bin/newname.pl" method="POST">

    I just logged into the server where my friend's site is hosted and it said

    Apache ASP support No (Component was not installed)
    SSI support Yes
    PHP support Yes
    CGI support Yes
    Perl support Yes
    Python support No
    FastCGI support No (Component was not installed)
    Miva support No (Component was not installed)
    ColdFusion support No (Component was not installed

    So it looks like the ASP thing is not an option. I did a search about filters with ASP but didn't understand anything anyway.

    .

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,641 Times in 4,603 Posts
    Yeah, that <form> is submitting to a CGI page written in PERL.

    You can't use ASP on that machine. Even if you installed "Apache ASP", it's not really the same thing at all as true ASP.

    So yeah, do what I suggested.

    Let's see...

    Assuming you change the <form> to this:
    Code:
    <form action="http://www.your_site.com/cgi-bin/newname.pl" method="POST"
          onsubmit="fixup(this); return true;">
    and then add this in the JS section:
    Code:
    function fixup(form)
    {
        var reprod = /^PROD_[a-z]*_\d?\.\d*$/i;
        for ( var e = 0; e < form.elements.length; ++e )
        {
            var fld = form.elements[e];
            if ( reprod.test( fld.name ) )
            {
                // yes, this matches the PROD_xxxx_1.99 type of pattern
                var val = parseFloat( "0" + fld.value );
                if ( isNaN(val) || val == 0 )
                {
                    // quantity is not valid number or no quantity given
                    fld.disabled = true; // so disable that field
                }
            } // end of the test on name
        } // end of the for loop
    }
    Utterly untested. If it doesn't work, show some more of the actual <form> code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Beeble (08-14-2010)

  • #7
    New to the CF scene
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Old Pedant: Didn't have any luck with that. Kept action to mail as otherwise I wouldn't be able to test it. Have removed the repetiton of all 50 items from code. So now just ten. Have also removed contact details section.
    My original formatting was
    "PROD_075g_LEMO_3.00" but changed it to
    "PROD_075gLEMO_3.00" to suit your code relating to the original sample form.
    I certainly appreciate the help you're giving me and it looks like to a lot of other people as well.

    I've uploaded the full page, still a work in progress though, to a testing site:
    http://testform.atspace.com/
    Edit: This test site now used Old Pedant's code with Philip M's modification

    Code:
    <form method="post" action="mailto:whatever@whatever.com" enctype="text/plain" onsubmit="fixup(this); return true;">
    
      <div class="bigbox">
      <div class="r1c1">
      <div>
      <div class="lemon">75g tubs - $3.00</div>
      <div class="wrap">
      <div class="box1"><span class="underline">Scent</span> <br>
      <div class="items" style="background-color: #ffff33;">Lemon</div>
      <div class="items" style="background-color: #5ea3ff;">Bubblegum</div>
      <div class="items" style="background-color: #ff9900;">Orange</div>
      <div class="items" style="background-color: #ff3852;">Strawberry</div>
      <div class="items" style="background-color: #e20062;">Raspberry</div>
      <div class="items" style="background-color: #33ff33;">Lime</div>
      <div class="items" style="background-color: #f2c900;">Banana</div>
      <div class="items" style="background-color: #a0a0a0;">Licorice</div>
      <div class="items" style="background-color: #33ff33;">Glitter Lime</div>
      <div class="items" style="background-color: #ff3852; font-size: 13px;">Glitter S'berry</div>
      </div>
      <div class="box2"> <span class="underline">Qty</span> <br>
     <input class="qty1" name="PROD_075gLEMO_3.00" maxlength="3" value="" onkeydown="return numbersonly(this, event)" onkeypress="return tabE(this,event)" onkeyup="CalculateTotal(this.form)" type="text"> 
      <input class="qty" name="PROD_075gBUBB_3.00" maxlength="3" value="" onkeydown="return numbersonly(this, event)" onkeypress="return tabE(this,event)" onkeyup="CalculateTotal(this.form)" type="text"> 
      <input class="qty" name="PROD_075gORAN_3.00" maxlength="3" value="" onkeydown="return numbersonly(this, event)" onkeypress="return tabE(this,event)" onkeyup="CalculateTotal(this.form)" type="text"> 
      <input class="qty" name="PROD_075gSTRA_3.00" maxlength="3" value="" onkeydown="return numbersonly(this, event)" onkeypress="return tabE(this,event)" onkeyup="CalculateTotal(this.form)" type="text"> 
      <input class="qty" name="PROD_075gRASP_3.00" maxlength="3" value="" onkeydown="return numbersonly(this, event)" onkeypress="return tabE(this,event)" onkeyup="CalculateTotal(this.form)" type="text"> 
      <input class="qty" name="PROD_075gLIME_3.00" maxlength="3" value="" onkeydown="return numbersonly(this, event)" onkeypress="return tabE(this,event)" onkeyup="CalculateTotal(this.form)" type="text"> 
      <input class="qty" name="PROD_075gBANA_3.00" maxlength="3" value="" onkeydown="return numbersonly(this, event)" onkeypress="return tabE(this,event)" onkeyup="CalculateTotal(this.form)" type="text"> 
      <input class="qty" name="PROD_075gLICO_3.00" maxlength="3" value="" onkeydown="return numbersonly(this, event)" onkeypress="return tabE(this,event)" onkeyup="CalculateTotal(this.form)" type="text"> 
     <input class="qty" name="PROD_075gLGLIT_3.00" maxlength="3" value="" onkeydown="return numbersonly(this, event)" onkeypress="return tabE(this,event)" onkeyup="CalculateTotal(this.form)" type="text"> 
     <input class="qty" name="PROD_075gSGLIT_3.00" maxlength="3" value="" onkeydown="return numbersonly(this, event)" onkeypress="return tabE(this,event)" onkeyup="CalculateTotal(this.form)" type="text"> 
      </div> 
      </div>
      </div>
      </div>
      
      <br>
      <div class="total">Total: $<input style="border: 0px solid #000000;" name="TOTAL" size="10" onfocus="this.form.elements[0].focus()" type="text">
      </div>
       
      </div>  
    
    
     <div style="border: 0px solid rgb(0, 0, 0); text-align: center;"><input type="reset" onkeypress="return tabE(this,event)" > 
     
     <input value="Send Order" type="submit" onkeypress="return tabE(this,event)" >   </div> 
      
      </form>
    Last edited by Beeble; 08-15-2010 at 03:35 AM. Reason: Test link now incorporates suggested code

  • #8
    New to the CF scene
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Old Pedant


    Your code works perfectly. Just realised that I've got numbers in my Product item description and your code does not allow for that. So I got rid of the numbers and oh my goodness it worked. I can't tell you how pleased I am. Thank you so much.

    I will need to use numbers though as it reflect the size of the items. I'll have a go at figuring it out for myself and report back if I need help.

    Thanks again for a simple elegant solution.

    Beeble

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Stripped down for testing - this works. Fault was in the regex.
    Naturally the button is simply for test purposes.


    Code:
    <form name = "myform" action="http://www.your_site.com/cgi-bin/newname.pl" method="POST" onsubmit="fixup(this); return true;">
    <input type = "text" class="qty" name="PROD_075gLEMO_3.00" maxlength="3" value="" > 
    <input type = "text" class="qty" name="PROD_075gBUBB_3.00" maxlength="3" value="" > 
    <input type = "text" class="qty" name="PROD_075gORAN_3.00" maxlength="3" value="">
    <input type = "text" class="qty" name="PROD_075gSTRA_3.00" maxlength="3" value="">
    
    <br>
    <input type = "button" value = "Disable Blank Fields" onclick = "fixup(this.form)">
    </form>
    
    <script type = "text/javascript">
    
    function fixup(form) {
    var reprod = /^PROD_/i;
    for ( var e = 0; e < form.elements.length; ++e ) {
    var fld = form.elements[e];
    if ( reprod.test( fld.name ) ) {
    // yes, this matches the PROD_ type of pattern
    var val = parseFloat( "0" + fld.value );
    if ( isNaN(val) || val == 0 ) {
    // quantity is not valid number or no quantity given
    fld.disabled = true; // so disable that field
    }
    } // end of the test on name
    } // end of the for loop
    }
    
    </script>
    Make sure that any validations re quantites or whatever are completed before running this script which disables the blank/invalid fields and makes further editing impossible!
    Last edited by Philip M; 08-14-2010 at 10:09 AM. Reason: Typo

  • #10
    New to the CF scene
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Philip M

    Thank you for that alteration to allow for numbers in the product description. It worked perfectly and I couldn't have done it myself.

    Also thanks for pointing out that the empty fields are disabled after submitting the form. In my excitement I hadn't realised that.

    I'll probably see if I can get a button to do the equivalent of a hard refresh so that users don't get freaked out if they want to do another order.

    Beeble

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by Beeble View Post
    Philip M

    Thank you for that alteration to allow for numbers in the product description. It worked perfectly and I couldn't have done it myself.

    Also thanks for pointing out that the empty fields are disabled after submitting the form. In my excitement I hadn't realised that.

    I'll probably see if I can get a button to do the equivalent of a hard refresh so that users don't get freaked out if they want to do another order.

    Beeble
    Not quite right - the empty fields are disabled before the form is submitted. But submitting the form causes a page refresh, which will reload the page and start over. No problem with another order.

    My point was simply that you should validate the fields before running the fixup() function.

  • #12
    New to the CF scene
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Philip M

    Thanks for the follow up.

    Well
    the empty fields are disabled before the form is submitted
    I don't understand that but I don't think I need to.

    What I can say is that in Firefox 3.5.11 after submitting the form, the order form page is unusable. The fields that didn't get filled out are slightly grey and won't accept numbers until I do a hard refresh.

    Seems to do the same thing in IE 7, but the disabled boxes don't change color. However a normal refresh restores the fields to enabled.

    I also tested it out with the cgi bin thing in the action instead of mail to and nothing changed.

    I have updated the test site http://testform.atspace.com/index.html to use Old Pedant's code with Philip M's modification but still with the mail to action.

  • #13
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by Beeble View Post
    What I can say is that in Firefox 3.5.11 after submitting the form, the order form page is unusable. The fields that didn't get filled out are slightly grey and won't accept numbers until I do a hard refresh.
    Yes, that's right. You must refresh (reload) the page before it can be used again.

  • #14
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,641 Times in 4,603 Posts
    Given the actual code you show there, an easier/better solution would be to look at the class="..." for each <input>, thus:
    Code:
    function fixup(form)
    {
        for ( var e = 0; e < form.elements.length; ++e )
        {
            var fld = form.elements[e];
            if ( fld.className == "qty" || fld.className == "qty1"  )
            {
                // yes, this is a quantity input field
                var val = parseFloat( "0" + fld.value );
                if ( isNaN(val) || val == 0 )
                {
                    // quantity is not valid number or no quantity given
                    fld.disabled = true; // so disable that field
                }
            } // end of the test on name
        } // end of the for loop
    }
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #15
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,641 Times in 4,603 Posts
    You do know that the pricing on that page makes no sense?

    The price per 25grams for the various tubs is:

    75g tub: $1
    150g tub: $1
    200g tub: $1.25
    400g tub: $1.19
    800g tub: $1.09

    So the cheapest thing to do is only buy the 75g and 150g tubs, no matter what quantity you actually want.

    That's as bad as some of the "bargains" at the local grocery store, where it costs more per pound to buy 3 pounds of coffee than it does to buy 1 pound.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •