calc element with empty values

vipzeus

Member
in my form i have a calc element where at begin my fields are empty and calc element does not work as well.

Code:
//Consumi
$consumi_f0 = '{simulatore___consumo_f0}';
$consumi_f1 = '{simulatore___consumi_f1}';
$consumi_f2 = '{simulatore___consumi_f2}';
$consumi_f3 = '{simulatore___consumi_f3}';
//Chiama il costo
$ccv = {simulatore};

return($ccv_label . ' : ' . $ccv .'  ' .'Euro'.' </br> '. $kh_f0_label. ' : ' .$spesa_bio).'  ' .'Euro';

how i can use a validation if elements of dependi for calculation are empty ?
 
Last edited:
Yes but i dont know how do with the right syntax

$function = {table___cascading_element}; (but its empty at begin because depend by other cascading or dbj

i tried

if ($function >0 ) {echo $function} not work

if ($function !=empty) echo $function } but not work

In fron end i have errors
 
My problemi is if im working in the exist rows where data is not empty , my form work but when go to add a new record ihave errors.
This because in my cdd are empty and my script does not work .
is it way to calc only if casading elements are not empty?
 
It would be useful if you post the errors.
is it way to calc only if casading elements are not empty?
Sure, use if (...)

$ccv = {simulatore};
or
$function = {table___cascading_element};

This is no valid php, it must be a variable or a string (something with '' or "").
If it should be an element placeholder something like
'{table___element}'
 
the error is
0 syntax error, unexpected token ";" with broken page.

PHP:
$consumi_f0 = '{simulatore___consumo_f0}';
//Chiama il costo amministrativo
$ccv = {simulatore___costo_ccv_offerta_al_mese};

}

The code above is what i have now and work if edit a row with exist records.
If add new record ' i m obtain the error above
 
Last edited:
On a side note, when I'm doing calculations I usually have default fallback values, especially when they start out empty.

$consumi_f0 = '{simulatore___consumo_f0}' > 0 ? '{simulatore___consumo_f0}' : 0;
$consumi_f0 = !empty('{simulatore___consumo_f0}') ? '{simulatore___consumo_f0}' : 0;
Or whichever appropriate/preferred condition check and appropriate/preferred fallback value technique...
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top