Forums

Paypal and Value Addition

tbob22 04 Jun, 2013
I've been trying to figure out how to get Chronoforms to add up multiple values (radio box and then an extras checkbox) and insert it into the amount for the Paypal URL and haven't had any luck so far.

I've tried a few different javascript methods on load and on submit and nothing has worked so far, I just end up with $0 as the amount in Paypal.. If I remove the Extras boxes and set it to get the value from the radio fields it works great.

I'd like to keep the form wizard working to make edits easy down the road. Thanks!😀
GreyHead 04 Jun, 2013
Hi tbob22,

The secure way to do this is to run the calculation using PHP in a Custom Code action in the on Submit event. The action needs to be before the PayPal action.

You can also do a calculation in JavaScript in the On Load event as this can make the result immediately visible to the user, but you should still check with PHP after the form is submitted.

Bob
tbob22 04 Jun, 2013
Would you know of some examples that I could build off of? I don't need it to be visible to the user. It'll show on the Paypal page anyway. Thanks!
GreyHead 05 Jun, 2013
Hi tbob22,

<?php
$form->data['amount'] = $form->data['input_1'] + $form->data['input_2'];
?>

Bob
tbob22 06 Jun, 2013
Thanks! That worked great. I had to separate the check boxes to get them to calculate right (if multiples were selected, it would only calculate the first one).
<?php
$form->data['amount'] = $form->data['amount'] + $form->data['extra1'] + $form->data['extra2'] + $form->data['extra3'];
?>

Amount being the radio boxes and the amount field set in Paypal. Extra1/2/3 being the checkboxes.

I also tried setting the radio boxes to the id/name "package" with the first $form->data[''] + set to package as well, but it would only calculate the checkboxes for whatever reason.

For anyone else trying to do something like this, Paypal should be the last event and the PHP should be second last, otherwise you'll end up on a blank page after submitting.
GreyHead 06 Jun, 2013
Hi tbob22,

Checkbox groups and multiple Drop-Down select elements will return array results, you can get the value using $form_data['group_name']['element_id']

Use a Debugger action to see the correct names for your form.

Bob
This topic is locked and no more replies can be posted.