• Resolved elmirasln

    (@elmirasln)


    Hi,

    I’m building a form in cff. In a specific part, the users have to enter the sides and area of a space. FYI, this area is the accurate one gonna be used in future calculations. but I need an error for the case they make mistake. for example they enter 6 & 10 as sides but 600 as area. So i have to calculate the area with a tolerance of 3% myself to double check.

    The problem is I don’t know how to define the error. if the entered area is close to my calculation, the process should go on, but if it’s not, I need to stop the process and ask the user to check his numbers. I know the condition, but don’t know the TRUE or FALSE definition in this case.

    Would you please help me?

    • This topic was modified 1 year ago by elmirasln.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @elmirasln

    Thank you very much for using our plugin. I’ll try to describe the process with a hypothetical example.

    Assuming your form has three number fields for width, length, and area (fieldname1, fieldname2, and fieldname3, respectively).

    You can insert a calculated field in the form and enter the equation:

    (function(){
       let value = fieldname1*fieldname2;
       if( value*3/100 < ABS(value - fieldname3)) {
          return 'Please check your numbers they are incorrect';
       } else {
          return 'Excellent !!!';
       }
    })()

    Best regards.

    Thread Starter elmirasln

    (@elmirasln)

    Thank you so much for your support. It’s really heart-warming.

    Actually this solution made it a lot easier but not completed I guess. Because no matter if the user gets the message “correct your numbers” or “excellent”, he can click on “next page” button and continue filling other fields. Can I prevent him doing that? Like only if he gets “excellent” he can continue, otherwise the field turns red and necessary to be corrected.

    What’s this programming language you used btw? I like to learn more.

    Plugin Author codepeople

    (@codepeople)

    Hello @codepeople

    The equations are evaluated on the client side (the browser). So, they are implemented in Javascript.

    If you have a multipage form and want to allow the user to continue to the next page only if the equation’s result is Excellent, you can edit the equation as follows:

    (function(){
       let value = fieldname1*fieldname2;
       if( value*3/100 < ABS(value - fieldname3)) {
          jQuery('.pbNext').hide();
          return 'Please check your numbers they are incorrect';
       } else {
          jQuery('.pbNext').show();
          return 'Excellent !!!';
       }
    })()

    Best regards.

    Thread Starter elmirasln

    (@elmirasln)

    It worked! Thanks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘compare 2 numbers and error user if they aren’t close’ is closed to new replies.