Advanced Custom Fields – Custom Field Type with multiple inputs

I am trying to create a new field type for ACF that contains multiple inputs or stores an array of values. The reason is that I would like to have some interactivity and a custom layout for a group of input fields.

I followed this tutorial http://www.advancedcustomfields.com/resources/tutorials/creating-a-new-field-type/ and used the provided template: https://github.com/elliotcondon/acf-field-type-template which is really nice and well documented. Storing one value is pretty simple. I am using only this function from the template:

Read More
function create_field( $field )
{
    echo '<textarea id="' . $field['id'] . '" rows="4" class="' . $field['class'] . '" name="' . $field['name'] . '" >' . $field['value'] . '</textarea>';
}

What do I have to change in order to use two or more inputs?
Thanks!

Related posts

Leave a Reply

2 comments

  1. The names and values of your 2 textareas must be as follows:

    echo '<textarea id="' . $field['id'] . '" rows="4" class="' . $field['class'] . '" name="' . $field['name'] . '[textarea1]" >' . $field['value']['textarea1'] . '</textarea>';
    
    echo '<textarea id="' . $field['id'] . '" rows="4" class="' . $field['class'] . '" name="' . $field['name'] . '[textarea2]" >' . $field['value']['textarea2'] . '</textarea>';
    

    textarea1 and textarea2 can be chosen freely by you.

    This will save multiple values in your custom field type, value will save an array like:

    Array
    (
        [textarea1] => abc
        [textarea2] => xyz
    )
    
  2. Did you check the flexible content add-on for ACF?
    I think you will find the solution in that code.

    Oh, and if you find the solution please post it here, because i’m really interested in the solution. Sorry to get your hopes up by posting a not so clear answer.