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.

Default/Dynamic Value for Time

  1. Is it possible to insert a default value for a time field? I couldn't find any docs on this.

    I tried an array:

    add_filter('gform_pre_render_6', 'populate_each_product_reserve');
    function populate_each_product_reserve ($form){
       $choices2 = array(
                        array("text" => "HH", "value" => '6'),
                        array("text" => "HH", "value" => '00'),
                        );
    
        $inputs2 = array(
                        array("label" => "HH", "id" => 4.1),
                        array("label" => "MM", "id" => 4.2),
                    );
    
            foreach($form["fields"] as &$field){
               if($field["id"] == 4){
                $field["value"] = $choices2;
                $field["inputs"] = $inputs2;
                }
            }
    
        return $form;
    }

    I have tried some variations of the input and value labels for the array, but couldn't get it to go through. Any ideas?

    Posted 11 years ago on Thursday October 18, 2012 | Permalink
  2. I've asked the developers for their feedback on this one.

    Posted 11 years ago on Thursday October 18, 2012 | Permalink
  3. Okay great, thanks

    Posted 11 years ago on Thursday October 18, 2012 | Permalink
  4. You're making things harder on yourself than necessary. You can check the "Allow field to be populated dynamically" box on the advanced tab for your field, and give it a parameter name (i.e. my-time-field). Then use the following:

    [php]
    add_filter('gform_field_value_my-time-field', 'populate_time');
    function populate_time($value) {
        return "11:30am";
    }

    Does that work for you?

    Posted 11 years ago on Friday October 19, 2012 | Permalink
  5. Yes, that worked perfectly. Thank you for your help I don't think I would have figured that out, I was way off

    Posted 11 years ago on Saturday October 20, 2012 | Permalink