• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Cannot calculate with values in a dropdown list

Cannot calculate with values in a dropdown list 10 years 6 months ago #29246

  • bonobo1er
  • bonobo1er's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 1
Hello all

I am brand new on this forum. I have been searching for an answer to my issue but found nothing. So I first apologize if my request has already been answered.

Here is my problem : I would like to calculate a PMT (payment for a loan based on constant payments and a constant interest rate) based on input in my RS Form. One of the formula's parameters is the number of payment but it is a free input. I would like to handle it with a dropdown value list.

So my custom script would be : "$_POST('form')('pmt') = $_POST('form')('amount') * $_POST('form')('periods');"

where:
$_POST('form')('pmt') is a hidden field I will use in the Thank you message.
$_POST('form')('amount') is a numeric input field in my form
$_POST('form')('periods') is a dropdown list where I manage numeric values.

But the calculation fails. If I replace the "period" with a numeric input, it works. So I guess my calculation fails because the dropdow sends non numeric formatted values even if the values are numeric.

Do you have an idea on how I could solve this issue ?

Thank you very much in advance for your help.

Bonobo
Last Edit: 10 years 6 months ago by bonobo1er.
The administrator has disabled public write access.

Cannot calculate with values in a dropdown list 10 years 6 months ago #29249

  • silviup
  • silviup's Avatar
  • OFFLINE
  • Moderator
  • Posts: 309
  • Thank you received: 49
Hello Bonobo,

There are a few things that are wrong with your described approach:

1. You cannot add form fields in the 'Thank You' message. Even if you edit the 'Thank You' message's code and add the HTML code for a hidden field, it will not get stored in the $_POST variable and, therefore, you will have no access to the value it contains.

2. You are calling the $_POST variable, with all of its contents, in the wrong way. The correct syntax would be:
$_POST['form']['pmt']
$_POST['form']['amount']
$_POST['form']['periods'][0] (default syntax for dropdowns)

3. Make sure to set up the dropdown items (for the 'periods' field) as follows:

value|text

In other words, if you have 2 products, Product 1 that costs 5 $ and Product 2 that costs 10 $, you should define your items like this:

5|Product 1
10|Product 2

4. Make sure to add the custom script in the proper scripting area: Components >> RSForm!Pro >> Manage Forms >> edit your form >> Properties >> PHP Scripts >> Script called on form process.

A much simpler approach would be to just use RSForm!Pro's 'Calculations Feature', you can read about it here:

www.rsjoomla.com/support/documentation/v...rm-calculations.html

The article also contains a link to a video tutorial that will shed light on the usage of form calculations.
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Cannot calculate with values in a dropdown list 10 years 6 months ago #29250

  • bonobo1er
  • bonobo1er's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 1
Hello Silviup,

1 - It is possible to add forms fields in the Thank You message. I tried and it worked.
$thankYouMessage .= 'Based on supplied information, your PMT is '.$_POST('form')('pmt');

2 - I have replaced the brackets with "(" and ")" in this topic because they do not appear in the forum. But do not worry, there are no syntax error in my scripts. ;)

3 - This is exactly what I did. ;)

4 - This is also exactly what I did. ;)

5 - I also tried to use the calculations but:

--> The final formula is too complex to be built with caclulation (it contains exponentials)
--> Simple operations drive me to errors when I use the dropdown values. :dry:

Thank you for your help.
The administrator has disabled public write access.

Cannot calculate with values in a dropdown list 10 years 6 months ago #29252

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
As my colleague stated,
$_POST['form']['periods'][0]

is the proper syntax for dropdowns, use the [0] index.

Try it and let us know
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 10 years 6 months ago by cosmin.cristea.
The administrator has disabled public write access.

Cannot calculate with values in a dropdown list 10 years 6 months ago #29255

  • bonobo1er
  • bonobo1er's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 1
Hi Cosmin

It works !!! :laugh: :laugh: :laugh:
I did not realize Silviup was indicating me that the statement "[0]" was missing.

Sorry Silviup,
And many thanks to both of you.

Bonobo.
The administrator has disabled public write access.

Cannot calculate with values in a dropdown list 10 years 6 months ago #29256

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
No worries, we are here to help as much as we can. I'm glad that you figured things out.

You can read more on PHP scripts and RSForm!Pro in these articles:
http://www.rsjoomla.com/support/documentation/view-article/76-custom-php-code.html
http://www.rsjoomla.com/support/documentation/view-article/602-php-scripts.html
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.

Cannot calculate with values in a dropdown list 10 years 6 months ago #29257

  • bonobo1er
  • bonobo1er's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 1
Thank you Cosmin,

Let me post my work here. It may help people willing to do the same.
I am currently using RSForm Pro to display a form which goal is to calculate a PMT, based upon the following parameters:

Asset Present Value field: pv (numeric)
Rate (use a monthly constant rate) field tx
Number of periods (in months) dropdown: nper
Asset Future Value (optional: usually equal to 0) field: fv (numeric)
Payment day (0 = begin of month; 1 = end of month). dropdown: nper

hidden fields : loan, var1, var2, var3

In the Script called on form process, write the following statements
$_POST['form']['var1'] = $_POST['form']['pv'] * (pow((1 + $_POST['form']['tx']), $_POST['form']['nper'][0])) + $_POST['form']['fv'];
$_POST['form']['var2'] = 1 + $_POST['form']['tx'] * $_POST['form']['typ'][0];
$_POST['form']['var3'] = (pow((1 + $_POST['form']['tx']), $_POST['form']['nper'][0]) - 1) / $_POST['form']['tx'];
$_POST['form']['pmt'] = $_POST['form']['var1'] / ($_POST['form']['var2'] * $_POST['form']['var3']);

In the Thank you message, write the following statements
$thankYouMessage .= 'Based on supplied information, your pmt is '.round($_POST['form']['pmt'],2);
$thankYouMessage .= ' euros';
$thankYouMessage .= '</br>';
$thankYouMessage .= 'Thank you';
Last Edit: 10 years 6 months ago by bonobo1er.
The administrator has disabled public write access.
The following user(s) said Thank You: cosmin.cristea
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!