advancedforms / advanced-forms

WordPress plugin to create forms using Advanced Custom Fields
75 stars 14 forks source link

af_get_field not working with sub fields inside "Group" field #35

Closed tyrann0us closed 6 years ago

tyrann0us commented 6 years ago

Hi @Fabianlindfors, thank you for this great plugin!

I noticed that af_get_field won't work if the field type is set to "Group". Example: Field of type "Group" called "field" has a sub field called "sub_field". How am I supposed to access the sub field? af_get_field( 'field[sub_field]' ) does not work, neither does af_get_field( 'sub_field' ).

https://github.com/advancedforms/advanced-forms/blob/12e950b93c2969f71480af4488cc93ffd7bc1b6f/api/api-forms.php#L55-L56

If I change the condition to if ( isset( $field['sub_fields'] ) ) { then af_get_field( 'sub_field) works.

Would it be safe to change the condition as mentioned? Thanks!

fabianlindfors commented 6 years ago

I think that would work! I implemented your suggested changes with commit e30e128e95d622c33ea42b46d624c28b30d3de1e.

Thanks a lot!

cedricDevWP commented 4 years ago

Hi,

I think there is a problem when you have a group that owns another group.

Example :

1 ACF : image

who has a acf dog (see 2 ACF)

2 ACF : image

Who has a acf owner (see 3 ACF)

3 ACF : image

If i do :

af_get_field("civilite") => Return false

When i see the data : image

We do not go through the group

cedricDevWP commented 4 years ago

to correct I add:

if ( $sub_field_name == $field_key_or_name ) { return $sub_field_value; }elseif( $sub_field_name == 'groupe'){ foreach ($sub_field_value as $sub_field_name_2 => $sub_field_value_2) { if ( $sub_field_name_2 == $field_key_or_name ) { return $sub_field_value_2; } } }

image

for the future it would not be judicious to use the indentifiants and not the names like key?