Page 3 of 3 FirstFirst 123
Results 21 to 29 of 29

Thread: Help with Computation

  1. #21
    Join Date
    Apr 2008
    Posts
    23

    Default Re: Help with Computation

    Quote Originally Posted by aaron_w View Post

    What do all the arguments to initialize the float mean?

    It looks to me like you've got a "number of digits after the decimal point" argument, a "decimal point separator" argument, and then something which you're passing a comma to - I assume thousands separator?
    OK, I found the answer to that question ---
    http://tectite.com/vbforums/showthread.php?t=1561

  2. #22
    Join Date
    Feb 2007
    Posts
    72

    Default Re: Help with Computation

    Hello Arron

    There is a whole wealth of information at: http://tectite.com/fmhowto/guides.ph...abfd09b1e813f8

    The reading is short and to the point, which is what's great about formmail w/extras, you need to do the creation, formmail is only a tool. Instead of asking "what can formmail do?" you should be asking "what do I want it to do?" Chances are formmail w/appropriate mods can do whatever you need.

    Enjoy exploring
    Nelson

  3. #23
    Join Date
    Apr 2008
    Posts
    23

    Default Re: Help with Computation

    Hey Nelson ---

    Thanks, I'm familiar with those and have scoured them

    It's an amazingly capable little tool for a formmail script

    I was more wondering about the specific capabilities of the computation module, and as far as I know, there's no doc page for that one yet ...

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

    Default Re: Help with Computation

    Hi Aaron,

    Quote Originally Posted by aaron_w View Post
    First off, what data types do we have?
    Are there also integers? If so, how to initialize them?
    Inside a computation, you have:
    • bool
    • int
    • string
    • float
    Outside a computation, we're just dealing with HTML fields, and fields are just strings - there are no types.

    So, that's why we import and export fields to and from the computations. In the process of importing, you can convert the field (string) to the type you're wanting it to be.

    In the process of exporting you're converting the type to a string, and the case of floats, you can format them as you've seen.

    In the case of exporting int's you can convert base (radix) and insert thousands separators:
    Code:
    export int    iVal1(8);       // octal, or base 8
    export int    iVal2(10,',');  // base 10, with comma for thousands
    How strongly typed is this little language?
    It is strongly typed, but with sensible conversions (though I think some things need to be tightened too). You can add numbers and strings, and the strings are converted to the number type. But you can't add numbers and bools, for example.

    You can't assign to an imported variable (field), unless it is also marked for export.

    The most important thing is that you cannot use a variable without declaring it first.

    Languages that don't do that, haven't learned the lessons from the languages created in the 1960's and 1970's.

    And how do the error functions work?
    Do you just go
    if (something) { FMUserError('something') }
    ?
    That's correct.

    For FMFatalUserError and FMUserError you just pass a string.

    For FMFatalError, there are 3 parameters: the string as above, a bool to specify whether to filter the message (you would generally want false for this), and a bool to specify whether to show the error to the user (person submitting the form).

    BTW, these functions are actually defined in FormMail, and imported into the Computation.

    Sorry, lots of questions, but this just opens up a whole can of worms for my mind wanting to know what is and isn't possible, since there doesn't seem to be much documentation on this, save for the sample and what's in the forums ...
    Yes, sorry.

    If you look around the site, you'll see we don't yet actively market the computation module. We offer it to solve specific problems people have (mostly Advanced Tempaltes).

    We *will* be writing a manual as soon as we possibly can (and ramping up the marketing).

    Also is it possible to put the "fmcompute1", ... fields into the .ini so as to hide your form computation logic from the world?
    Yes!

    This is best with PHP 5 because PHP 4 doesn't allow you to have an INI file value with newlines embedded - which makes your computation field unreadable.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  5. #25
    Join Date
    Apr 2008
    Posts
    23

    Default Re: Help with Computation

    Awesome!

    Thank you.

    I'm especially glad I can put these in the .ini file.

    I can't think of why I'd want to at present, but can you define functions and/or import your own functions?

    Of course, at a certain point, it may be a case of "why don't you just use PHP and do these things yourself?"

    But I have been quite impressed by this little form handling framework and it does take some of the regular things you do with forms (error handling, input validation, confirmations, multi-pages, etc) much easier.

    Aaron

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

    Default Re: Help with Computation

    Hi,

    Before I respond to your questions, I just realized I made a mistake in the above (I really need to write the documentation ).

    When importing fields, you *cannot* currently import into a specific type. Fields are strings, so you need to:
    Code:
    import string fieldname;
    If you want, you can then convert to a specific type:
    Code:
    import string fieldname;
    float fField;
    
    fField = fieldname;
    I'm not sure why the import-to-a-type was not implemented, but I'm sure I had good reason at the time: I think it was probably the problem of handling errors - what happens if you import an alpha into a float?

    Often, users (and spammers) will put junk into fields.

    However, I think it's an opportunity for validating data during the import, so this feature will get implemented in a future version.


    Quote Originally Posted by aaron_w View Post
    I can't think of why I'd want to at present, but can you define functions and/or import your own functions?
    Not yet, but the syntax will be available to define your own functions.

    You can import functions that you write in PHP. It's quite complicated though, and I need to document it along with everything else.

    The long-term idea is that developers will be able to write useful PHP functions that you can import into your computations.

    Of course, at a certain point, it may be a case of "why don't you just use PHP and do these things yourself?"
    Absolutely. And that's the marketing challenge with the Computation Module.

    The answer is really this: the code you write for the Computation Module is completely safe. It will never be a security vulnerability (subject to the imported functions, of course; which is another challenge.)

    In effect, the computations live in their little sandbox. Also, writing PHP or any other general purpose language is difficult. You need to learn a lot to get started and non-programmers can get into all sorts of mess. Even "real programmers" easily create security vulnerabilities in general languages.

    The Computation Module, on the other hand, aims to be simple - if you can understand basic types, and if statements, and write a simple equation, you're fit to go.

    But I have been quite impressed by this little form handling framework and it does take some of the regular things you do with forms (error handling, input validation, confirmations, multi-pages, etc) much easier.
    Thanks, it's definitely got potential.

    BTW, it was originally written to enable generic access to the GeoIP module.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  7. #27
    Join Date
    Apr 2008
    Posts
    23

    Default Re: Help with Computation

    OK, another question here.

    Can I do complex conditionals? IE, is there some way to do AND and OR in the computation?

    such as

    Code:
    if (qty_Item1 < 1) and (qty_Item2 < 1)
    {
     // something
    }
    Also, can comparisons be inverted? Can I use != or !< or something?

    And one more thing ---

    When I use the FMUserError() function to throw an error from the module, it shows the error message to the User. But, it doesn't seem to tell me the error message in the alert email it sends me.

    All I seem to get is:

    Code:
    The following error occurred in FormMail :
    fmcompute_usererrors
    Error=One or more errors occurred in your form submission
    Is that by design or am I possibly doing something wrong here?

    Thanks --

    Aaron

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

    Default Re: Help with Computation

    Hi,

    [quote=aaron_w;10792]
    Can I do complex conditionals? IE, is there some way to do AND and OR in the computation?

    such as

    Code:
    if (qty_Item1 < 1) and (qty_Item2 < 1)
    {
     // something
    }
    Yes. "and" is "&&" (which for HTML validation you may need to enter as &amp;&amp; - we need to provide a synonym) and "or" is "||"

    For example:
    Code:
    if ((qty_Item1 < 1) && (qty_Item2 < 1))
    {
     // something
    }
    or without the redundant parentheses:
    Code:
    if (qty_Item1 < 1 && qty_Item2 < 1)
     {
      // something
     }
    And here's a more complex one:
    Code:
    if ((item1_name == '' || qty_Item1 < 1) && (item2_name == '' || qty_Item2 < 1))
     {
       FMUserError('please select at least one item');
     }

    Also, can comparisons be inverted? Can I use != or !< or something?
    Yes, here are the supported operators:
    Code:
    == equals
    != not equals
    > greater than
    >= greater than or equal
    < less than
    <= less than or equal
    Note that the opposite of < is >=, the opposite of > is <=.

    When I use the FMUserError() function to throw an error from the module, it shows the error message to the User. But, it doesn't seem to tell me the error message in the alert email it sends me.

    All I seem to get is:

    Code:
    The following error occurred in FormMail :
    fmcompute_usererrors
    Error=One or more errors occurred in your form submission
    Is that by design or am I possibly doing something wrong here?
    It's implemented to only show the "headline" error in the alert, not all the details.

    That could certainly be changed in a future version.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  9. #29
    Join Date
    Apr 2008
    Posts
    23

    Default Re: Help with Computation

    Alright,

    Thanks again for your help and further documentation

    Note that the opposite of < is >=, the opposite of > is <=.
    Yes, thanks for clarifying my thinking there

    Quote Originally Posted by russellr View Post

    It's implemented to only show the "headline" error in the alert, not all the details.

    That could certainly be changed in a future version.
    I guess it would be useful to know which errors were triggered.

    I find that since I have the computation module, it's easier to write some of the more complex validations there rather than in a "conditions" statement.

    Aaron

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, 05:39 AM
  2. How to do simple computation
    By pbrienesse in forum HOWTO Guides and Tips
    Replies: 2
    Last Post: 22-Jan-2009, 06:40 PM
  3. Do I need the FormMail Computation Module?
    By smaynar in forum FormMail Computation Module
    Replies: 2
    Last Post: 21-Oct-2008, 03: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, 06:58 PM
  5. derivative, computation and order_id
    By kreon in forum Community Support
    Replies: 1
    Last Post: 17-Oct-2006, 08: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
  •