Posting event with a gravity form.

This topic contains 30 replies, has 5 voices, and was last updated by  Stephen Harris 3 years, 8 months ago.

Viewing 15 posts - 1 through 15 (of 31 total)
  • Author
  • #2845

    I need to allow frontend event posting and want to use a gravity form with some custom fields. It looks like this will not be easy to do with how the data is stored.

    I just need the dates (start end) and if no start/end time a check for an all day event. If the event organizer wants a reoccurring I will have them contact me to set that (so it is not abused from the front end). I believe I have working code to change gravity’s date to a unix time (but it only has date no time) as I think this needs to happen.

    Could anyone shed some light on how I could do this?


    Hi Michael,

    I’ve not used Gravity Forms (though I believe some people have used it with Event Organiser). For the front-end posting you might find the following useful:

    I believe Gravity Forms allows to you to add various fields (including date and time fields) and provides hooks so you can process form submissions. From that you can take the date/time submissions and convert it to a DateTime object required by eo_insert_event().

    I’m not really able to help with the Gravity Forms part – but if you’re able to pastebin some code, I’ll be able to give a few pointers on integration with EO. Most of what you need to know is in the linked article though.

    Stephen Harris

    I forgot about that article I taken in so much in the last few months. I’ll see what i can come up with.


    Hi Stephen
    Here is a Pastebin with what I’d hoped would work but alas my php skills…well they suck frankly.
    I’ve no problem believing this is all wrong because I can’t make it work.


    Ok so it does work sort of but…
    I get double posts one made by the gravity form and one from EO.
    The post EO creates adds new venue with a number for a name and with the dates set but it’s also set to a draft.
    The gravity post has the right venue and category but no dates (this I knew) I’ve to find a different gravity hook maybe.


    So this Pastebin fixes the double post. I just have to get the venues to save the name rather then id.
    eo_insert_event seems to be setting my event to drafts. How can I change this?


    I’m sorry for filling your forum “thinking out loud”. But just keeping the progress updated maybe my noobness will help other wanting to do this.
    Fixing the post status was easily done using wp_insert_post args ('post_status'=>'publish',) plus I learned I can use wp_strip_all_tags() to clean the title and content as I needed.

    I still can not work out the venue. I can set the category without problem but the venue always returns the ID.
    I have the ID stored in $entry['5'] and don’t know how to get the name.
    I tried adding this $event_venue = (int) isset($entry['5']) ? $entry['5'] : 0; but it still gives the ID in 'event-venue'=>array($event_venue),.


    One last thing I can not seem to work out also is how to keep my custom field data from the form when using eo_insert_event().

    These two things (venue issue above and this) and I am all set to relaunch our site. I am one week late and sooo want to get this off my plate (this is where all my desperation is coming from).


    Hi Michael – no worries, I’m sure many others will find this thread useful.

    Post Status

    The first argument in eo_insert_event() (see docs) is passed to wp_insert_post() (see codex). So anything like setting the event status (publish, draft) etc can be done by setting the post_status argument as appropriate.

    $post_args = array(
        'post_status' => 'publish'


    I take it you are selecting an existing venue, and not creating a new one? If so, you need to pass the venue ID (as an integer). If its not an integer then its interpreted as a slug, and since it probably doesn’t exist, it’ll create a new one:

     $venue_id = (int) $entry['5'];
     $post_args = array(

    Custom Data

    Is this custom data post meta? If so, eo_insert_event() returns the event’s post ID, so you can simply use WordPress’ update_post_meta() from there (see Codex)

    Stephen Harris

    Sweet! Thank you so much, venues set right and my custom fields are included.

    How can I set a featured image from my upload field? I’ve just begun looking into this bit now.


    When I let gravity handle inserting the post it would move the uploaded image and set it as featured. Because I have disabled it creating the post, how can move and attach the image stored in ($entry['3'] (full path) to my event.

    If I add this

    $url = $entry['3'];
    $tmp = download_url( $url );
    $desc = "Event Image";
    // Set variables for storage
    // fix file filename for query strings
    preg_match('/[^\?]+.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
    $file_array['name'] = basename($matches[0]);
    $file_array['tmp_name'] = $tmp;
    // If error storing temporarily, unlink
    if ( is_wp_error( $tmp ) ) {
    $file_array['tmp_name'] = '';
    // do the validation and storage stuff
    $id = media_handle_sideload( $file_array, $post_id, $desc );
    // If error storing permanently, unlink
    if ( is_wp_error($id) ) {
    return $id;
    $src = wp_get_attachment_url( $id );
    set_post_thumbnail( $post_id, $src );

    After submitting my form it hangs and does not complete and redirect as it should. The post is made but the is not attached.

    I have tried several thing but no luck with this thus far.


    The second argument of set_post_thumbnail() takes the thumbnail ID rather than src value.

    Alternatively, if Gravity forms provides a hook after creating the post, you can always use eo_update_post() (see docs) to add the event details, and do it that way round…

    Stephen Harris

    Looks like I can only hook and change the post before it is created and not after. Unless I can add EO’s data to it’s custom field _eventorganiser_event_schedule some how. I tried eo_update_post() but no dates saved.

    Maybe I can work out a different way to add an image from a custom field. I just want to delete the image when the event is deleted.


    Don’t touch the meta value _eventorganiser_event_schedule directly (other things need to be done!).

    Sorry, its eo_update_event() not eo_update_post(). If it doesn’t seem to work – have a look at what its responding with. It should work if the post is an event (but obviously post will need to exist!).

    I just want to delete the image when the event is deleted.

    Hook onto before_delete_post ( ) and get the thumbnail image ID and then use wp_delete_attachment().

    Stephen Harris

    I had to take a break. Things have been hard then I thought.

    I did use eo_update_event and not eo_update_post. If I let gravity make the post and use eo_update_event the event details are not added to the post.

    I will make a feature request in the right spot.

Viewing 15 posts - 1 through 15 (of 31 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.