Hello,
I am trying to populate the value in the field based on the value entered, in this case date, dynamically. I am trying to calculate prorated dates till the end of the month and based on that to calculate the price.
The problem is, I don't seem to find the way how to make the value appear without the page refreshing. Any workarounds?
I appreciate any help you can give me.
Thanks,
Yulia
Here is the code I am starting of:
add_filter('gform_field_value_prorated_days', 'get_prorated_days');
function get_prorated_days($form){
$start_date = $_POST["input_5"]; //NOTE: replace 2 with your actual start date input ID
$arr = explode('/', $start_date);
//$end_date = date('%m/%t/%Y', strtotime($arr[0].'/01/'.$arr[2])); //
$ldom = date('%t', strtotime($arr[0].'/01/'.$arr[2]));
$end_date = $arr[0]."$ldom".$arr[2];
$days = gf_date_diff($start_date, $end_date);
$arr2 = explode('|', $_POST["input_6"]);
$daily_rate = round($arr2[1]/$ldom);
$pamt = floatval($daily_rate) * floatval($days);
//$_POST["input_17"] = floatval($daily_rate) * floatval($days);
return $pamt;
}
function gf_date_diff($start, $end) {
$start_ts = strtotime($start);
$end_ts = strtotime($end);
$diff = $end_ts - $start_ts;
return round($diff / 86400);
}