Forums

eval()'d code on line XX

Marysia 03 Sep, 2015
Hello,
first of all I need to say I have very little knowledge about php.

I have a form which behave differently dependently on user choices (some questions determines what questions users see later). For example I ask user if (s)he has different or the same delivery address. If the answer is "yes, address is the same", user doesn't even see fields about delivery address.
Form results are send by mail. I think the mail would be much more readable if I could use some if/else statements because I don't see any reason to send for example empty delivery address.
So I wrote something like this:
<?php
if ({Address_checkbox}=0)
    print "<td>Delivery address is the same!</td>";
else
    print "<td>Delivery address is diffrent!</td>";
?>

I would like to build it more, ad fields end so on, but firstly I've just checked if it is fine. It's not. I've got an email with info:
Parse error: syntax error, unexpected '{' in /domains/....../components/com_chronoforms5/chronoforms/actions/email/email.php(127) : eval()'d code on line 20

Probably I would have thought it's my mistake, but before I tried to build an array and I copied code from HERE it I've got similar effect: "eval()'d code on line XX". End I almost literally copied and pasted, because my field is named "color"...

Any advices?
GreyHead 03 Sep, 2015
Hi Marysia,

You can't use the {input_name} syntax in PHP, please try this instead:
<?php
if ( $form->data['Address_checkbox'] === 0)
    print "<td>Delivery address is the same!</td>";
else
    print "<td>Delivery address is different!</td>";
?>
I suggest that you don't use 0 as a checkbox value as it can cause problems, better to use a short text string if that's OK.

Bob
Marysia 09 Sep, 2015
Hi,
thank you for your answer, I will play with it somewhere at night😉

If 0 can cause a problems, why it is a default option?

Sorry for not reacting for so long, but notification about your answer were classified as spam and I didn't see it.

Regards,
Marysia
GreyHead 09 Sep, 2015
Hi Marysia,

Good question - I think Max was trying to keep it simple and didn't realise the implications.

Bob
Marysia 01 Jan, 2016
Long time no see😉 but as I'm finally here I can say that I followed your advice and I've build an e-mail template as I wanted🙂

One tricky thing was type of the data - 0 or 1, or 10 seems to be strings, not numbers, and in comparisons I needed to write it like that:
$form->data['Address_checkbox'] === '0'
GreyHead 03 Jan, 2016
Hi Marysia,

Good to see that you got it working. As I said earlier - I suggest that you don't use 0 and 1 as values as they can cause problems.

Bob
Marysia 03 Jan, 2016
Hi Bob,
as the name says 'Address_checkbox' is a checkbox and to be precise I wrote like that about it:
<?php
if ( $form->data['Address_checkbox'] === '1')
    print "Delivery address is different!";
else
    print "Delivery address is the same!";
?> 

I have no idea what are default values for checked and unchecked field, but this code works just fine.

I have 0 in 'amount' field and it has to be there to mean exactly it, zero...
This topic is locked and no more replies can be posted.