Currently people give their data, including their birthday and type of membership, and then at the end, the amount they have to pay, is shown.
I would like to update the membership selector, which is a dropdown, based on the current date, and the birthday the give.
We have four types of memberships:
Senior
Junior
Family
Support
The two first are influenced by the birthday they give, and they are all influenced by the current date.
What I would like is to update the memberships, so it autmatically shows the correct Senior/Junior, and the amount is shown at the same time.
Something like
Senior (750)
Family (1500)
Support (100)
or if the person is young
Junior (500)
Family (1500)
Support (100)
The Family and Senior / Junior are also influenced by the current date, ie. for each quarter it is less as the memberships all run from 1/1->31/12
I can't seem to be able to do anything automatically from the datepicker? Is that true? Or can I do a workaround somehow?
I have the calculation of the fee in PHP.
This is private content
First of the dropdown field called 'type' is not populated. Secondly, I would like for the code to only show the right 'Senior' / 'Junior', and not both.
This is private content
I only see one ChronoForms question in here (the rest are about your specific code).
You can call a JavaScript function when a datepicker selection is made using the On date selected box in the Datepicker element settings. Just add the function name there.
I guess you will want that function to make some kind of Ajax call to get the data updated - or maybe it would be easier to load the data as JavaScript when the form loads.
Bob
echo json_encode($subs[$form->data["type"]]);
?
I've placed it in the 'onLoad' action?
This explains it, so that even I think I understand it 😀
So I've built this small code:
$Subs = array(
'[0]' => array('medlem' => 'Enkeltperson', 'beskrivelse' => $Senior.' / '.$Junior),
'[1]' => array('medlem' => 'Familie' , 'beskrivelse' => $Family),
'[2]' => array('medlem' => 'Støtte' , 'beskrivelse' => 'Støtte (kr. 100)'),
) ;
print_r(array_values($Subs)) ;
$form->data('medlemstyper') = $Subs ;
But when I use it I get this error:
Can't use method return value in write context
It doesn't calculate with the birthday, but at least it now calculates from the current date when the form is loaded.
This worked as it should:
$form->data['medlemstyper'] = array(
'[0]' => array('medlem' => 'Enkeltperson', 'beskrivelse' => $Senior.' / '.$Junior),
'[1]' => array('medlem' => 'Familie' , 'beskrivelse' => $Family),
'[2]' => array('medlem' => 'Støtte' , 'beskrivelse' => 'Støtte (kr. 100)'),
) ;
