This topic is locked

Using Default Value in Visual Editor

9/19/2011 5:52:05 PM
PHPRunner General questions
D
DigitalDean8 author

Hello, I am trying to use the "Default Value" function in the visual editor to do a simple calculation for a field further down the page (tab order).
My code is a simple one liner as follows: $data["Job_Total"]-$data["Job_Cost_Total"]-$data["Job_Overhead"]
The good new is that it works and the calculations correctly appear. The bad news is that I can't save the form without getting an error
What am I doing incorrectly here?

Sergey Kornilov admin 9/19/2011

What's the error message?
Where exactly do you put this code ($data["Job_Total"]-$data["Job_Cost_Total"]-$data["Job_Overhead"])?

D
DigitalDean8 author 9/19/2011



What's the error message?
Where exactly do you put this code ($data["Job_Total"]-$data["Job_Cost_Total"]-$data["Job_Overhead"])?


I am putting it into the "Default Value" entry box in the Visual Editor and the error message is: "Undefined Variable: Data"

C
cgphp 9/20/2011

"Default value" for input text field in add and edit page, should be a valid PHP expression but you can't access from php values of other fields. Use javascript instead. Check this article: http://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm

D
DigitalDean8 author 9/20/2011



"Default value" for input text field in add and edit page, should be a valid PHP expression but you can't access from php values of other fields. Use javascript instead. Check this article: http://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm


Actually the code "works" on the page and correctly calculates the values and places them in the fields. The only issue is that I am unable to SAVE that form with those values so it "mostly" works, just not all the way. I will investigate the Javascript you recommend though.

Sergey Kornilov admin 9/20/2011

It's not easy to understand how this code works and, at the same time, produces "Undefined Variable: Data" error message. Probably you can elaborate.