Unlimited TextFields with Form API I'm creating a Block Plugin with a form. I'm able to create the standard form with various input field types. Like so.

    $form['text_field_1'] = array(
        '#type'          =&gt; 'textfield',
        '#title'         =&gt; $this-&gt;t('Entry 1'),
        '#default_value' =&gt; $this-&gt;configuration['text_field_1_submit'],
        '#size'          =&gt; 60,
        '#maxlength'     =&gt; 10,
    );

    $form['text_field_2'] = array(
        '#type'          =&gt; 'textfield',
        '#title'         =&gt; $this-&gt;t('Entry 2'),
        '#default_value' =&gt; $this-&gt;configuration['text_field_2_submit'],
        '#size'          =&gt; 60,
        '#maxlength'     =&gt; 10,
    );


This works but I can't anticipate how many entries the user may need, so I'd like users to be able to add multiple field entries in the same way that you can in a content type field.



Is this possible?
This is not a form API level feature, it's field/widget API.

For a custom form, you have to build it yourself with an add more button that uses #ajax to add more elements. A full code example would be too complicated for an answer, but you have to keep track of the count in $form_state, on pressing of the button increaes it, rebuild the form and then return the new elements.

See https://api.drupal.org/api/drupal/core%21core.api.php/group/ajax/8.2.x for more documentation, a quick tutorial that I found: https://www.sitepoint.com/using-ajax-forms-drupal-8/