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

Thread: Need a little direction with fmcompute.

  1. #1
    Join Date
    Dec 2008
    Location
    Maryland
    Posts
    82

    Default Need a little direction with fmcompute.

    Will the Computation module help me select different forms based on a selected value?

    Example:

    <select name="year">
    <option value="">Year</option>
    <option value="2009">2009</option>
    <option value="2008">2008</option>
    <option value="2007">2007</option>
    </select>
    <select name="make">
    <option value="">Make</option>
    <option value="Acura">Accura</option>
    <option value="Bmw">Bmw</option>
    <option value="Ford">Ford</option>
    </select>


    So on the second form I would insert the two values from the first page like so.
    Then present another drop down for the particular model.

    2008
    Ford

    <select name="model">
    <option value="">Model</option>
    <option value="explorer">Explorer</option>
    <option value="mustang">Mustang</option>
    <option value="taurus">Taurus</option>
    </select>

  2. #2
    Join Date
    Dec 2008
    Location
    Maryland
    Posts
    82

    Default Re: Need a little direction with fmcompute.

    Few questions.

    1) What logic would I use to load_the_proper_makes base on what_model_was_selected?

    2) Can this be done with out fmcompute? Is there another way?

    3) How can I hide all the important stuff so no one will see/understand the logic?

    I am anticipating making a lot forms for each make. Looks like its going to be a lot of work.

    Tia

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

    Default Re: Need a little direction with fmcompute.

    Hi,

    Quote Originally Posted by billy View Post

    1) What logic would I use to load_the_proper_makes base on what_model_was_selected?
    There are two ways which seem good:
    1. Generate the "next_form" field from a computation so that it selects a different second page (as per your first post) based on the make selected.
    2. Use the same second page for every make and use Advanced Templates to control what gets displayed.
    I think the first method would be easier from a maintenance point of view.
    Also, the Advanced Templates don't yet handle expressions in IF blocks - so it makes things more messy.

    Here's the basic logic for field "fmcompute1":
    Code:
      import function FMUserError;
      import string make;
      export string next_form;
    
      next_form = make.'.html';
    This simply appends ".html" to the name of the make to create the name for the next page.

    You can do other things like this, depending on what naming scheme you want:
    Code:
      import function FMUserError;
      import string make;
      export string next_form;
    
      if (make == 'ford' || make == 'gm')
      {
         next_form = 'usa/'.make.'.html';
      }
      else
      {
         next_form = 'intl/'.make.'.html';
      }
    So, this is structured for a multiform templates folder that has subfolders called "usa" and "intl" (international). Then the documents for the makes are within one of those subfolders.

    2) Can this be done with out fmcompute? Is there another way?
    It can be done in PHP with FormMail's Hook System - but I don't recommend writing PHP code unless you are a very experienced programmer.

    The main worry is creating security vulnerabilities for your server.

    The first example logic above is very simple, so you could do it with derive_fields instead:

    HTML Code:
    <input type="hidden" name="derive_fields" value="next_form=make.%2E%.%'html'%" />
    3) How can I hide all the important stuff so no one will see/understand the logic?
    You can put your fmcompute's in an INI file.

    If you have PHP version 4, though, this is impractical because you can't wrap lines in an INI file.

    There's an alternative in this case.

    So on the second form I would insert the two values from the first page like so.
    Then present another drop down for the particular model.

    2008
    Ford

    <select name="model">
    <option value="">Model</option>
    <option value="explorer">Explorer</option>
    <option value="mustang">Mustang</option>
    <option value="taurus">Taurus</option>
    </select>
    Assuming you wanted all makes in the one document, using Advanced Templates, your second page (which is a FormMail template, of course) could look like this (note: this will not work in the current version):

    HTML Code:
    $year
    $make
    
    <if "$make" == "ford"> <!-- this type of expression is not yet supported! -->
     <select name="model">
     <option value="">Model</option>
     <option value="explorer">Explorer</option>
     <option value="mustang">Mustang</option>
     <option value="taurus">Taurus</option>
     </select>
    </if>
    As mentioned, that's the idea, but the comparison expression is not yet supported in Advanced Templates....it's coming though.

    Instead, you'd have to create a flag field for every type of make (that's why I said it was messy), and the code would need to look like this:
    HTML Code:
    $year
    $make
    
    <if "$make_is_ford">
     <select name="model">
     <option value="">Model</option>
     <option value="explorer">Explorer</option>
     <option value="mustang">Mustang</option>
     <option value="taurus">Taurus</option>
     </select>
    </if>
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  4. #4
    Join Date
    Dec 2008
    Location
    Maryland
    Posts
    82

    Default Re: Need a little direction with fmcompute.

    Hi Russell,

    I have multi now submitting from page 1 to page 2.

    Code:
    <input type="hidden" name="fmcompute1" value="import function FMUserError;
      import string make;
      export string next_form;
      next_form = make.'.html';" /
    The problem is i cannot get the dropdown to load in the second page. I used your example above but does not display.

    Code:
    $year
    $make
    
    <if "$make_is_ford">
     <select name="model">
     <option value="">Model</option>
     <option value="explorer">Explorer</option>
     <option value="mustang">Mustang</option>
     <option value="taurus">Taurus</option>
     </select>
    </if>
    I do not understand the correct way to set up the second form to get $make_is_ford to display the dropdown box. It does not show up in the form. When you right click and look at source you dont even see the code for it.

    If you would like ftp it is no problem at all...
    Last edited by billy; 13-Dec-2008 at 12:19 AM. Reason: lil spelling

  5. #5
    Join Date
    Dec 2008
    Location
    Maryland
    Posts
    82

    Default Re: Need a little direction with fmcompute.

    Good morning,

    I did get the second page working last night. I just went back to a regular select box without the if statements.

    HTML Code:
    $year
    $make
    
     <select name="model">
     <option value="">Model</option>
     <option value="explorer">Explorer</option>
     <option value="mustang">Mustang</option>
     <option value="taurus">Taurus</option>
     </select>
    However I would still like you to explain about your example below.

    HTML Code:
    <if "$make_is_ford"> 
    Where was this going. How can I to use this?
    Last edited by billy; 13-Dec-2008 at 09:13 PM. Reason: spelling

  6. #6
    Join Date
    Dec 2008
    Location
    Maryland
    Posts
    82

    Default Re: Need a little direction with fmcompute.

    Based on what I have learned in your first post. I need to make things a bit more complicated to me. lol

    As i am sure you know with each model year a manufacture produces different vehicles. Meaning they add new kinds of cars and stops making the old ones. I need to account for this in my forms. It means making close to 1000 forms i am sure. What I need is the logic to pull this off in the most none confusing way. lol

    In this next step I need to get fm pulling the correct template based on year and make.

    Example page 1

    HTML Code:
    <select name="year">
    <option value="">Year</option>
    <option value="2009">2009</option>
    <option value="2008">2008</option>
    <option value="2007">2007</option>
    </select>
    <select name="make">
    <option value="">Make</option>
    <option value="Acura">Accura</option>
    <option value="Bmw">Bmw</option>
    <option value="Ford">Ford</option>
    </select> 

    Example page 2

    If I chose 2009 Toyota the second page will display.

    HTML Code:
    <select name="model">
    <option value="">Model</option>
    <option value="camry">Camry</option>
    <option value="corolla">Corolla</option>
    <option value="yaris">Yaris</option>
    Here is the the basic issue. In the above example
    for the model year 2009 they made those three cars
    but in the model year 2008 they made different cars

    So I chose 2008 and toyota and I have different cars
    on the second page than was on the 2009 page.

    God I hope that makes sense to you.

    So could you provide a few examples in fmcompute for me as well as derive_fields?

    This really is very cool stuff man! I think I might be hooked.

    Thank you for your time.

    Regards

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

    Default Re: Need a little direction with fmcompute.

    Hi,

    OK, to set a make "test" field you'd do this in an fmcompute:

    HTML Code:
    import string make;
    import string year;
    export string make_is_ford;
    export string make_is_toyota;
    export string year2009;
    
    if (make == 'ford')
    {
     make_is_ford = '1';
    }
    elseif (make == 'toyota')
    {
     make_is_toyota = '1';
    }
    
    if (year == 2009)
    {
     year2009 = '1';
    }
    and so on.

    Then, in your template you'd do this:

    HTML Code:
    <if "$make_is_ford">
     <select name="model">
     <option value="">Model</option>
     <option value="explorer">Explorer</option>
     <option value="mustang">Mustang</option>
     <option value="taurus">Taurus</option>
     </select>
    </if>
    <if "$make_is_toyota">
     <select name="model">
     <option value="">Model</option>  
     <option value="camry">Camry</option>
     <option value="corolla">Corolla</option>
     <option value="yaris">Yaris</option>
     <if "$year2009">
       <option value="xymagic">XYMagic</option>
     </if>
     </select>
    </if>
    (I'm inventing a new model for 2009 called the "XYMagic".)

    You get the idea?

    This is a bit clunky because you have to create these extra fields to test for different values.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  8. #8
    Join Date
    Dec 2008
    Location
    Maryland
    Posts
    82

    Default Re: Need a little direction with fmcompute.

    You get the idea?
    This is a bit clunky because you have to create these extra fields to test for different values.
    I kinda get it Russell.

    This is what I have so far but its still incomplete. I have not been able to figure out how to get it setup correctly.

    Code:
        <input type="hidden" name="fmcompute1" value="import function FMUserError;
    import string make;
    import string year;
    export string make_is_ford;
    export string make_is_toyota;
    export string year2009;
    export string year2008;
    export string year2007;
    
    if (make == 'ford')
    {
     make_is_ford = '1';
    }
    elseif (make == 'toyota')
    {
     make_is_toyota = '1';
    }
    
    if (year == 2009)
    {
     year2009 = '1';
    }
    
    if (year == 2008)
    {
     year2008 = '1';
    }
    
    if (year == 2007)
    {
     year2007 = '1';
    }
        export string next_form;
        next_form = make.'.html';" />
    As you can see above by my example I am confused in the correct way to get this working. I am not even sure if I am close to what you intended. The point is I am trying hard to understand your posts.

    HTML Code:
    <if "$make_is_ford">
     <select name="model">
     <option value="">Model</option>
     <option value="explorer">Explorer</option>
     <option value="mustang">Mustang</option>
     <option value="taurus">Taurus</option>
      <if "$year2009">
     <option value="explorer">Explorer</option>
     <option value="van">Van</option>
     <option value="taurus">Taurus</option>
     </if>
      <if "$year2008">
     <option value="explorer">Explorer</option>
     <option value="truck">Truck</option>
     <option value="taurus">Taurus</option>
     </if>
      <if "$year2007">
     <option value="explorer">Explorer</option>
     <option value="car">car</option>
     <option value="taurus">Taurus</option>
     </if>
     </select>
    </if>
    <if "$make_is_toyota">
     <select name="model">
     <option value="">Model</option>  
     <option value="camry">Camry</option>
     <option value="corolla">Corolla</option>
     <option value="yaris">Yaris</option>
      <if "$year2009">
     <option value="">Model</option>  
     <option value="camry">Camry</option>
     <option value="van">Van</option>
     <option value="yaris">Yaris</option>
     </if>
       <if "$year2008">
     <option value="">Model</option>  
     <option value="camry">Camry</option>
     <option value="truck">Truck</option>
     <option value="yaris">Yaris</option>
     </if>
       <if "$year2007">
     <option value="">Model</option>  
     <option value="camry">Camry</option>
     <option value="car">car</option>
     <option value="yaris">Yaris</option>
     </if>
     </select>
    </if>
    I understand where you were going with all the different models by year.
    Very cool example indeed that seems very straight forward. But i am still puzzled on how to get this talking to fmcompute or fmcompute to this example.

    How close am I to getting this puppy working?

  9. #9
    Join Date
    Dec 2008
    Location
    Maryland
    Posts
    82

    Default Re: Need a little direction with fmcompute.

    Quote Originally Posted by russellr View Post
    Hi,
    You can put your fmcompute's in an INI file.
    If you have PHP version 4, though, this is impractical because you can't wrap lines in an INI file.
    I have php 5.2.6 installed.

    I have not been able to hide your first fmcompute1 in my ini file. Any pointers on getting this to work? I have tried every way I can think of.

    -----

    The following error occurred in FormMail :
    fmcompute_parse
    **********
    Error=These parse errors occurred in the following code:
    Line 1, position 1: Undeclared identifier 'make'.

    1:make

    -----

    The following error occurred in FormMail :
    fmcompute_parse
    **********
    Error=These parse errors occurred in the following code:
    Line 1, position 1: 'do' is a reserved word or symbol but is not yet supported.

    1:do

    -----

    Hum maybe you can sort this lil issue for me?

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

    Default Re: Need a little direction with fmcompute.

    Hi,

    Quote Originally Posted by billy View Post
    I kinda get it Russell.

    This is what I have so far but its still incomplete. I have not been able to figure out how to get it setup correctly.

    Very cool example indeed that seems very straight forward. But i am still puzzled on how to get this talking to fmcompute or fmcompute to this example.

    How close am I to getting this puppy working?
    Yes, this all looks exactly right.

    So, the fmcomputes execute to process and create fields when the page is submitted.

    Then, the next page is loaded and processed as a template. The template uses the fields that were submitted (and created by fcompute and derive_fields) previously.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. INI FILES and fmcompute
    By stehl in forum FormMail Computation Module
    Replies: 3
    Last Post: 11-Dec-2009, 09:39 PM
  2. Cant get fmcompute to work
    By stehl in forum FormMail Computation Module
    Replies: 12
    Last Post: 24-Nov-2009, 04:00 AM
  3. help with csv and fmcompute
    By drquijote in forum HOWTO Guides and Tips
    Replies: 1
    Last Post: 09-Dec-2008, 08:21 AM
  4. Trouble loading fmcompute module
    By aaron_w in forum FormMail Computation Module
    Replies: 2
    Last Post: 09-May-2008, 01:29 AM
  5. email not sent after fmcompute
    By aussieworld in forum Features Questions
    Replies: 4
    Last Post: 12-Jun-2007, 07:55 PM

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
  •