Support » Plugin: Gravity Forms: Post Updates » Using in a template

  • Eh…
    Im working on a customize theme.

    and im trying to show the edit form and then use this edit plugin to preload and allow editing of a certain post for users.

    not enough documentation here…
    I tried this:

    echo gravity_form( 12);
     do_action('gform_update_post/setup_form', array('post_id' => $profile_id, 'form_id' => 12));

    This doesnt seem to work.
    What am I doing wrong?

    • This topic was modified 4 years, 11 months ago by Eric.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Eric

    (@shamai)

    ok:

    for those of you scratching your heads wondering how to make this work:
    the action must come first then echo the form.

    Now unfortunately for some reason the developers decided it would be smart to make it that only the author of the post or an admin can edit the post.
    grrr… I guess it makes sense if your embedding it on a page or something.

    Here i was using current_user_can() to decide if the form should even be output based on the post id and the user id. And they went ahead and made it more difficult :/
    sigh… ill play around and get back when i figure it out…

    Also beware users CAN change the update id via the hidden field and can ruin someone esles post. I would use pre_submission hook and reset it back to the current post in case it got tampered with…

    • This reply was modified 4 years, 11 months ago by Eric.
    • This reply was modified 4 years, 11 months ago by Eric.
    Thread Starter Eric

    (@shamai)

    ok i looked through the code…
    theres a lot more filters!!

    if you want to allow anyone to edit posts use:
    add_filter( 'gform_update_post/public_edit', '__return_true');

    Thread Starter Eric

    (@shamai)

    ok so altogether:

    for using in your theme templates and you want to let users (subscribers) edit a post, perhaps their profile post or something… I have a post type profile. Each user has a post there.

    You need to make a edit page and put this in the template for that page:

    
    //allow subscribers to edit post 
    //even though they are not the author
    add_filter( 'gform_update_post/public_edit',  '__return_true');
    
    //update post action
    do_action('gform_update_post/setup_form', array('post_id' => $post_id, 'form_id' => 12));
    
    //actual form
    echo gravity_form( 12, false, false);
    

    My form ID was 12.
    Lastly make sure you use conditionals and test to make sure on your own that this user can edit this specific post. In my site the post has a meta field that holds the subscribers ID.
    Once i test the current_user_id against it I show the form.

    And lastly, use pre_submission hook to make sure they dont tamper with the update post id.

    • This reply was modified 4 years, 11 months ago by Eric.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using in a template’ is closed to new replies.