Read a date make some calculations and write the value into another field of the form

Hello,

I am trying to make a form to sell lunches to our students. The flow is: the student chooses the start date for the lunch service, the end date is known (the end of the semester, read only populated date field).
The form calculates the number of days between the chosen date and the end date, minus weekends, public holidays and school holidays. Then it will multiply
the number of school days with the daily lunch price and the student will pay the total.

I have code in JS and PHP that calculates the school days, but what I can’t figure out is how do I get the start date, and after calculations, write the calculated school days into a read only number field.
If I want to dynamically populate a field (using gform_field_value_$parameter_name) I don’t think I can get the start date (as it is JS, executed on the client side, while the PHP from gform_field_value_$parameter_name is executed on the server side).
If I try to use gform_calculation_result, the calculation is made before the user chooses the start date.
How can I accomplish this, please?
Thank you!

Hi Alexandru,

You could use GP Date Time Calculator to count the number of weekdays between the dates.

We don’t have a ready solution for excluding the public and school holidays, however. If you’re a Gravity Perks customer, we could look into what it would take to add support for this. Just drop us a line.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.