• Resolved laymonk

    (@laymonk)


    HI,

    I have a basic need to modify post_title and slug before save (on post insert) … and on post update, do same if any of the fields used change:

    • post title will be a concat of various form fields user has entered in the form
    • post slug will be a simple case of calling sanitize_title() on the auto-generated post title as above

    A couple of questions

    In the Post Action -> Save tab … what does ‘Enter a custom value or template tag’ mean ?

    • Does it mean I can achieve the auto-creation of the title or slug from concatenation of form fields by using template tags?
    • if so, is there an example usage that you could point one to.

    Your code examples in Post Action –> Code tab are very useful … but I am am not sure how to retrieve the values from cloned sub_fields (created with setting ‘Prefix Field Names’) with predictable field names.

    • I am not able to see the field names for these cloned sub fields displayed in the ACF-E UI (only their parent field name).
    • Will get_field(‘predictable_field_name’) work for these ?

    Still on the Field Action –> Code tab, what is the use of ‘prev_post_action’ in the ‘Change post arguments’ example ? Is this really essential in my very simple use case?

    Final questions:

    • in the case of an update, how can I check whether values in the fields I am using to auto-generate the title and slug have changed ? What’s the most effective way of doing that?
    • Will leaving post slug settings as default, while auto-generating titles give me the effect I am trying to achieve?

    Thanks for this great tool, and thanks in advance for responding. This challenge is holding up important work I am doing, so I hope for a quick response.

    • This topic was modified 4 years ago by laymonk.
    • This topic was modified 4 years ago by laymonk.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback! First, when it comes to the ACF Extended Form feature, I would recommend to head over the documentation here. This is where you will find all examples and explanations available, including Post Action documentation. I’ll probably get rid of that “Code” tab in the future and simply send developers to the documentation.

    In the Post Action -> Save tab … what does ‘Enter a custom value or template tag’ mean ?

    That means you can use any Template Tag available in the Cheatsheet. For example you could use {field:my_field} to use the my_field value as post title.

    Does it mean I can achieve the auto-creation of the title or slug from concatenation of form fields by using template tags? if so, is there an example usage that you could point one to.

    Exactly. I still have to write more advanced usage examples, but you can just try it and see it action, really. Concatenation is possible of course.

    For example you could enter the following value in the Post Title field: Contact Form of {field:first_name}. The Post Slug will naturaly use sanitize_title() (unless you specify it differently) and generate contact-form-of-laymonk, just like the native wp_insert_post() behavior.

    Your code examples in Post Action –> Code tab are very useful … but I am am not sure how to retrieve the values from cloned sub_fields (created with setting ‘Prefix Field Names’) with predictable field names.

    When it comes to clones and sub fields, Template Tags aren’t sustainable, since fields using sub fields are quite more complex (Flexible Content, Repeater, Clone…). You’ll have to rely on PHP hooks there to do exactly what you want.

    What you’re looking for is the acfe/form/submit/post_args hook, which let you change the Post Arguments right before it is inserted/updated in DB using wp_insert_post().

    I am not able to see the field names for these cloned sub fields displayed in the ACF-E UI (only their parent field name). Will get_field(‘predictable_field_name’) work for these ?

    As explained above, you’ll have to use PHP hooks since clones are very advanced. Clones values can be accessed in different ways, using get_field('my_clone') which would return an array, and then accessing the array, or using the have_rows('my_clone'): the_row(), see the ACF documentation: https://www.advancedcustomfields.com/resources/clone/

    I would recommend the following method to know how to access your values and debug it more easily: Create a post with your field group and your clone values from the back-end, like any admin. Then in the front-end template try to access all necessary values using get_field() or have_rows().

    Make sure you have access to everything, debug it, then when everything works as expected, use the code inside your form, in the acfe/form/submit/post_args hook.

    In fact, in that hook you can use get_field(), have_rows(), get_sub_field() without any post_id. The system will simply run those function on the actual input entered by the user, before it is even in DB! (yes it’s magic).

    As a conclusion, if you’re looking quick help/support, you may would like to join the ACF Slack community, it’s a great place to discuss with other ACF/ACF Extended users and get help, as we can just text-chat. Here is an invitation link: https://join.slack.com/t/wpacf/shared_invite/enQtODc2MjczMzM3NzQ1LTQxNmY2ZGY3OTU2NDkxNTliYmNhMmY1NDMwZGM4NmYxNzgwZTI5MDUzMDFlMGQ5YzcwNDc0ZWM0MDVmODI4NmI

    Come say hi, I’m always connected there ??

    Hope it helps!

    Have a nice day.

    Regards.

    Thread Starter laymonk

    (@laymonk)

    Konrad, Million thanks for the most helpful information. Definitely sets me straight on how this is supposed to work.

    And I can confirm that this is working perfectly.

    Thanks for sharing the slack link too … had a weird problem where the media library will display blank on attempting to select images for image / gallery fields … lasted a couple of hours but it suddenly started working again, so it’s probably nothing to do with ACF-E.

    And please please, don’t get rid of that ‘Code section’, without it I would not have delved deeper and figured out the immense usefulness of your plugin. I reckon it’s arguably one of the best selling feature.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I’m glad to hear that it now works as expected! Please create a new topic if you have an another problem, to keep things organized. I would also recommend to try to isolate the problem, as incompatibility with front-end forms can come from many sources (especially when using builders like Divi etc…).

    Regarding the “Code Section” in the ACFE Form UI, I can understand you find those snippets helpful, but there are multiple reasons to remove them. First, I added it because there wasn’t proper online documentation, which is fixed now. In my opinion, documentation shouldn’t be in the user interface, but on a separated document too.

    Also having two documentation require additional maintenance, since I have to update two sources instead of one. And finally, users may not look for the real/complete documentation online if they find one or two snippets directly in the UI, just like you did. One solution would be to replace them with links to documentation. That’s probably what I will do.

    Regards.

    Thread Starter laymonk

    (@laymonk)

    Thanks again for your awesome plugin and immense support of it … I hear you loud and clear on all you have said. I will vote for links in the UI to the specific docs pages in your documentation site.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Struggling to understand how to use ‘Generated ID’’ is closed to new replies.