• Okay, I am using the following code to create an “Edit Post” link:

    <?php
    echo do_action(‘gform_update_post/edit_link’, array(
    ‘post_id’ => $post->ID,
    ‘url’ => home_url(‘/?page_id=160/’)
    ) ); ?>

    This produces a link but now I am confused as to what I need to place on the page it is linked to? If I use the shortcode: [gravityform id=”1″ update] on the page it grabs the content of the edit page itself rather than from the post. So instead I used the get status to get the correct post ID (from gform_post_id) and grab the correct post data. While this works it’s insecure because users can just change the get url to edit other posts. I’m sure the nonce needs to come into play somehow – if it’s meant to be done this way. Can anyone help?

    https://wordpress.org/plugins/gravity-forms-post-updates/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Jupitercow

    (@jcow)

    You could use <?php do_action('gform_update_post/edit_link'); ?> in order to link to the current post with an edit link, but you will need to make changes to the template file to show the form…

    It looks like there is definitely a hole in the explanation, so, after looking closely at it, I am not surprised it is confusing… I will update it now and see if it helps.

    Thread Starter BenAttenborough

    (@benattenborough)

    Thanks for the speedy response, I appreciate it, especially as this is a free plug-in. The usage is probably obvious to most, but I was struggling a little so any help would be great.

    Thread Starter BenAttenborough

    (@benattenborough)

    Okay think I’ve resolved most of this now. However the edit form now only allows me to edit certain fields and not others. When I edit some fields the change doesn’t show on the published post. However the change does show when the edit field on the form is populated, which is very weird. It must be getting this info from somewhere but I don’t know where.

    BTW I am using custom post types and “Gravity Forms + Custom Post Types” to update these fields. One of these custom post type field updates fine but the other behave as described.

    I’ve had problems with Gravity Forms + Custom Post Types since Gravity Forms moved to version 1.9. In my case, both creating and changes to a taxonomy selection via checkboxes doesn’t save. I rolled back gravity forms to 1.8.X and that allowed all fields to be updated.

    Thread Starter BenAttenborough

    (@benattenborough)

    After a lot of head scratching and choice language I discovered that the fields need to be marked as “Unique Custom Field?” on the Gravity Form or they would not update.

    Regarding the original query, in case anyone is having the same trouble, this is what I did: The link created by do_action(‘gform_update_post/edit_link’); points to the single template, which I then setup to show the edit form using either:

    do_action(‘gform_update_post/setup_form’);
    gravity_form(1);

    OR

    $formshortcode = ‘[gravityform id=”1″ update]’;
    echo do_shortcode( $formshortcode );

    Which then allows users to edit the post. You also need a condition that looks to see if the user wants to see the post or edit it which you can do using the get method. Now I’m not certain this is the correct way to do things but hopefully that may help and Jupitercow may be able to say if this is right or not.

    I’m not sure if I should start a new thread or request clarity on this one but here goes:

    I’m using this (fantastic and free) plugin to edit/update a custom post type – “company”.

    – I’ve got http://site.com/add-company/ which loads my Add Company gform using a shortcode.
    – I’ve got http://site.com/company/company-name/ which is the page that is created from filling out the gform.

    I would like to have a link at the top of my page-company.php template that lets a user edit that page by essentially loading the Add Company gform and pre-filling in all the fields with the company info that called the edit link.

    Do I need to create a second gform called Edit Company? Should I be using the update shortcode in the page-company.php template?

    Thanks!

    Okay, I found a GitHub repo that contained some more installation instructions.

    For anyone with the same question:

    • Do not create a second Gravity Form. This plugin lets you use the original form, but prefills the form fields with the specific post/page content.
    • Create a page template for your “Edit [Post]” page. In it, include this and update the gravityform ID with the correct form ID for your original Add Post (mine is 2 in this case):
      <?
        $edit_post_id = isset( $_GET['gform_post_id'] ) ? (int) $_GET['gform_post_id'] : 0;
        if ( !empty( $edit_post_id ) ) {
          echo do_shortcode('[gravityform id="2" title="false" description="false" update="'.$edit_post_id.'" ]');
        }
      ?>
    • If you want to have a link/button on the custom post template, say your single-company.php, include this and note the ability to pass a CSS class and link text field:
      <?
        do_action('gform_update_post/edit_link', array(
          'post_id' => $post->ID,
          'url'     => home_url('/edit-company/'),
          'class' => 'btn',
          'text' => 'Edit Company'
         ) );
      ?>

    Follow up questions:

    1. Taxonomy fields (checkboxes and radio) aren’t loading or saving values.
    2. I would like to have conditional logic for my submit button so that when I’m adding a new company, the submit button says “Add Company” (currently does this), but when I’m editing the company, the submit button says “Edit Company”.
    3. Is there a way of letting only specific users (not roles, but IDs) edit a specific post/custom-post?

    Thank you so much!

    Plugin Author Jupitercow

    (@jcow)

    I will finish up getting this stuff updated into the wp repo content this week. I am really sorry for the delay on this. Had a death in the family.

    Sorry for your loss @Jupitercow.

    Thread Starter BenAttenborough

    (@benattenborough)

    Really sorry to hear that. Don’t worry about this too much, I’m pretty much sorted now anyways.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Confused as to usage’ is closed to new replies.