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.

Filtering the values for the address field type

  1. Hey guys,

    I'm currently adding default values for all sorts of fields using the great hooks you provide for most input types. However I'm currently trying to limit the address 'province' dropdown to only 2 provinces (as this particular 'thing' is limited to those 2 provinces). I've looked through the core files and can't see any filters which would allow for that. I've tried using the gform_pre_render hook (which works great for normal dropdowns) and the gform_field_value_* hook without any success.

    I can see that for an address the setup is slightly different (As you'd expect) as the $field has an [inputs] part of the array. I've tried doing something like $field['inputs'][3]['choices'] = array( 'text' => 'test', 'value' => 'testval' ) within the gform_pre_render hook but to no avail.

    Am I missing something?

    public function auto_populate_address_province( $form )
    		{
    
    			foreach( $form['fields'] as &$field )
    			{
    
    				if( $field['type'] != 'address' || strpos( $field['cssClass'], 'slide2-address' ) === false )
                		continue;
    
                	//gForms expects an array with 'text', 'value' and 'isSelected' as keys
    				$choices = array( array( 'text' => 'test', 'value' => 'value' ), array( 'text' => 'test2', 'value' => 'value2' ) );
    
    				$field['inputs'][3]['choices'] = $choices;
    
    			}
    
    			return $form;
    
    		}/* auto_populate_address_province() */
    Posted 10 years ago on Friday May 10, 2013 | Permalink
  2. Nothing on this at all guys?

    Posted 10 years ago on Tuesday May 28, 2013 | Permalink
  3. We've forwarded this one to the development team. Sorry for the delay.

    Posted 10 years ago on Wednesday May 29, 2013 | Permalink
  4. For your particular case, take a look at the hook http://www.gravityhelp.com/documentation/page/Gform_address_types . This allows you to create a new address type where you can limit it to your two provinces. The address field has "addressType" as part of the field collection.

    Posted 10 years ago on Thursday May 30, 2013 | Permalink