PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

gform_after_submission; inherit post

  1. hittheroadjack
    Member

    I am using 'gform_after submission' to check input data and setting filters.
    Now I recognized that the form always submits two post to my database: a 'Untitled_??' named one with status 'inherit' and the real one with the given name and status 'published'.
    This is causing trouble because the first entry already triggers Subscribe2 to send out an email to notify subscribers of a 'Untitled_??' new post.
    I have tried 'gform_post_submission' with the same result.
    How can I avoid or suppress the 'inherit posting'? What is it good for ?

    Posted 13 years ago on Monday November 14, 2011 | Permalink
  2. I'm assuming this form has a Post Image field on it.

    Posts with a status of 'inherit' are attachments. Media library items are stored in the posts table and their status is set to 'inherit'. So these are attachments to the post.

    Your terminology is a bit confusing, because you said the first entry triggers Subscribe2 but "entries" are Gravity Forms form submissions, they aren't posts.

    But the post type for the attachments is going to be different than what posts are stored as. So you may need to make sure you only get posts in whatever code code you are executing. If you get all post types then you would run into things like this.

    Posted 13 years ago on Monday November 14, 2011 | Permalink
  3. hittheroadjack
    Member

    Yes, you are right: I was a little confusing.
    Found out the same meanwhile. Looks like Subscribe2 ( the code I am running) is getting the post_title of the child (attachment) not the parent (the post).
    I changed code now to
    [$post->post_title = get_the_title($post->post_parent);]

    Hope this helps.

    Posted 13 years ago on Monday November 14, 2011 | Permalink
  4. hittheroadjack
    Member

    This did not help. Now it is showing the author's name instead.
    Assuming that, when firing the 'gform_after_submission', the post plus it's children for attachments are inserted, how can I get the post_title of the parent then?
    Also the permalink is a little confusing because it shows
    'http://my_IP/wordpress/2011/untitled_79/' with a customized structure of '/%year%/%postname%/'. So the postname is 'Untitled_79' like in the child post_title not like the parent post_title 'Test-Map4' or the parent post_name 'test-map4'
    How comes?

    Posted 13 years ago on Monday November 14, 2011 | Permalink
  5. hittheroadjack
    Member

    Found the reason for my probs:
    I had this three fields in my forms: a single line text(1), a Post Title(2) and a Body Field(3).
    For some reason, I used the single line input(1) via tag also in (2) as PostTitle in form of {input:1}.
    Somehow, on submission the Post Title field(2) came in empty, although text was entered into (1). This caused the 'Untitled_**' naming and all subsequent failures.
    Changed to use the Post Title field(2) as entry point and dropped (1). It works now but I lost the 'no duplicates' checkbox which is available in (1) but not in (2).
    What is the reason for this behaviour? Inserting the merge tag should fully replace the content of the Post Title field - at least at submission.

    Posted 13 years ago on Tuesday November 15, 2011 | Permalink
  6. The Post Title field doesn't have the no duplicates because of it's a unique field type and involves both entry and post interaction so it wasn't a feature that was added.

    The problem could be related to how and when post fields are executed. It's possible this code executed before the merge tags were parsed.

    Can you reliably reproduce this issue with a Single Input and Post Title field using the content template?

    Posted 13 years ago on Tuesday November 15, 2011 | Permalink
  7. hittheroadjack
    Member

    I am not sure what you want me to do because I am using the German translations of GF. Do you mean the content template in a body field?
    I can check putting a Single Input and a Post Title as a tag into the content field and see what happens or I do a var_dump($entry) in the callback function of my gform_after_submission hook. I guess the latter will be more enlightening or I do both together.
    I am highly interested to use the Single Input field because this is a user input. They have no glue what's already in my database when they type it. Otherwise, I have to set a filter to avoid duplicates, bouncing back to user, re-enter and all that stuff.
    Is there a hook later in time, maybe gform_post_submission, where I can rely on the merge tags being parsed?

    Posted 13 years ago on Tuesday November 15, 2011 | Permalink
  8. hittheroadjack
    Member

    Now I have set up a test. the result is: it can be reproduced!
    This is what I did :
    [5] is the single line input field
    [2] is the Post Title field with a merge tag in the content template like this {input:5}
    [3] is the body field
    the callback function of the gform_after_submission looks like
    function var_mail($entry, $form){
    var_dump($entry);
    wp_mail('dietmar@herian.de', 'Test GF', print_r($entry,True));
    wp_mail('dietmar@herian.de', 'Test GF', var_dump($entry,True));
    }
    this is what I get in the email:

    Array
    (
    [id] => 443
    [form_id] => 11
    [date_created] => 2011-11-16 13:51:03
    [is_starred] => 0
    [is_read] => 0
    [ip] => 82.135.31.79
    [source_url] => http://82.135.31.79/wordpress/cat_show_test/
    [post_id] => 1103
    [currency] => EUR
    [payment_status] =>
    [payment_date] =>
    [transaction_id] =>
    [payment_amount] =>
    [is_fulfilled] =>
    [created_by] => 1
    [transaction_type] =>
    [user_agent] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0
    [status] => active
    [5] => title
    [3] => some text from body
    [1] =>
    [2] =>
    [4] =>
    )
    $entry[2] is empty at firing the hook - it should be equal to $entry[5], if I am not wrong about the function of merge tags.
    And btw : you get exectly the same result when using the gform_post_submission hook

    Posted 13 years ago on Wednesday November 16, 2011 | Permalink
  9. The problem is going to be the content template is only used to create the post. It's not stored as the value for that field.

    An alternative solution to what you want to do is going to be to scrap using the Single Input that populated the Post Title and instead use the Post Title.

    Since the Post Title field doesn't currently have the No Duplicates features what you will need to do is use the gform_validation field and write some custom validation to do your own check.

    The gform_validation hook has a tutorial here:

    http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_validation%22_Hook

    Posted 13 years ago on Wednesday November 16, 2011 | Permalink
  10. hittheroadjack
    Member

    Thanks for looking into my problem.
    Knowing all this now, another solution comes to my mind :
    What if I simply take [5] and write it to [2] using a hook which is fired just before the post is created. That should solve the problem because direct entry to Post Title field is taken as the postname.
    Is there such a hook or filter? possibly 'gform_post_data' ?

    Posted 13 years ago on Wednesday November 16, 2011 | Permalink
  11. I believe the hook you would want to use would be the gform_pre_submission hook:

    http://www.gravityhelp.com/documentation/page/Gform_pre_submission

    This hook fires after validation but before the entry is stored and the post is created.

    Posted 13 years ago on Wednesday November 16, 2011 | Permalink
  12. hittheroadjack
    Member

    Thanks!
    I'll try that!

    Posted 13 years ago on Wednesday November 16, 2011 | Permalink
  13. hittheroadjack
    Member

    Tried it and worked well, so far!
    But now I have another issue maybe related to the above. I have a image file upload field in my form and whenever my users are typing German umlauts the $entry[n] contains the right representation also after submission. The file is targeted as thumbnail image for the post. When I look at the uploaded file name, it has been transferred to the standard WP upload folder and to the hashed GF upload folder, but both have the umlauts converted to HTML entities and subseqently, is not displayed as a post_thumbnail. Looking at the database the GUID of the thumbnail points to the WP standard upload folder but the file name shows umlauts. Because they are not the same, it will not display. I have traced it back to the line 1870 in forms_model.php and the target there is the GF hashed upload folder/file name with umlauts. After that may debugger won't work and crashes when the database is accessed. So ,I can't tell what happens after.
    Long story, short question: where happens the fault? Is it the move_uploaded_file() function?
    It seems to happen during the file transfer. Anything I can hook or filter into?

    Posted 13 years ago on Friday November 25, 2011 | Permalink
  14. hittheroadjack
    Member

    Another question: When using the 'gform_pre_submission' hook you get a $Form object as hand-over parameter. This does not contain the $Entry object or the values, does it? How can I make changes to the values in the $entry[n] before submission to the database?
    I tried also the 'gform_post_data' and 'gform_save_field_value' but they do not seem to be fired in this case.

    Posted 12 years ago on Sunday November 27, 2011 | Permalink
  15. hittheroadjack
    Member

    Auto-reply to my question 3 days ago : it is the move_uploaded_file() function!
    Transferring the files using this function converts umlauts . Since GF is not using wp_handle_upload function from WP (why?) you do not get hooks or filters short before transferring the upload. So I had to modify the plugin code(!) to get rid of this nasty thing. I hate doing that because of obvious reasons.
    Are there any plans to insert a hook/filter there or to use wp_handle_upload in future??

    Posted 12 years ago on Wednesday November 30, 2011 | Permalink