Hi there,
I'm building a form to allow parents to pay for camps their kids will attend. Since every parent might have more than 1 child I need to look that up in the database first and then dynamically list their children beside a checkbox. It seems I can do this using the following code (I'm currently not using a DB query while testing)
add_filter('gform_pre_render_1', 'swp_populate_attendee_list');
function swp_populate_attendee_list($form){
foreach($form['fields'] as &$field){
if( $field['cssClass'] == 'attendees-child' ) {
$choices[] = array( 'text' => '1', 'value' => 1, 'price' => '1.00' );
$choices[] = array( 'text' => '2', 'value' => 2, 'price' => '2.00' );
$field['choices'] = $choices;
}
}
return $form;
}
Problem is, if I don't choose the first checkbox I'm not sent to paypal (confirmation message shows up instead). If I choose only the first checkbox I'm redirected to paypal but I get the wrong total. If I choose both checkboxes I only see the first option listed but the total is wrong again.
Here's the form:
http://pine.switchwp.com/?page_id=6
The product field is hidden and with a value set to $0. Since I'm attempting to use the options as the actual products, the field type is set to calculation and in the formula box the option fields are added.
What's preventing the options from appearing correctly on the paypal page?
Another way to do this would be to set the price field to the cost of the camp and then allow the parents to choose which child(ren) will attend the camp which would automatically multiply the price by the number of checkboxes chosen. One way to do that would be to edit the query sent to paypal. Is there a way to do it on the form dynamically?