Forums

condition

ernst@volny.cz 29 Jul, 2019
how do I create a condition that if the field is empty, the row is written to the database?I can't write it using event switch or if condition
healyhatman 29 Jul, 2019
{data:fieldname/default_value_if_field_missing} which is slightly different to if the field is there but empty
Could always use a switch: {data.empty:fieldname} and in true put your default value and false just {data:fieldname}
ernst@volny.cz 29 Jul, 2019
I also invented a solution, but it doesn't work for me. can you advise me?
in logis PHP is
if($this->data["kurz"]  =='1'): $hop='1';
else : $hop='2';
endif;

return $hop;
and in event switcher: https://jmp.sh/A9bfJec, but I don't see the message
healyhatman 29 Jul, 2019
I don't see where you set $hop or gave it a value in the first condition
healyhatman 29 Jul, 2019
You sure did, which means it's not available outside of that else.
healyhatman 29 Jul, 2019
Answer
1 Likes
Either use a switch with conditions 1 and * (in that order) or
if($this->data("kurz"))
return 1;
else
return 2;

Or for your code
$hop = ''; // Set this outside of the condition
if($this->data('kurz') == 1)
$hop = 1;
else
$hop = 2;
return $hop;
ernst@volny.cz 30 Jul, 2019
Thanks a lot for your help, it works for me.
I wouldn't think of using parentheses instead of square brackets.
Also, because it was a deep night with us, I made other mistakes there.
GreyHead 30 Jul, 2019
1 Likes
Hi Ernst,

The difference in the syntax is because $this here is an object, not an array. There are some similarities but a lot of differences too. There's an article here that tries to explain it.

Bob
This topic is locked and no more replies can be posted.