PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

prorated dates question

  1. NextFab
    Member

    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);
    }
    Posted 10 years ago on Tuesday August 7, 2012 | Permalink
  2. Do you have this online somewhere so we can take a look at it? What happens with this code currently? And are you trying to pre-populate the form with the number of days left, so you can show the price, BEFORE the form is submitted?

    Posted 10 years ago on Wednesday August 8, 2012 | Permalink
  3. NextFab
    Member

    Correct. I need to display the number of days left in the month, before the form is submitted.
    I don't have the form online yet. I running it on test server.

    Posted 10 years ago on Wednesday August 8, 2012 | Permalink
  4. Can you export the form as XML please and email it to me at chris@rocketgenius.com - thank you. Please reference this topic in your email.

    Posted 10 years ago on Thursday August 9, 2012 | Permalink