Backend Integration of Advanced Custom Fields

Home Forums Calendar Products Community Events Backend Integration of Advanced Custom Fields

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

    Hello,

    You guys have always provided exceptional supported, so I did not hesitate to purchase the Community Events add-on, understanding fairly well that it would not fully meet my needs out-of-the-box.

    That said, I’m hoping you can at the very least point me in the right direction here, because I was surprised to find myself unable to integrate Advanced Custom Fields (ACF) with Community Events on the backend.

    I have successfully created ACF Field Groups and had them implemented on the backend of The Events Calendar Pro in single event creation, but I have been unsuccessful in my attempt to do the same for submitting an event via the Community Events page.

    Are Community Events not seen as a post-type recognizable by any of the ACF “rules?”

    Again, just to be clear, I only need for the ACF to show up on the backend where users are submitting their “Community” event, I don’t necessarily need it to be displayed on the front-end when the event is ultimately published.

    #1362088
    Steven Frasier
    Participant

    It’s possible that I’m getting confused between front-end and backend here. Since users are submitting the forms, I now feel like it probably constitutes front-end implementation. One way or the other, I sincerely apologize for the confusion.

    #1362252
    Andras
    Keymaster

    This reply is private.

    #1362264
    Steven Frasier
    Participant

    Absolutely—thanks Andras!

    #1362501
    Andras
    Keymaster

    Hi Steven,

    Here’s some of the info I managed to gather:

    The CE submission form share some of the same components of the back-end form.

    In terms of customizing/injecting stuff into the front-end editor, there are a raft of hooks and template override opportunities for this. But, triggering the custom ACF fields and finding out how to a) make them display b) save the submitted data for those fields is, beyond the scope of our support.

    It is possible to create a front-end forms using the ACF custom fields created in the back-end. There is some documentation on how to do it here:

    Create a front end form

    You basically need to use some functions to add the necessary styles/scripts for the fields to work and submit. Mixing them with our own CE front-end forms however would be slightly different and we don’t know what could result from it.

    If you would like to go down this path and you require help I can share with you a list of freelance developers who are known in our community and are not affiliated with us.

    Cheers,
    Andras

    #1362800
    Steven Frasier
    Participant

    Hi Andras,

    Thanks for the detailed response!

    I was able to get the form to display on the user submission form on the front-end with the following code plugged into /wp-content/plugins/the-events-calendar-community-events/src/views/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 acf_form( $options );
    	$settings = array(
      'id' => 'acf-group_59dd13c80be9e',
      'form' => false
    );
    acf_form($settings);
    			
    ?>
    
    	<?php tribe_get_template_part( 'community/modules/description' ); ?>
    
    	<?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/organizer' ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/website' ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/custom' ); ?>
    
    	<?php tribe_get_template_part( 'community/modules/cost' ); ?>
    
    	<?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 ); ?>
    

    Basically, I added the following acf_form call to edit-event.php (I’ll save it to the tribe-events folder on the production site once I get it working correctly):

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

    I tested it, but at the moment it isn’t registering any of the data entered. It erases upon hitting submit, and isn’t sent via the notification email. So now I’m trying to look into that, before eventually tweaking the CSS to get the look right.

    Also, is this bit of advice from the ACF support forum relevant? If so, could you shed some light?

    Note that you’ll need to figure out how to modify the header to include the call to acf_form_head() that’s mentioned in the acf_form() documentation.

    According to their documentation, that’s what allows it to perform the logic needed to save the data.

    It is important to note that whilst the acf_form() function will create a form allowing you to input data, it will not perform the logic needed to save the data. This logic is handled by another function called acf_form_head(). To allow the form to save data, you will need to place the acf_form_head() function at the top of your page template before any HTML is rendered.

    Where would I add that?

    #1363133
    Andras
    Keymaster

    Hi Stephen,

    I’m happy you’re making progress with your project.

    Unfortunately I’m not at all familiar with the inner workings of Advanced Custom Fields. Looking at their documentation probably you need to add the following line before the ‘get_header()’ of your templates:

    <?php acf_form_head(); ?>

    But this is really beyond me and the scope of our support, since this is a third-party plugin. Your best bet would be reaching out to ACF support or to a developer to help you implement this.

    Cheers,
    Andras

    #1363235
    Steven Frasier
    Participant

    Thanks again, Andras,

    Unfortunately I’m getting mostly the same from them. They have helped get me this far, and provided the same line you provided, but they aren’t sure where the appropriate ‘get_header()’ would appear in the TEC/CE template files.

    Do you have any idea where I might begin to look? Which template files contain ‘get_header()’?

    Here is the last responses I received from them:

    f that’s the template, there are no hooks there that will help you. Like I said, you’d need to talk to the developers of that plugin to see if they provide any hooks that let you make changes. I am not familiar with that plugin at all and I cannot really help with that. The only part I can help you with is the acf_form call, it should look something like this

    $settings = array(
      'id' => 'acf-group_59dd13c80be9e',
      'form' => false
    );
    acf_form($settings);

    also, note that you’ll need to figure out how to modify the header to include the call to acf_form_head() that’s mentioned in the acf_form() documentation.

    I was able to get the form to display by adding the code he provided to my get-details.php file, per the Themer’s Guide.

    ACF will not save anything if you do not include the call to acf_form_head() before anything is output on the page.

    YOu can also add something like this that will work

    add_action('init', 'add_acf_form_head_to_entire_site');
    function add_acf_form_head_to_entire_site() {
      acf_form_head();
    }

    But where? Who would best know where the get_header() line exists pertaining to The Events Calendar / Community Events plugin?

    #1364313
    Andras
    Keymaster

    Hey Steven,

    I looked around a bit and might have found something that could help.

    There is a template file,

    \the-events-calendar\src\views\default-template.php

    which you can override (=> Themer’s Guide), that has a ‘get_header()’ in it.

    For this template to work you will need to have the setting Events > Settings >  Display tab > Events Tempate > Default Events Template.

    If you want to use the ‘Default Page Template’ setting, then you either need to look around in your theme’s template files, search for it and add it there. If you have a page.php file in your theme, then that would be your best bet.

    In this case it is also recommended to use a child theme, so that your settings don’t get lost with a theme update.

    Let me know if this helps you move forward.

    Cheers,
    Andras

    #1365708
    Steven Frasier
    Participant

    Hi Andras,

    A fellow dev came up with this snippet.

    It was unsuccessful—at least the way I implemented it, within my theme’s functions.php—but I’m wondering if that offers you any clues.

    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);
                 
    ?>
    #1365756
    Cliff
    Member

    Steven, I’m working https://theeventscalendar.com/support/forums/topic/where-to-place-acf_form_head-to-save-submitted-data/ with you at this same time. At this point, is it a duplicate of this thread? If so, I can handle all your questions over there and we can Close this thread.

    #1379097
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Backend Integration of Advanced Custom Fields’ is closed to new replies.