Creating a Custom or Extended Gravity Forms Field with Multiple Inputs

I’m building a site for a Japanese company.  They need a Gravity Forms address field with a different order.  I spent a BOATLOAD of time trying to get this working and I finally did.  Here’s some details.

Extending Address Field

I started by extending the address field.  Simple enough.  Made some tweaks to the get_field_input() function to reorganize.  Made sure all other functions that used the .1, .2, etc. id’s for the inputs inside the field were updated in my field class.

After some trial and error with those I got the form field to be in the admin so I could add it to a form.  Awesome! Went to the front and there’s my new beautiful field.  But no matter how hard I tried it would not save any of the data.

I searched and searched through all the hooks I could find related to this.  I almost gave up but then I found a comment that said something about default inputs were loaded in js.php file.

JS.PHP

In the root directory of Gravity Forms is a file named js.php.  This file runs a switch case on different field types and populates some data.  If you look towards the bottom around line 838 at the writing of this post you will see:

<?php do_action( 'gform_editor_js_set_default_values' ); ?>

Right there you need to hook in your own default settings with field.inputs defined.  That’s about it! I just copied the info they had for the address field, tweaked it to match my class’s data and voila.

Leave a Reply

Your email address will not be published.