Where to Place acf_form_head() to Save Submitted Data

Home Forums Calendar Products Community Events Where to Place acf_form_head() to Save Submitted Data

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1363504
    Steven Frasier
    Participant

    I have the Advanced Custom Fields showing on the frontend CE form—and they save if the edits are made via admin—but I cannot get the frontend form to save the data.

    According to the Advanced Custom Fields documentation, found here: https://www.advancedcustomfields.com/resources/acf_form_head/

    This function is used to process, validate and save the submitted form data created by the acf_form() function. This function will also enqueue all ACF related scripts and styles for the acf form to render correctly. This function must be placed before any HTML has been created, preferably above the get_header(); function in your theme file.

    So that figures to be the issue. But does anyone have any guesses as to where I could place the acf_form_head()? I see no get_header(); function among the Community Events template files. I’m at a total loss, and the ACF support staff I’ve worked with have no familiarity with the Community Events plugin, suggesting I check with the devs here.

    #1364343
    Cliff
    Member

    Hi, Steven.

    Thanks for your detailed question.

    The Community Events form is actually not a regular WordPress post or archive page; it’s a WP Router “page”.

    tribe_events_community_form might be the action hook you’re looking for. I found it in the render() method inside /wp-content/plugins/the-events-calendar-community-events/src/Tribe/Event_Form.php

    Please let me know how this goes for you.

    #1364645
    Steven Frasier
    Participant

    Hey Cliff,

    Very much appreciate that, but it did not work, at least not the way I implemented it (as seen in attached screenshot).

    If it’s any help, here is a thread that includes additional ideas and information from my discussion with a dev for Advanced Custom Fields.

    I have also tried changing my calendar template to Default Page, as well as Default Events Page, adding acf_form_head() above the get_header(); function that exists in both with no luck.

    screenshot

    #1364941
    Cliff
    Member

    I see from your image that you tried it but it didn’t work. (Even though this isn’t the ideal way to implement it long-term.)

    Since you want it in wp_head(), I think the best way is to actually use that hook.

    You could reference this is_community_page() method as a check inside the code you hook into wp_head(): https://github.com/moderntribe/products-extensions/blob/master/tribe-ext-community-currency-symbol/index.php#L294-L331

    Please let me know how this goes for you.

    #1364969
    Steven Frasier
    Participant

    Cliff,

    Unfortunately, I’m not exactly clear about the instructions.

    Are you suggesting I add acf_form_head(), using that method, to the same Event_Form.php file?

    Is this the correct code? Where within the file should it be placed? I sincerely apologize for all of the confusion.

    if (
    	is_community_page( 'acf_form_head()' )
    		)
    
    add_action('wp_head', 'acf_form_head()');
    #1364986
    Cliff
    Member

    Steven, this code snippet should get things working for you:

    https://gist.github.com/cliffordp/9c88e97e5f2392b1c36eabb248a50b11

    Please let me know how this goes for you.

     

    #1365690
    Steven Frasier
    Participant

    Cliff,

    I can’t even begin to express how much I appreciate the time and hard work you put into writing that snippet, but unfortunately the front end CE form is still failing to retain or save any of the data input into the ACF fields.

    I have attached a screenshot to show you where I placed the snippet within my theme’s function.php file.

    I see the notes within the snippet stating “This will get ACF loaded but you will need to add your own additional code to get ACF to do anything at all on the Community Events forms.”

    Is this for other people who use the snippet in the future? The ACF form group is displaying on the front-end form, it just will not save any of the data entered into the ACF fields. Once I hit submit, the content for ACF fields is gone. (For what it’s worth, the data saves when it is input via Admin edit event.)

    I have disabled all plugins with the exception of my theme, all Events Calendar-related plugins and the ACF Pro plugin.

    If it’s any help..

    Here is my /community/edit-event.php:

    <?php
    /**
     * Event Submission Form
     * The wrapper template for the event submission form.
     *
     * Override this template in your own theme by creating a file at
     * [your-theme]/tribe-events/community/edit-event.php
     *
     * @since    3.1
     * @version  4.5
     *
     * @var int|string $tribe_event_id
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	die( '-1' );
    }
    
    if ( ! isset( $tribe_event_id ) ) {
    	$tribe_event_id = null;
    }
    
    ?>
    
    <?php tribe_get_template_part( 'community/modules/header-links' ); ?>
    
    <?php do_action( 'tribe_events_community_form_before_template', $tribe_event_id ); ?>
    
    <form method="post" enctype="multipart/form-data" data-datepicker_format="<?php echo esc_attr( tribe_get_option( 'datepickerFormat', 0 ) ); ?>">
    	<input type="hidden" name="post_ID" id="post_ID" value="<?php echo absint( $tribe_event_id ); ?>"/>
    	<?php wp_nonce_field( 'ecp_event_submission' ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/title' ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/description' ); ?>
    	
    	<?php tribe_get_template_part( 'community/modules/acf' ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/datepickers' ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/image' ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => Tribe__Events__Main::TAXONOMY ) ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => 'post_tag' ) ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/venue' ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/spam-control' ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/submit' ); ?>
    </form>
    
    <?php do_action( 'tribe_events_community_form_after_template', $tribe_event_id ); ?>
    

    And here is the template for the ACF field group I created at community/modules/acf:

    <?php acf_form( $options );
    	$settings = array(
      'id' => 'acf-group_59dd13c80be9e',
      'form' => false
    );
    acf_form($settings);
    			
    ?>
    #1365757
    Cliff
    Member

    You’re welcome. It’s always nice to receive appreciation.

    I’ve never actually used ACF so I don’t have intimate details of how to get it to do what you want. I only attempted to do what you requested, per their support.

    https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/ and https://www.advancedcustomfields.com/resources/create-a-front-end-form/ would probably be relevant if not trying to use ACF’s alongside Community Events’ form. I’d think you need to rely on one or the other…

    …which is what it seems John Huebner stated Oct 13: https://support.advancedcustomfields.com/forums/topic/acf-integration-with-community-events-plugin-the-events-calendar-2/

    Because acf_form() — what you’re trying to implement with Community Events — creates a new <form> — and therefore you have a <form> within another <form> — my recommendation would be to go one of two mutually-exclusive directions:

    1. Ditch ACF for the sake of front-end submission forms in relation to our plugin suite and use only Community Events and PRO’s Additional Fields functionality.
    2. Use ACF only and ditch Community Events (basically using ACF to recreate all that Community Events can do–seems like a heavy lift to me). We do have API functions and you could possibly get ACF to leverage those when it does its data submission.

    My first choice would be using PRO’s Additional Fields. Is there a reason you’re unable or unwilling to use that, which works with Community Events out of the box?

    #1365942
    Steven Frasier
    Participant

    Understood. Thank you again.

    The trouble is that I’m not sure Additional Fields functionality helps me achieve the more advanced form field options like “repeater fields” or even multi-line table-like fields where users input the data horizontally according to the field’s sub-labels up top. Please see screenshot for some clarity.

    Am I mistaken?

    #1366183
    Cliff
    Member

    You’re correct. I know ACF and CRED can do such things, but neither have native integration with The Events Calendar.

    I’d recommend reviewing https://github.com/moderntribe/the-events-calendar/blob/4.6.2/src/Tribe/API.php and see if you want to undertake creating your own form or stick with Community Events’ form.

    If you need some coding help, you may want to ask your developer or reference our documentation and list of known customizers.

    #1366218
    Steven Frasier
    Participant

    Okay, thank you for everything, Cliff. I actually think my best option may be one that I have not mentioned—namely, Gravity Forms.

    Feel free to close the thread. You were tremendously helpful, no matter the result.

    #1366277
    Cliff
    Member

    You’re welcome.

    Gravity Forms, Ninja Forms, Caldera Forms, and Formidable Forms would all probably be able to get things done if you’re going the full custom route.

    Have a great rest of your week.

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Where to Place acf_form_head() to Save Submitted Data’ is closed to new replies.