Event Submissions Using Gravity Forms in 2.0

Published on: October 26, 2011 | Categories: Tutorial

This tutorial works with both the open source events calendar as well as the PRO add-on.

One of the first issues that came to our attention after launching The Events Calendar/Events Calendar PRO 2.0 is that Tim Bowen’s awesome Gravity Forms walkthrough unfortunately no longer worked.

After looking into the issue this week, our developer John has identified a fix that should allow the original walkthrough to work. Just add this to your functions.php file:

add_action('save_post', 'save_tec_event_meta_from_gravity', 11, 2);
    function save_tec_event_meta_from_gravity($postId, $post) {
        if( class_exists('TribeEvents') ) {
            // only continue if it's an event post
            if ( $post->post_type != TribeEvents::POSTTYPE || defined('DOING_AJAX') ) {
                return;
            }
            // don't do anything on autosave or auto-draft either or massupdates
            if ( wp_is_post_autosave( $postId ) || $post->post_status == 'auto-draft' || isset($_GET['bulk_edit']) || $_REQUEST['action'] == 'inline-save' ) {
                return;
            }

            if( class_exists('TribeEventsAPI') ) {
                $_POST['Organizer'] = stripslashes_deep($_POST['organizer']);
                $_POST['Venue'] = stripslashes_deep($_POST['venue']);

                if( !empty($_POST['Venue']['VenueID']) )
                    $_POST['Venue'] = array(‘VenueID’ => $_POST['Venue']['VenueID']);

               if( !empty($_POST['Organizer']['OrganizerID']) )
                   $_POST['Organizer'] = array(‘OrganizerID’ => $_POST['Organizer']['OrganizerID']);


                TribeEventsAPI::saveEventMeta($postId, $_POST, $post);
            }
        }
    }

We tested this today and it worked without issue, so you guys should be all set with this. If anyone has any feedback or issues, give us a shout over at the forum and we’ll try to assist.

13 Responses to Event Submissions Using Gravity Forms in 2.0

  1. Pingback: Gravity Forms + Events Calendar Submissions | Modern Tribe Inc.

  2. Jamie O says

    Thanks very much for this. I’ve not yet purchased the Pro version as I hoped I’d be able to do this type of integration with the stand-alone version. Date of event submissions are working, but not any of the custom fields of data for venue / organizer as yet. Any help on that front would be appreciated – or is it a line in the sand that Pro is required to store all fields via Gravity Forms.

    • Shane Pearlman says

      It should work with the free version. You might watch the related thread in the pro support forum (anyone can read them). See if you get any useful tips.

  3. Al says

    Hey guys,

    Soo I’m stuck. I don’t think I know exactly where to put the added code in the functions.php. Here is a copy of my functions.php:

    http://bit.ly/uFAZHN

    When I try to update my functions.php, the site goes white and stops working entirely. I then have to overwrite the functions.php with the original file via FTP.

    I’m not a web developer really, but I think the tutorial is pretty straight forward. What am I doing wrong?

    Cheers,

    Jeromie

  4. Al says

    Sorry if it’s not the best place for support, I was getting a fatal error every time I tried to post in support under “Integration with Gravity Forms?”

  5. Blake says

    I followed all the instructions and it does submit an event, unfortunately the “date” and “time” and other custom fields are not being populated. Just the event title and the body information. Any help would be appreciated.

  6. Blake says

    I am now getting this too:
    syntax error, unexpected ‘&’ in /home/wahhadesign/livinoutloudmag.com/wp-content/themes/livinoutloud/functions.php on line 331

  7. Rob La Gatta says

    Hey guys. Happy to help with this — though I will note that the forum is definitely the best place to post when it starts getting technical like this. The “fatal error” issue you were experiencing, Al, should be gone by now…let me know if it’s still giving issues on your end.

    Blake: can you share the code you used in your functions.php file, so I can take a look at what might be causing that issue? Are you sure you followed Tim’s initial walkthrough & the addendum above to a tee? Just want to verify.

  8. Ashley says

    I also just got an error message trying to add the above code to my site. “Parse error: syntax error, unexpected ‘&’ in /home/content/32/8701132/html/wp-content/themes/canvas/functions.php on line 116″

    Please advise.

    Thanks!

    ~Ashley

    • Ashley says

      Oops, just saw the line where it says to post problems on the forum. My apologies– please disregard my previous comment on this post.

  9. Lorne says

    For those of you experiencing the syntax error problem, there is a problem with the code as it is displayed here… you need to replace every instance of the string “>” with the greater than symbol.

    For example, “$post->post” should read “$post->post”.

    (Hopefully the right symbols will mak it through comment moderation!)

    Happy Eventing!

  10. Lorne says

    Well, that didn’t make much sense…

    The string you need to replace is this (without the underscores):

    &_g_t_;

    Cheers,

    Lorne

    • Rob La Gatta says

      Thanks for sharing, Lorne. This will certainly be of value to other users down the road experiencing the same problem.