Home › Forums › Feature Requests › Exclude checkbox for frontend form
I have an information gathering form I use for clients to fill out. Works well, but I’m porting it to ACF because the interface is way cleaner and lots of complex field options.
Currently the acf_form(); only allows you to specify an option group. It’d be a nice addition to allow within the interface a checkbox that lets you exclude a field from the front end form, or within the acf_form specifically. I can technically accomplish this with the filters you supply, but I don’t know if I’m applying this very efficiently.
add_filter('acf/field_group/get_fields', 'check_acf_fields');
function check_acf_fields($arg){
$x=0;
foreach ($arg as $field) {
// this bit is redundant and requires me to manually add it within php for each private field added.
if( in_array($exclude, $field['label']) || in_array('should only be internal', $field) ){
unset($arg[$x]);
}
$x++;
}
return $arg;
}
acf_form_head();
Hi @drrobotnik
Thanks for the feedback. I will soon be adding an ‘admin only’ or ‘backend only’ option to the fields settings.
Also, perhaps an option into the acf_form to list a bunch of fields to disable would work well too..
For now, you can use the acf/load_field filter (documentation on ACF site) to hook in and return false on the fields you want to hide. You can use the field name or key in the hook!
Good luck!
@ Elliot
Hello
Do you know new this featured Will ne avialable, for tell if the field is visible in the back office only ?
Regards
I just created a tab of stuff that should be internal and once it hits that tab it breaks the output. So everything after the private tab is hidden. This way I don’t have to go to php anytime I add a field. Works for me in this situation.
add_filter('acf/field_group/get_fields', 'check_acf_fields');
function check_acf_fields($arg){
$x=0;
foreach ($arg as $field) {
if( in_array('Internal', $field,true) || in_array('should only be internal', $field,true) ){
$output = array_slice($arg, 0, $x);
return $output;
}
$x++;
}
}
Thank drrobotnik for the tips.
Can you tell me where you put the code that you have wrote in your post ?
Regards
Gipe
I’d love to see an “admin/backend only” flag for fields.
Right now I’m testing things with a simple approach:
function prefix_hide_field($field) { return false; }
add_filter(‘acf/load_field/name=/*somefield_1*/’, ‘prefix_hide_field’);
add_filter(‘acf/load_field/name=/*somefield_2*/’, ‘prefix_hide_field’);
/* … */
add_filter(‘acf/load_field/name=/*somefield_n*/’, ‘prefix_hide_field’);
But I fear the amount of add_filter()’s is going to eventually be a pain to maintain. Flagging fields would be a great help in terms of back-end UX design because in complex scenarios you will want to have logical groups of fields that pertain to a certain set of data and functions yet only allow access to a select set of those fields to members (from the front-end).
Of course, it is possible to split options into different field groups and only include front-end-user field groups through the acf_form() options parameter but it makes it much harder and less intuitive from the standpoint of logically ordering things by areas of function.
Hi @Stefan Didak
This ‘admin visibility’ is an option which will be added soon.
This will be part of a big update for front end forms!
I tried tying into acf/load_field and returning false on certain fields. This works fine in the back end, but doesn’t seem to effect the front end at all.
Hello
When this option will be added ?
How to hide some fields on frontend form ?
Thank you
The topic ‘Exclude checkbox for frontend form’ 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.