I want to create a price quote page using Chronoforms, by calculating the values that are submitted in the form. I've got the email to work, and the thank you page displays, but the variables are not appearing correctly. What am I doing wrong?
I put the calculations in the Custom Code - Before Email(s):
Then I put this in the Show Thanks Message:
In both the email as well as the thank you page, the result shows nothing for the values.
Help...
I put the calculations in the Custom Code - Before Email(s):
<?php
// Get values from the form
$recipient = $_POST['email'];
$hours_needed = isset($_POST['hours_needed']) ? intval($_POST['hours_needed']) : 0;
$property_size = isset($_POST['property_size']) ? intval($_POST['property_size']) : 0;
$property_type = isset($_POST['property_type']) ? intval($_POST['property_type']) : 0;
$uniform_type = isset($_POST['uniform_type']) ? intval($_POST['uniform_type']) : 0;
$guards = isset($_POST['guards']) ? intval($_POST['guards']) : 0;
$guard_type = isset($_POST['guard_type']) ? intval($_POST['guard_type']) : 0;
$extras = isset($_POST['extras']) ? intval($_POST['extras']) : 0;
$name = isset($_POST['name']) ? intval($_POST['name']) : 0;
// Define some constants to be used later
define('unarmed', 11.0);
define('armed', 19.0);
define('casual_uniform', 200.0);
define('tactical_uniform', 280.0);
define('corporate_uniform', 200.0);
define('residential', 0.2);
define('commercial', 0.25);
define('corporate', 0.35);
define('government', 0.3);
define('event', 0.2);
define('guardscan', 600.0);
define('golfcart', 2000.0);
// Do our calculations
$hourly_rate_low = (((((($guard_type + ($guard_type * 0.08) + ($guard_type * 0.04) + ($guard_type * 0.01)) * $hours_needed) * 52) + ((($property_size * 0.01) / $guards) + (($uniform_type * 2) * $guards) + 3600 + 56 + $extras)) / 52) / $hours_needed);
$monthly_rate_low = (((($guard_type + ($guard_type * 0.08) + ($guard_type * 0.04) + ($guard_type * 0.01)) * $hours_needed) * 52) + ((($property_size * 0.01) / $guards) + (($uniform_type * 2) * $guards) + 3600 + 56 + $extras)) / 12;
$hourly_rate_high = $hourly_rate_low * 1.15;
$monthly_rate_high = $monthly_rate_low * 1.15;
$setup_fee_low = $monthly_rate_low * 0.1;
$setup_fee_high = $monthly_rate_high * 0.1;
?>
Then I put this in the Show Thanks Message:
<h2>Requested Quote</h2>
<p>Hi <?=$name;?>,</p>
<p>Thanks for requesting a quote. Here you go:</p>
<table style="padding:10px;">
<thead>
<tr>
<th>Description</th>
<th>Cost</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding:10px;">Hourly rate</td>
<td style="padding:10px;">$<?=$hourly_rate_low;?> - $<?=$hourly_rate_high;?></td>
</tr>
<tr>
<td style="padding:10px;">One time setup fee</td>
<td style="padding:10px;">$<?=$setup_fee_low;?> - $<?=$setup_fee_high;?></td>
</tr>
<tr>
<td style="padding:10px;">Monthly charge</td>
<td style="padding:10px;">$<?=$monthly_rate_low;?> - $<?=$monthly_rate_high;?></td>
</tr>
</tbody>
</table>
In both the email as well as the thank you page, the result shows nothing for the values.
Help...
Hi TheAmazingZar ,
The problem here is that the variables' scope is limited to the single code box. So they aren't transferred between boxes.
The simplest answer is to copy the code from the Custom Code box into the Show Thanks Message box; then delete the Custom Code box.
There are other ways of transferring variable data if you need to: add it to the form data; save it in the user session; set the variable to have global scope, etc. but the copy and paste approach should work best here.
Bob
The problem here is that the variables' scope is limited to the single code box. So they aren't transferred between boxes.
The simplest answer is to copy the code from the Custom Code box into the Show Thanks Message box; then delete the Custom Code box.
There are other ways of transferring variable data if you need to: add it to the form data; save it in the user session; set the variable to have global scope, etc. but the copy and paste approach should work best here.
Bob
Maybe I should have explained that I'm very new to all this programming stuff.
I'm trying to calculate the values (or assign digits for text inputs before calculating), then returning the results. Keep in mind that I also want to email these same results to the user.
Is my code correct? If so, where should the pieces go to email and show (print) the final result correctly?
I'm trying to calculate the values (or assign digits for text inputs before calculating), then returning the results. Keep in mind that I also want to email these same results to the user.
Is my code correct? If so, where should the pieces go to email and show (print) the final result correctly?
Hi TheAmazingZar,
Sorry, I've got no idea if your code is correct. From a quick look it appears to be OK PHP but I haven't checked it line by line.
Have you copied and pasted it as I suggested? Does it give you the results you expect?
Bob
Sorry, I've got no idea if your code is correct. From a quick look it appears to be OK PHP but I haven't checked it line by line.
Have you copied and pasted it as I suggested? Does it give you the results you expect?
Bob
I copied and pasted there, and it still won't work.
Hi TheAmazingZar,
I don't see any PHP or HTML errors in the code but I haven't checked it in detail.
There are a couple of possible problems though. Please replace the $ in the text with the HTML Entity; you might also have a problem with the short-form PHP tags, try replacing them with the full form.
So:
becomes
Bob
I don't see any PHP or HTML errors in the code but I haven't checked it in detail.
There are a couple of possible problems though. Please replace the $ in the text with the HTML Entity; you might also have a problem with the short-form PHP tags, try replacing them with the full form.
So:
$<?=$hourly_rate_low;?>
becomes
$<?php $hourly_rate_low; ?>
Bob
Still didn't work...
😟
😟
Nothing?
Hi TheAmazingZar,
I'm not sure what you are expecting? My job here is to help people with ChronoForms problems - not to debug PHP and HTML that isn't working.
That said, I have taken another quick look and suggest that you check that the opening and closing brackets match up. I'm not sure that they do in either of the long expressions.
Bob
I'm not sure what you are expecting? My job here is to help people with ChronoForms problems - not to debug PHP and HTML that isn't working.
That said, I have taken another quick look and suggest that you check that the opening and closing brackets match up. I'm not sure that they do in either of the long expressions.
Bob
Ok. I understand. I was hoping I could do some calculations based on form values, then display and email them.
I didn't wanna write my own solution, but I guess I'll have to, since I can't do it in Chronoforms. Thanks for all your help though, at least we tried.
😟
I didn't wanna write my own solution, but I guess I'll have to, since I can't do it in Chronoforms. Thanks for all your help though, at least we tried.
😟
This topic is locked and no more replies can be posted.