Hi,
I am trying to use some PHP to take a value from a form input, do some math and produce another value that I can then put into an email action for my form. For example, the person selects 3 items from a drop down on the form. This value is now in {data: numberItems}. In the email action, I want to put some PHP code that will read the number of items and then produce a cost which I can then echo in the email HTML.
I tried this:
<?php
$numberItems = $this->data['numberItems'];
if ($numberItems=1){
$totalAmount =100;
}
if ($numberItems=2){
$total Amount =200;
}
?>
Then in my HTML email, I used this to try to show the total amount owed: <html><p>$<?php echo $totalAmount;?></p></html>
I used the debugger to see what was going on. It doesn't tell me anything. All I see is this at the start of my email: data['numberItems'];
I tried parantheses instead of brackets. I tried $form-> instead of $this-> (but I know this is not for chronoformsv6). This has to be doable. I just must not be accessing the form data correctly.
Please let me know what you think. Thank you in advance for any tips.
Erik
I am trying to use some PHP to take a value from a form input, do some math and produce another value that I can then put into an email action for my form. For example, the person selects 3 items from a drop down on the form. This value is now in {data: numberItems}. In the email action, I want to put some PHP code that will read the number of items and then produce a cost which I can then echo in the email HTML.
I tried this:
<?php
$numberItems = $this->data['numberItems'];
if ($numberItems=1){
$totalAmount =100;
}
if ($numberItems=2){
$total Amount =200;
}
?>
Then in my HTML email, I used this to try to show the total amount owed: <html><p>$<?php echo $totalAmount;?></p></html>
I used the debugger to see what was going on. It doesn't tell me anything. All I see is this at the start of my email: data['numberItems'];
I tried parantheses instead of brackets. I tried $form-> instead of $this-> (but I know this is not for chronoformsv6). This has to be doable. I just must not be accessing the form data correctly.
Please let me know what you think. Thank you in advance for any tips.
Erik
$this->data("field name", "default if not found");
Also : if($numberItems == 1) {
Need to get your syntax right.
Need to get your syntax right.
ALSO ALSO why would you use a series of if statements for that, instead of
If you want a value that you then can use in another action later on in the same event, you need to RETURN the value. So
Then if your php action is called for example "get_total_cost" then in your email you would put
<p>${var:get_total_cost}</p>
$cost = 100;
echo $this->data("numberItems", 0) * $cost;
If you want a value that you then can use in another action later on in the same event, you need to RETURN the value. So
$cost = 100;
return $this->data("numberItems", 0) * $cost;
Then if your php action is called for example "get_total_cost" then in your email you would put
<p>${var:get_total_cost}</p>
This topic is locked and no more replies can be posted.