Recently, we’ve been using Gravity Forms on some pretty complex forms. One of the most complex forms had a bunch of select fields, and one of them had to list all posts associated with a custom post type. Gravity Forms has in their documentation a check on a foreach loop where we check the field type is equal to a value (such as input, checkbox, radio, etc.). This is done using checking the ['inputType'] index in the $field array. Whilst suitable for forms with only one field, this could lead to all select fields in the form to have the same value. We need to target only one field. You could check the ['id'] of the $field array, which would allow you target individual entries in the form. However the problem with this was the client was pretty savvy, and was after a way of prepopulating other forms using similar code. In the end, we decided to check whether a select field had a CSS class (in our case, populate-with-posts). If it does have said class, then we populate the select options with all posts. The Code function winwar_populate_dropdown_with_posts($form){ foreach($form['fields'] as &$field){ if($field['inputType'] != 'select' || strpos($field['cssClass'], 'populate-with-posts')
Share This