Forms and Location Rules
-
Hello.
Thanks for such a useful plugin.
I noticed that the location rules do not affect the display of form fields on the frontend. Despite the rules, all field groups are always displayed. Rules have an effect only in the admin area. Is it possible to apply the rules for forms on front-end as well?
-
Hello bootword,
Thanks for the feedback!
The field group locations rules are quite special and only work in the administration of WordPress. There’s a an exception tho. Following the native ACF Form Front logic, you can set the form to display only field groups which are tied to a specific post. In such use case, field group locations rules which depend on the said post will be applied. Ie: “Display field group X if the current post has category: category-1”.
If you use ACF Form Front, this is behavior that is used with the following code:
acf_form(array( 'post_id' => 123, 'submit_value' => __('Update meta') ));In this example, ACF takes the post
123and look for field groups which are tied to it.With ACF Extended: Dynamic Forms module, the logic is quite different as forms are not necessarily tied to a post. However, it is possible to apply this behavior: In your form adminstration, in the “Advanced tab”, you’ll find a setting called “Post field groups” which will let you choose a post, and override the form’s field groups which are rendered.
Override rendered field groups with a specific post field groups.
Note: Make sure to set the related field groups in the “General” tab in order to map fields in the actions tab
Here is a screenshot: https://i.imgur.com/zzrwCgT.png
Hope it helps 🙂
Regards.
Thanks for the detailed answer!
The field group locations rules are quite special and only work in the administration of WordPress.
It’s a pity, given that there are all the necessary conditions. http://prntscr.com/r3fbsl It would be really useful if the location rules could be applied to Dynamic Forms.
Hi,
i like your plugin very much but i’m a beginner using ACF!
So 2 days ago i ran into the same problem as “bootword”.
I created 3 form field groups with location rules to show or hide the field groups individually based on taxonomies which are set in the post.
That works fine in wordpress backend and also using acf_form() in the frontend.
I would need to use the extended ACFE functions, actions and hooks for ACFE forms,
but like “hwk-fr” wrote it seems to be impossible to use taxonomie based location rules with ACFE forms.I fully agree that it would be really useful if the location rules could be applied to Dynamic ACFE Forms.
Thanks
JoeHello @joecpu,
Have you tried the “Post field groups” setting in the Advanced Tab, like in the screenshot I posted?
This will work exactly as
acf_form(array('post_id' => 123)).Let me know!
Regards.
Hello @hwk-fr,
Have you tried the “Post field groups” setting in the Advanced Tab, like in the screenshot I posted?
I tried this, but unfortunately this is not at all what I need.
The “post_id” setting is used to edit an existing post, but I don’t need to load data from the existing one, I don’t have it at all. I’m creating a new one and I just need the conditions to display field groups in frontend without using additional code.
For example: an application from a user is created through an ACFE Dynamic Form. If the user is not logged in or doesn’t have ‘customer’ role, I need to show him an additional group of fields. How the “Post field groups” can help here?
However, with the help of location rules, such a behavior could be easily set without extra lines of code, using only one form.
Hello @bootword,
I was replying to @joecpu, who specified that he was using the native ACF Form to display field groups attached to
post_idand display specific field group based on the said post taxonomy.In his case, the setting “Post field groups” is what he’s looking for, as the form field groups will behave the same as it would using the native ACF Form Front.
Regarding what you’re asking for field group location applying on the front-end, the feature is kinda tricky, because all native field groups locations would not work.
For example, the location “Widget == All” doesn’t make much sense in the Front-end. Your feature request is interesting tho, because as you said you could easily define rules like “Current user == viewing front-end” + “Current user != logged in” which seems pretty cool for form display.
After thinking about it, what I can do is to add a setting in Dynamic Forms: “Apply Field Groups Locations Rules”. This way, all users who already run Dynamic Forms with field groups that use the default field group location “Post Type == Post” won’t have their form displaying an empty page after upgrading to the new version.
I add the feature request in the Trello board. For the first version I will focus on the following location rules, so it shouldn’t take too much time:
- Post Type
- Post Category
- Post Taxonomy
- Current user
- Current user role
Have a nice day 🙂
Regards.
@hwk-fr, thanks. I will look forward to updates. I am sure this functionality will be useful to many.
There is one more case and I think it’s related to the current topic. When you create a complex form for the front-end (and sometimes for admin panel), you often need fields that are created solely for the logic of displaying other fields (Conditional Logic). Such fields will never be used to save and load user data (I guess the layout fields has similar logic). It would be helpful to have a quick switch to create such fields. And one more thing to quickly turn off the display of this fields in the admin panel (often such fields are created for the convenience of regular users). Usually for such purposes the choice types are used.
It might look something like this: https://prnt.sc/r507g9
Already now I can hide a specific field by activating “Advanced fields settings & validation”, but usually no other conditions or validation are needed for such logic fields.
@hwk-fr, thank you very much for good news about adding the new location rule features!
In between i checked your hint and set the “Post field groups” in the “advanced” tab to my already existing post.
I opend the form using the shortcode on my page and only the form field groups of my existing post which are defined by the location rules of my 3 individual form field groups are shown (showing the individual field groups by taxonomie values of the post).
So this approach seems to work in my case.
The problem is that i cannot use the forms shortcode because i must pre-set the post name in the “Post field groups” before opening the form.
So that seems to work only if i want to show the form to update this specific post.
But i would like to use the form to update different posts and so would need a dynamic way of setting the value of “Post field groups” before showing the form.Is there a way to integrate the form using PHP and set this “Post field groups” to the current post_id before showing it?
Have a nice day and thank you in advance
Hello!
Regarding “Show only on front”: Such a field would mean that there should be an another switch “Show only on admin”, because some people will want to show it only in the backend. If both switches are added, it should be renamed to “Hide on front-end” and “Hide on back-end”, otherwise they would be contradictory.
I understand that you want a quick switch when administrating forms field groups, however that would add unecessary settings for all other field groups that are not used within Dynamic Forms. However, it would be possible to add those switch when “Advanced settings” is enabled in the field group. I will think about it, and check what would happen if “Hide on back-end” is set to ON while the advanced setting “Hide field” is set to false for the admin in the advanced setting.
Regarding “Use only for conditional logic”: I don’t understand what this switch is supposed to do. If you use your field group as Dynamic Form, then that’s your choice to save the data or not anyway (using mapping for example). Data isn’t saved by default. Can you please provide further instructions on what the switch is supposed to do when it is enabled?
You’re right, there should be an option for “Current post” in that select. However, considering that “Apply field group location rules” setting will be added in the Dynamic Forms UI in the next patch, I will most likely deprecate this setting in a future update, as the first setting will fulfill people’s needs concerning “Field groups locations” in Dynamic Forms.
Unfortunately, there is no way to integrate Dynamic Forms exclusively in PHP right now. This feature will come in a future update (no ETA for the moment tho). However, it is possible to tweak the setting to make it use the current post dynamically.
To do so, please add the following code in your
functions.phpfile:// Change the "/form=my-form" accordingly, using the form name add_filter('acfe/form/load/form=my-form', 'my_acfe_form_post_field_groups', 10, 2); function my_acfe_form_post_field_groups($args, $post_id){ $args['post_field_groups'] = get_the_ID(); return $args; }Hope it helps!
Regards.
If both switches are added, it should be renamed to “Hide on front-end” and “Hide on back-end”, otherwise they would be contradictory.
It sounds good, two switches are a more complete solution for such cases.
However, it would be possible to add those switch when “Advanced settings” is enabled in the field group.
Maybe in this case it’s worth adding a global setting so that the “Advanced settings” option is enabled by default for all new field groups. For those who create many forms for the frontend it will be useful. Just one checkbox somewhere in the plugin settings.
Can you please provide further instructions on what the switch is supposed to do when it is enabled?
This switch should make the field purely for conditional logic. Yes, I can never save anything in this field, but it will be like a dead weight in all other places (for example other plugins that support ACF).
Imagine a complex Dynamic form. There may be several of these “Show advanced options” radio buttons or checkboxes. There can be 10 such forms on the site. And let’s say for each form you need to create such switches (because the logic of the forms is different). And then I go, for example, to the Elementor, where I want to display data from a normal field and see there: http://prntscr.com/r59hua
However, if I add a Layout field, for example, a Message or an Accordion, it will not appear anywhere. Only when displaying field groups. I wondered if it’s possible to create such a switch so that normal choice fields (checkbox, radio, select, true/false) lost the ability to store something and could not be used like a normal field anywhere. They can only perform a specific task because otherwise they will only get in the way.
Hello @hwk-fr
for my case there is no need to integrate Dynamic Forms exclusively in PHP as long as i can use ACFE hooks and filters in functions.php 🙂
Your add_filter sample works very well on my side.Thank you for fast help
JoeHello,
Regarding “Advanced Settings as Default”:
There is no UI for global settings in the plugin for the moment. It will come in a future version. When it will come out, I’ll think about a “default field group” settings template, so you will be able to customize your experience, for all settings.
Meanwhile, you can add the following code in your
functions.phpfile in order to force “Advanced Settings” in all new field groups creation:add_filter('acf/validate_field_group', 'my_acf_field_group_advanced'); function my_acf_field_group_advanced($field_group){ // Bail early if field group has been already saved if(acf_maybe_get($field_group, 'acfe_form') !== null) return $field_group; // Set field advanced settings $field_group['acfe_form'] = true; // return return $field_group; }Regarding “Blank Checkbox/Radio/Select”:
Message/Tab/Accordion fields are very specific field types, in fact they do not save any value (and get their field name are auto nulled). However, as you can see they cannot be used as conditional logic either. Applying the same behavior to checkbox/radio/select fields (with a switch), would be very experimental IMO and could lead to unexpected behavior.
When a field is used as “conditional logic”, it can “exclude” other dependant fields from saving. Tabs/Accordion/Message do not have such behavior, they are simply used for “display”. Checkbox/radio get their value saved, and if they are used as conditional logic, this value is used to know if a dependant field is supposed to be displayed or not. In the other hand, the tabs/accordions save the user preference (ie: last opened tab) in browser local storage (not in DB).
It looks like your end goal is Elementor integration. If you add such switch on radio/checkbox/select, you would have to hook inside Elementor in order to exclude fields that have this setting enabled. Elementor most likely exclude Tabs/Accordion/Message from available fields manually in the code (by field type).
I’m glad to hear that it now works as you wanted!
If you guys enjoy ACF Extended, feel free to submit a review, it always helps and it’s much appreciated 🙂
Have a nice day!
Regards.
Hello,
Regarding “Advanced Settings as Default”:
There is no UI for global settings in the plugin for the moment. It will come in a future version. When it will come out, I’ll think about a “default field group” settings template, so you will be able to customize your experience, for all settings.
Meanwhile, you can add the following code in your
functions.phpfile in order to force “Advanced Settings” in all new field groups creation:add_filter('acf/validate_field_group', 'my_acf_field_group_advanced'); function my_acf_field_group_advanced($field_group){ // Bail early if field group has been already saved if(acf_maybe_get($field_group, 'acfe_form') !== null) return $field_group; // Set field advanced settings $field_group['acfe_form'] = true; // return return $field_group; }Regarding “Blank Checkbox/Radio/Select”:
Message/Tab/Accordion fields are very specific field types, in fact they do not save any value (and get their field name are auto nulled). However, as you can see they cannot be used as conditional logic either. Applying the same behavior to checkbox/radio/select fields (with a switch), would be very experimental IMO and could lead to unexpected behavior.
When a field is used as “conditional logic”, it can “exclude” other dependant fields from saving. Tabs/Accordion/Message do not have such behavior, they are simply used for “display”. Checkbox/radio get their value saved, and if they are used as conditional logic, this value is used to know if a dependant field is supposed to be displayed or not. In the other hand, the tabs/accordions save the user preference (ie: last opened tab) in browser local storage (not in DB).
It looks like your end goal is Elementor integration. If you add such switch on radio/checkbox/select, you would have to hook inside Elementor in order to exclude fields that have this setting enabled. Elementor most likely exclude Tabs/Accordion/Message from available fields manually in the code (by field type).
I’m glad to hear that it now works as you wanted!
If you guys enjoy ACF Extended, feel free to submit a review, it always helps and it’s much appreciated 🙂
Have a nice day!
Regards.
Hello,
Regarding “Advanced Settings as Default”:
There is no UI for global settings in the plugin for the moment. It will come in a future version. When it will come out, I’ll think about a “default field group” settings template, so you will be able to customize your experience, for all settings.
Meanwhile, you can add the following code in your
functions.phpfile in order to force “Advanced Settings” in all new field groups creation:add_filter('acf/validate_field_group', 'my_acf_field_group_advanced'); function my_acf_field_group_advanced($field_group){ // Bail early if field group has been already saved if(acf_maybe_get($field_group, 'acfe_form') !== null) return $field_group; // Set field advanced settings $field_group['acfe_form'] = true; // return return $field_group; }Regarding “Blank Checkbox/Radio/Select”:
Message/Tab/Accordion fields are very specific field types, in fact they do not save any value (and get their field name are auto nulled). However, as you can see they cannot be used as conditional logic either. Applying the same behavior to checkbox/radio/select fields (with a switch), would be very experimental IMO and could lead to unexpected behavior.
When a field is used as “conditional logic”, it can “exclude” other dependant fields from saving. Tabs/Accordion/Message do not have such behavior, they are simply used for “display”. Checkbox/radio get their value saved, and if they are used as conditional logic, this value is used to know if a dependant field is supposed to be displayed or not. In the other hand, the tabs/accordions save the user preference (ie: last opened tab) in browser local storage (not in DB).
It looks like your end goal is Elementor integration. If you add such switch on radio/checkbox/select, you would have to hook inside Elementor in order to exclude fields that have this setting enabled. Elementor most likely exclude Tabs/Accordion/Message from available fields manually in the code (by field type).
I’m glad to hear that it now works as you want!
If you guys enjoy ACF Extended, feel free to submit a review, it always helps and it’s much appreciated 🙂
Have a nice day!
Regards.
@hwk-fr These “please delete” replies are getting tedious. Please be more careful or edit with the corrected content.
The topic ‘Forms and Location Rules’ is closed to new replies.