Forums

Assigning variable to a data field

lcbarker 19 Oct, 2013
I have a radio button with 4 choices. Once the choice is made I want a dollar figure assigned to a variable. Then I want the variable assigned to a data field.

In Custom Code I have this php code:
<?php
$exhiblevel = $form->data['ex_level'];

if ( $exhiblevel == 'ex_business') {
	$ex_level_amt = 185;
} elseif ( $exhiblevel == 'ex_sponsor' ) {
	$ex_level_amt = 0;
} elseif ( $exhiblevel == 'ex_non-profit' ) {
	$ex_level_amt = 90;
} elseif ( $exhiblevel == 'ex_resource' ) {
	$ex_level_amt = 25;
}

$form->data['ex_test_amt']=$ex_level_amt;

?>


The dollar value gets assigned properly (I have tested with an echo) but I cannot get the value assigned to 'ex_test_amt'. Using a debug in Submit shows the ex_test_amt field empty.

I have also tried a js (which I've constructed from various examples) in OnLoad:
window.addEvent('domready', function() {
  $('ex_level').addEvent('change', ex_test_amt);
});
//Dropdown values to prices
var exhiblevel = new Array();
exhiblevel["ex_business"]=185;
exhiblevel["ex_sponsor"]=0;
exhiblevel["ex_non-profit"]=90;
exhiblevel["ex_resource"]=25;

function exhibit_total(){
  var ex_total = parseInt(exhibvalue);
    $('ex_test_amt').value = ex_total;
}


Again, using a debug in Submit shows the ex_test_amt field empty.

What am I missing? Why is the variable exhibvalue not being assigned to ex_test_amt.

Thanks.
GreyHead 20 Oct, 2013
Hi lcbarker,

The PHP looks OK to me. I assume that it is in the On Submit event?

Please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here.

The JavaScript won't work because this line
$('ex_level').addEvent('change', ex_test_amt);
calls a function ex_test_amt that doesn't exist. Try putting exhibit_total in its place.

Bob
lcbarker 21 Oct, 2013
Hi Bob,

Thanks for looking at this.

Changed the JS to
window.addEvent('domready', function() {
  $('ex_level').addEvent('change', exhibit_total);
});
//Dropdown values to prices
var exhiblevel = new Array();
exhiblevel["ex_business"]=185;
exhiblevel["ex_sponsor"]=0;
exhiblevel["ex_non-profit"]=90;
exhiblevel["ex_resource"]=25;

function exhibit_total(){
  var ex_total = parseInt(exhibvalue);
    $('ex_test_amt').value = ex_total;
}

It produced this result in debug:

Array
(
[option] => com_chronoforms
[chronoform] => Test_Form
[event] => submit
[ex_level] => ex_non-profit
[ex_outlet] =>
[ex_exlunch_num] =>
[exhibit_level] =>
[ex_amt] =>
[ex_test_amt] =>
[input_submit_12] => Submit
[16a61ee67f1d0967f2f97f14e8758a3a] => 1
)



Took out the JS and tried the php in a custom code in Submit and ran the debug as I had done before. But lo and behold, this time it worked. You have great authority in your voice from such a distance to cause this code to suddenly work. I should have written earlier!

I have the php working but if you have any comments on how to get the js to work I'd love to hear them. Enable JS Validation is set to Yes. The source code for the page shows that mootools-core.js, mootools-more.js, jquery.min.js, jquery.conflict.js, and bootstrap.min.js are all loaded.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger