Support

Account

Home Forums ACF PRO Frontend form with location rules

Solving

Frontend form with location rules

  • I’m attempting to setup a frontend form using ACF, I’ve exported my ACF groups in to separate PHP files (as there are many of them).

    The main ACF group asks to pick a custom taxonomy, then based on the selection I show another corresponding ACF group (using a location rule: discover-categories:planet)

    In the backend this works perfectly and the fields show when I select a category from the taxonomy term list, however I can’t seem to get this working in the front-end form. The taxonomy list is displayed, but when I click one the corresponding ACF group doesn’t show as expected.

    If anyone could help me to get this working I’d massively appreciate it 🙂

    DW

  • This won’t work on the front end. In the back end when you select a category in the standard WP category box this triggers WP to run AJAX to see if there are more field groups that need to be displayed. This will not work on the front end because ACF does not update the taxonomy field until you save the post. You would basically need to create a location rule that’s based on the value of an ACF field and that functionality does not exist.

    It is something that can be done. I don’t know of any examples of how to do this with a taxonomy field, but this JavaScript is an example of how to do it with an ACF choice field and with some work you could probably make make it work with a taxonomy field. https://github.com/Hube2/acf-custom-field-locations-rule/blob/master/acf-custom-field-location-rule.js

  • Many thanks for the reply,

    Out of interest if I was to bring all the fields into one form and setup conditionals within ACF would these work on the front-end?

  • Conditional logic will not work on taxonomy fields. To use conditional logic you would need to either

    1) Build conditional logic for the field yourself using JS. There is an old example of something similar here https://support.advancedcustomfields.com/forums/topic-tag/conditional-logic/

    2) Use a select field and populate the choices dynamically using an acf/load_field filter and then update the terms in WP youself using and acr/save_post action and wp_set_post_terms.

  • Thanks John, the link you provided just points towards a search for conditional-logic, was it supposed to be a specific thread?

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.