• Can Form to Post handle repeating fields?

    I have a form which takes multiple values in a single field. For example, if a user checks off the following…
    [ ] class 1
    [x] class 2
    [ ] class 3
    [x] class 4
    [x] class 5
    … it would return the value “array(‘class 2′,’class 4′,’class 5’)” to a hidden CF7 text field. I’m trying to get this into a repeating field when FtP creates the post.

    If it matters at all, I’m using the plugin ACF Repeater Fields.

    https://www.ads-software.com/plugins/form-to-post/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    I’m not familiar with that plugin. Is this something you are using to set custom fields in the post? In which case the hidden field’s name should start with “meta_”. I think it should handle setting multiple values in the same field.

    If I’m not understanding, please provide more context about ACF Repeater Fields.

    Thread Starter friendofdog

    (@friendofdog)

    I looked into this a bit further and it’s a bit more complicated than I originally thought. ACF has its own method of creating posts, and with Repeater Fields I found no other solution than to use ACF’s method.

    $field_key = 'field_123123123123'; // corresponds with a meta_ field
    $subfield_key = 'field_456456456456'; // repeating sub-field of $field_key
    $post_id = $the_post_id; // gets the current post ID
    $items = array('foo','bar','meh','cat','dog');
    foreach ($items as $items_value) {
    	$value[] = array($subfield_key => $items_value);
    	update_field( $field_key, $value, $post_id );
    }

    The issue is that you when you use Repeater Fields, you can’t get a meta_ field by its name. You have to get it by its field key, which is generated by ACF when you create a custom field. Repeater sub-fields also have their own field keys.

    Also, I couldn’t get this to work with update_post_meta, which FtP uses. I had to use update_field (which is native to ACF).

    Sorry, I thought this would be an open-and-shut issue. I’ve posted a similar question on ACF’s forums – if they indicate a solution that allows FtP integration, I’ll share it here.

    Plugin Author Michael Simpson

    (@msimpson)

    Thanks for writing back. Note that there are a couple of hook in F2P, form_to_post_before_create_post and form_to_post_set_values. Perhaps you can add code to those and call ACF functions to do what you want.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Repeating fields’ is closed to new replies.