Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: Help with Computation

  1. #1
    Join Date
    Mar 2007
    Posts
    26

    Default Help with Computation

    Hi there...

    I need to add a bit of computation into my form.. and I am having a few problems working out how it all works. I think my needs are fairly basic.

    To give you an idea. I have a multi page form.

    PAGE 1: collects some general information, with only one drop down list that has products which the user has to choose (there are no quantities - each product has a fixed price).

    HTML Code:
      <form name="MultiSample" method="post" action="connection.php"/>  
    <div align="center">
        <p>
        <input type="hidden" name="this_form" value="http://mydomain.com/FM-Test.html" />
        <input type="hidden" name="multi_start" value="1" />
        <input type="hidden" name="next_form" value="multitest2.htm" />
    
        This is Product Group 1
        <select name="ProductGroup1" id="ProductGroup1">
          <option value="100">Item 1</option>
          <option value="100">Item 2</option>
          <option value="100">Item 3</option>
        </select>
    </p>
        <p>This is some information i need to collect 
          <select name="Information1" id="Information1">
            <option>Information 1</option>
            <option>Information 2</option>
            <option>Information 3 </option>
          </select>
        </p>
    </div>
    <div align="center">
      <input type="submit" name="submit" value="Next >" />
    PAGE 2: Has a number of drop down lists (which contain products - again, no quantities), in which the user has to make selections.

    HTML Code:
    <form method="post" action="../connection.php" name="multisample" enctype="multipart/form-data" />
    <input type="hidden" name="this_form" value="$this_form_url" />
    <input type="hidden" name="next_form" value="multitest3.htm" />
    
    <div align="center">
      <p>This is Product Group 2 
        <select name="ProductGroup2" id="ProductGroup2">
          <option value="100">Item 1</option>
          <option value="100">Item 2</option>
          <option value="100">Item 3</option>
        </select>
    </p>
      <p>This is Product Group 3 
        <select name="ProductGroup3" id="ProductGroup3">
          <option value="100">Item 1</option>
          <option value="100">Item 2</option>
          <option value="100">Item 3</option>
        </select>
    </p>
      <p>
        <input type="submit" name="submit" value="Next >" />
    Page 3: Will contain the total price of the products selected on PAGE 1 & 2 as well as an itemised list of the products that the user has selected, and the price for each item. So, much like a receipt.

    HTML Code:
          <form name="MultiSample" method="post" action="../connection.php" />
          <input type="hidden" name="this_form" value="$this_form_url" />
    
    <div align="center">
      <p>The total purchase comes to: $XXXX </p>
      <p>and comprises of</p>
      <p>Product Group 1: Item2 @ $XXXX</p>
      <p>Product Group 2: Item 3 @ $XXXX</p>
      <p>Product Group 3: @ $XXXX   </p>
      <p><input type="submit" name="submit" value="Submit" /></p>
    I hope this make sense.

    If someone could point me in the right directions in terms of what code needs to go where.. that would be fantastic. I am not the most skilled code in the world, but generally with a helping hand I can work things out :-)

    CHeers

    Steve

  2. #2
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Help with Computation

    Hi,

    First, you have a problem with your HTML.

    You have:
    HTML Code:
        <select name="ProductGroup1" id="ProductGroup1">
          <option value="100">Item 1</option>
          <option value="100">Item 2</option>
          <option value="100">Item 3</option>
        </select>
    This means that whatever item the user selects, "ProductGroup1" will have the value "100". So, you can't actually know what item the user selected!

    You want something like this instead:
    HTML Code:
        <select name="ProductGroup1" id="ProductGroup1">
          <option value="1">Item 1</option>
          <option value="2">Item 2</option>
          <option value="3">Item 3</option>
        </select>
    Similarly for ProductGroup2, and 3.

    Now to the computations...

    You create a field called "fmcompute1". You can create additional fmcompute fields "fmcompute2", "fmcompute3", and so on too. But one fieldwill be sufficient for you.

    You do this on page 2 because you want the computations to be performed just before page 3 is displayed.

    HTML Code:
    <input type="hidden" name="fmcompute1" value="
      import function FMFatalError,FMFatalUserError;
      import function FMUserError;
      
       " />
    These first two import statements provide some error handlers you can use if you want... just include the lines in every fmcompute field you create.

    Next, you want to import the fields you're going to process.

    HTML Code:
    <input type="hidden" name="fmcompute1" value="
      import function FMFatalError,FMFatalUserError;
      import function FMUserError;
      import string ProductGroup1,ProductGroup2,ProductGroup3;
    
       " />
    You can now work with these fields inside the computations.

    Next, we'll create some fields to identify the items the person has ordered:
    HTML Code:
    <input type="hidden" name="fmcompute1" value="
      import function FMFatalError,FMFatalUserError;
      import function FMUserError;
      import string ProductGroup1,ProductGroup2,ProductGroup3;
     export string Prod1Item,Prod2Item,Prod3Item;
    
     Prod1Item = 'not ordered';
     Prod2Item = 'not ordered';
     Prod3Item = 'not ordered';
    " />
    And now add some logic to set the name of the item.

    HTML Code:
     <input type="hidden" name="fmcompute1" value="
       import function FMFatalError,FMFatalUserError;
       import function FMUserError;
       import string ProductGroup1,ProductGroup2,ProductGroup3;
     export string Prod1Item,Prod2Item,Prod3Item;
    
    Prod1Item = 'not ordered';
    Prod2Item = 'not ordered';
    Prod3Item = 'not ordered';
    if (ProductGroup1 == '1')
    {
     Prod1Item = 'Item1';
    }
    elseif (ProductGroup1 == '2')
     {
        Prod1Item = 'Item2';
     }
     elseif (ProductGroup1 == '3')
      {
     Prod1Item = 'Item3';
      }
    /* similarly for ProductGroup2 and 3 */
       " />
    Note that comparisons use '==' instead of '='. This is like the C and C++ languages.

    Now, in your last page (the last multi-page form template), you want this:
    HTML Code:
    <div align="center">
      <p>The total purchase comes to: $XXXX </p>
      <p>and comprises of</p>
      <p>Product Group 1: $Prod1Item @ $XXXX</p>
      <p>Product Group 2: $Prod2Item @ $XXXX</p>
      <p>Product Group 3: $Prod3Item @ $XXXX   </p>
      <p><input type="submit" name="submit" value="Submit" /></p>
    See how you go with that. You can then send the calculation logic (prices, etc.) and I'll show you how to do that too.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  3. #3
    Join Date
    Mar 2007
    Posts
    26

    Default Re: Help with Computation

    Hi Russell...

    thanks for that. I have got that going A OK!

    If you could step me through adding prices to this, that would be excellent.

    In this case, it is assumed all quantities will be 1.

    Thanks

    Steve

  4. #4
    Join Date
    Feb 2007
    Posts
    72

    Default Re: Help with Computation

    Hi Stamper

    Setting your prices is simply modifying Russell's examples like this:

    Code:
    <input type="hidden" name="fmcompute1" value="
       import function FMFatalError,FMFatalUserError;
       import function FMUserError;
       import string ProductGroup1,ProductGroup2,ProductGroup3;
     export string Prod1Item,Prod2Item,Prod3Item;
     
    export float fPrice1(2,'.',','),fPrice2(2,'.',','),fPrice3(2,'.',','),fTotal(2,'.',',');
     
    /*export float is to create the price and total fields with 2 decimal places*/
     
    Prod1Item = 'not ordered';
    Prod2Item = 'not ordered';
    Prod3Item = 'not ordered';
    fPrice1 = 0;   /*set price one to 0*/
    fPrice2 = 0;   /*set price two to 0*/
    fPrice3 = 0;   /*set price three to 0*/
    
    if (ProductGroup1 == '1')
    {
     Prod1Item = 'Item1';
    fPrice1 = 8.95;
    }
    elseif (ProductGroup1 == '2')
     {
        Prod1Item = 'Item2';
        fPrice1 = 10.95;
     }
     elseif (ProductGroup1 == '3')
      {
     Prod1Item = 'Item3';
    fPrice1 = 12.95;
      }
    /* similarly for ProductGroup2 and 3 */
     
    fTotal = fPrice1+fPrice2+fPrice3 /*Add your prices together*/
       " />
    Then on your third page:

    Code:
    <div align="center">
      <p>The total purchase comes to: $$fTotal </p>
      <p>and comprises of</p>
      <p>Product Group 1: $Prod1Item @ $$fPrice1</p>
      <p>Product Group 2: $Prod2Item @ $$fPrice2</p>
      <p>Product Group 3: $Prod3Item @ $$fPrice3</p>
      <p><input type="submit" name="submit" value="Submit" /></p>
    Hope this helps point you in the direction you want.
    Elso
    Last edited by Elso; 07-Mar-2007 at 02:07 AM.

  5. #5
    Join Date
    Mar 2007
    Posts
    26

    Default Re: Help with Computation

    Thank you very much. That worked perfectly.

    I may need some help in the next day or two expanding on that.. but, I will have a shot at it myself first.

    Thanks again!

    Steve

  6. #6
    Join Date
    Feb 2007
    Posts
    72

    Default Re: Help with Computation

    Your very welcome.
    Did my response to your conditional next_form make sense or helpful?

    Nelson

  7. #7
    Join Date
    Mar 2007
    Posts
    26

    Default Re: Help with Computation

    havent tried that yet, but looks fairly straight forward. will give it a go this evening and let you know.

  8. #8
    Join Date
    Mar 2007
    Posts
    26

    Default Re: Help with Computation

    Ok... the next bit.

    I have had a crack at this myself, and I think I am probably close.

    As per the above examples, there were no quantities involved, ie every price was just 1 x the price.

    What I need to do now, is to have multiples. BUT, there is only ONE drop down menu that determines the quantity of all the other items.

    I have worked out that by doing this:

    HTML Code:
    fTotal = fQuantity*(fPrice1+fPrice2+fPrice3) /*Add your prices together*/
    ...will allow me to multiple the total price by the Quantity drop down menu. This is fine, but, I need to show the total price of each item. So, if Product1 costs $10 and they select the Quantity as 4, then I just want it to show Product1 = $40 (It does NOT need to show 4 x $10)

    I thought I might achieve this by:

    HTML Code:
        Prod1Item = 'Item2';
        fPrice1 = fQuantity*10.95;
     }
    But no go.

    Any suggestions?

  9. #9
    Join Date
    Feb 2007
    Posts
    72

    Default Re: Help with Computation

    Hello

    Looks like you are doing some thinking and heading down the right track. That's good First thing you need to determine is, "what pieces of this information will you or might you need to display?" If there is a chance you may want to display like unit price (product1 10.95ea) the quantity (4 units) total unit cost ($43.80) then you don't want to close these doors. With this train of thought I would follow along with your second idea/concept, but I think you might be missing some small pieces to the puzzle.

    Points to remember:
    any fields you will use from your form in any calculation you need to "import" them. This would be any field values from your user form that will be used by fmcompute field, whether it's text or numbers. Notice this line in the previous post:
    Code:
    import string ProductGroup1,ProductGroup2,ProductGroup3;
    
    We imported these field values so fmcompute can use them. If you are importing a number for purpose of doing math calculation such as your quantity, then you would import int (int is short for integer or whole number) in this case you would add to your import list like so:
    Code:
    import string ProductGroup1,ProductGroup2,ProductGroup3;
    import int iQuantity;
    This is assuming your quantity field name in your user form is "iQuantity".

    fmcompute can also generate new/additional fields that can be used in more calculations and/or displayed in succeeding pages. Ito will do this by the use of "export". You can have fmcompute create/export "strings" "int" or "float" and I am sure there are more, but I am still learning this stuff myself

    Armed with this detail I might suggest you follow along like this:
    (Modification are in burgundy)
    Code:
    <input type="hidden" name="fmcompute1" value="
    
     import function FMFatalError,FMFatalUserError;
    import function FMUserError;
    
    
    import string ProductGroup1,ProductGroup2,ProductGroup3;
    import int iQuantity;
    export string Prod1Item,Prod2Item,Prod3Item; export float fUnitPrice1(2,'.',','),fUnitPrice2(2,'.',','),fUnitPrice3(2,'.',','),fCalPrice1(2,'.',','),fCalPrice2(2,'.',','),fCalPrice3(2,'.',','),fTotal(2,'.',',');
    /*export float is to create the price and total fields with 2 decimal places*/
    Prod1Item = 'not ordered';
    Prod2Item = 'not ordered';
    Prod3Item = 'not ordered';
    fUnitPrice1 = 0; /*set price one to 0*/
    fUnitPrice2 = 0; /*set price two to 0*/ fUnitPrice3 = 0; /*set price three to 0*/ fCalPrice1 = 0; /*set price one to 0*/ fCalPrice2 = 0; /*set price two to 0*/ fCalPrice3 = 0; /*set price three to 0*/ if (ProductGroup1 == '1')
    { Prod1Item = 'Item1'; fUnitPrice1 = 8.95;
    }
    elseif (ProductGroup1 == '2') {
    Prod1Item = 'Item2';
    fUnitPrice1 = 10.95; } elseif (ProductGroup1 == '3') { Prod1Item = 'Item3'; fUnitPrice1 = 12.95; } /* similarly for ProductGroup2 and 3 */
    fCalPrice1 = fUnitPrice1*iQuantity; fCalPrice2 = fUnitPrice2*iQuantity;
    fCalPrice3 = fUnitPrice3*iQuantity;
    fTotal = fCalPrice1+fCalPrice2+fCalPrice3; /*Add your prices together*/
    "
    />



    Following this, you will have for display:
    Single unit price (fUnitPriceX)
    Calculated ProductGroup price (fCalPriceX)
    Total Price (fTotal)

    Notice also I changed some of the field names to make them more defined for easy recognition. Also, notice the "f" in the front of the field names, this is so you can easily recognize them to contain a floating point. I used "i" on your quantity to signify integer. These prefixes are not required, just a little tidbit I got from Russell.

    the fmcompute is an awesome addition to FormMail. If you can imagine it, fmcompute can do it

    Hope this helps
    Elso

  10. #10
    Join Date
    Feb 2007
    Posts
    72

    Default Re: Help with Computation

    Don't know why all the extra spaces were inserted in the code tags in my previous post. This happened when I previewed and edited my post. Maybe Russell can explain what happened here

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Paypal link to buy Computation Module.
    By billy in forum FormMail Computation Module
    Replies: 6
    Last Post: 27-Apr-2009, 06:39 AM
  2. How to do simple computation
    By pbrienesse in forum HOWTO Guides and Tips
    Replies: 2
    Last Post: 22-Jan-2009, 07:40 PM
  3. Do I need the FormMail Computation Module?
    By smaynar in forum FormMail Computation Module
    Replies: 2
    Last Post: 21-Oct-2008, 04:40 AM
  4. Just getting started with computation module... failing utterly.
    By Tony.Jackson in forum FormMail Computation Module
    Replies: 1
    Last Post: 09-Apr-2008, 07:58 PM
  5. derivative, computation and order_id
    By kreon in forum Community Support
    Replies: 1
    Last Post: 17-Oct-2006, 09:41 AM

Bookmarks

Posting Permissions

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