Support

Account

Home Forums Front-end Issues Conditional Statements in frontend ACF Form

Solving

Conditional Statements in frontend ACF Form

  • Hello, I have a frontend form which contains some categories using ACF Form.

    On ACF Admin Dashboard I created a rule for if category isn’t equal X than show the fields and another one if category is equal X show other fields.

    But when I select the X or Y category on my frontend ACF Form nothing happens, the fields doesn`t show.

    I think that to make it work I need some AJAX that gets my selected category and load the fields, but how can I do that?

    Thanks.

  • Hi @lucassimines

    Could you please share the JSON or XML export of the field group?

  • Hello James, thanks for answering, here is the JSON.

  • Hi @lucassimines

    I’m not sure how you create the category selection on the front end. If you want to hide and show some fields, you can use the Conditional Logic. This page should give you more idea about it: http://www.advancedcustomfields.com/resources/field-settings/.

    I hope this helps.

  • Hello James, I’ve done the Conditional Logic right, it works on Backend, but it’s not working on frontend using ACF Form.

    I’ve create a fake user for you to see what’s happening:

    User: [email protected]
    Password: 12345678

    Url: http://ideiasfmc.com/Clientes/ManejoRural/anuncie-gratis/

    Ps: the website is in Portuguese.

    What I need is:
    When I select all the categories except the category “Serviços”,

    The fields below will contain Title, Price, Video etc…

    But, when I select the category “Serviços”, the fields below will appear another field group containing only Title, Description and Photos.

  • Hi @lucassimines

    It seems that you set the location rules instead of the conditional logic. The location rule you have will only show when the post is set to a certain category. It means you need to publish it first to make it work on the front end.

    If you want to hide certain fields for a certain condition, conditional logic is the right choice. But the fields need to be in one field group. You can create a dummy category select field in the field group and then set the conditional logic for this select field. I’ve attached the example for you.

    Also, please set your post to private it you include credentials in it.

    Hope this helps.

  • Hello James, I’ve tried the conditional logic, it really works on backend, but it I can’t make it work on the frontend, when I select a category in my new Selector, it doesn’t hide the fields.

  • Hi @lucassimines

    That is weird. The conditional logic is working on my end. Could you please try to reproduce the issue on one of the WordPress’ stock themes (like Twenty Fifteen) with other plugins deactivated? If the issue disappears, then you can activate the theme and plugins one by one to see which one causes the issue.

    Keep in mind that you need to create the hidden field in one field group with the select field.

    I hope this helps.

  • Going back to at least v4.3.8 conditional fields have never worked on the front end for me. I’ve just run into it again with v5.3.4.

    It’s easy to fix without having to touch the core files but can be time consuming if there’s several layers of conditionals along with required fields.

  • Hi @circularone

    How have you implemented your conditional field.

    I have been testing conditional fields and they seems to be working just fine on my end.

    Is it possible you have not correctly configured your conditional field?

    Kindly check and let me know.

  • I too have had trouble with conditional logic on the front end. Is this actually supported? Perhaps it’s because I’m working with flexible content that it’s not working…

  • Hi @fullsteamlabs

    Could you please share your JSON or XML export file so I can test it out on my end?

    Also, please make sure that there’s no Javascript conflict on your front end by checking the developer tools on your browser.

    If you can, could you please try to reproduce the issue on one of the WordPress’ stock themes (like Twenty Fifteen) with other plugins deactivated? If it disappears, then you can activate the theme and plugins one by one to see which one causes the issue.

    Thanks!

  • Just to be clear conditional logic works great on the backend. It doesn’t work at all for me when using acf_form() to add a form on the frontend. Everything else works, but the conditional logic doesn’t do anything. All of the fields are shown from the beginning, and when I change a field that should should hide some and show others, it doesn’t have any impact. This seems like an issue for a while now. Not sure what I would be missing in my setup. I have acf_form_head() above get_header().

    None of the ACF JavaScript is loaded on the front end. The styles are, but not the JavaScript.

  • I just tested in Twentyseventeen, and it works fine. For me, this is definitely an issue with my theme.

    For me, I had deregistered jQuery since my theme does need it. That was breaking ACF.

  • I know this is an old topic, but I had the same problem and solved it. So I want to share my solution, maybe useful for somebody else…

    As @jcow said, my problem was originated from my theme… and at least I understood that my theme uses jQuery individually and it was loading the jQuery file at the footer.

    I just changed the position of loading jQuery in the theme (made it load in the header) and the problem solved.

    I changed this code:

    wp_enqueue_script( 'boot1', get_template_directory_uri() . '/assets/vendors/jquery/jquery-3.6.1.min.js', array(),'', true );
    

    To this:

    
    wp_enqueue_script( 'boot1', get_template_directory_uri() . '/assets/vendors/jquery/jquery-3.6.1.min.js', array(),'');

    If the last parameter in wp_enqueue_script was “true”, that means loading the script in the footer.

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

The topic ‘Conditional Statements in frontend ACF Form’ is closed to new replies.