Forums

Wordpress Form Using Chronoformsv6 - How to read form data with PHP

luxhodge 16 Aug, 2018
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
healyhatman 17 Aug, 2018
$this->data("field name", "default if not found");
healyhatman 17 Aug, 2018
Also : if($numberItems == 1) {

Need to get your syntax right.
healyhatman 17 Aug, 2018
ALSO ALSO why would you use a series of if statements for that, instead of
$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>
luxhodge 17 Aug, 2018
Thanks for the tips healyhatman. I must have more syntax messed up because I am getting nada. I will keep looking at it.

Thanks again.
Erik
This topic is locked and no more replies can be posted.