Forums

php variable to email not working

glens1234 29 May, 2013
Hi. It is rare for me to ever touch php code however, what i am trying to do should be fairly straight forward. I am trying to output the variable "$deposit" to the email template using {deposit}. However, it doesn't work. Nothing is displayed in the email. I have looked at several related forum posts but im none the wiser.

The customer code action is positioned after the handle array action in the onsubmit event.
The mode of the custom code is set to "View"
The variable echo's to the screen after submit so i know it has a value.

Below is my code...

<?php
$pkg_selected = $form->data['package_selected'];
$num_of_persons = $form->data['persons'];
$spa_booking_total = $pkg_selected * $num_of_persons;
$deposit = 2000;
$deposit = $num_of_persons * $deposit;
echo $deposit;
?>


Any ideas what i am doing wrong?
glens1234 30 May, 2013
ok. i think i need to add a hidden form field to the form and the write the variable to that field
i.e $form->data['hidden_input'] = $deposit;

And then display it using {hidden_input}

i cant test it yet because my server is down.

Thanks
GreyHead 30 May, 2013
Hi glens1234,

Please try replacing your first code with this version:
<?php
$form->data['spa_booking_total'] = $form->data['package_selected'] * $form->data['persons'];
$form->data['deposit'] = $form->data['persons'] * 2000;
?>

Then you can use {spa_booking_total} and {deposit} in the Email template and/or the Thank you page.

Bob
glens1234 30 May, 2013
ok thanks. Yes that looks more intuitive😉
This topic is locked and no more replies can be posted.