Home › Forums › General Issues › Limit displayed fields on acf_form for Repeater
I have a front end form that adds to a repeater. The repeater has first name, last name, email, checkbox, and a text field. On the front end form I only want to display the first three fields. Currently I’m using CSS to hide the fields but that doesn’t allow me to make those fields required (I use the same form on a different page where those hidden fields are displayed and updated).
<?php acf_form(['field_groups' => [ 246 ],
// 'fields' => array('field_5a21a84ddb30b', 'field_5a21a8a3db30c', 'field_5a21a8aedb30d'),
'post_id' => $user_ID,
'post_title' => false,
'submit_value' => __("Submit", 'acf'),
]); ?>
When I restrict the fields displayed by adding 'fields' => array('field_5a21a84ddb30b', 'field_5a21a8a3db30c', 'field_5a21a8aedb30d'),
it no longer allows me to add more items to the repeater. It just displays the last values submitted and allows me to edit it.
Ideally when this page loads I’d like to show a blank form that allows someone to add to the repeater upon submit, but I could also work with showing all the repeater items if I can limit it to only the first three fields.
In this case, I think it makes sense to use two separate forms: one with the 3 fields you need on one page, and another form with all the repeater fields on the other page. You could still have those save to the same place — in your case to a user.
Alternatively, if you need to use the same form for both pages you might have to disable the ‘required’ fields in ACF and then use some front-end validation like jQuery validate: https://jqueryvalidation.org
While a bit hacky, you could then add ‘required’ asterisks to your fields in your theme after the field label: <span class="required">*</span>
If it isn’t possible to edit the form label html directly you could use jQuery to append them or with css using the :after
pseudo selector.
I don’t see any disadvantage to creating two forms in this case.
You can also make the fields not required and then create a custom validation filter for the fields that only give and error if (is_admin())
https://www.advancedcustomfields.com/resources/acf-validate_value/
The topic ‘Limit displayed fields on acf_form for Repeater’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.