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.

Save image field and post title also as custom fields?

  1. jangro
    Member

    I have a submission form that saves several fields of data as custom fields that I use in displaying the post.

    In order to get the post saved as a draft post, I have to have a Post title field. That's fine, but I want that same information put in a custom field. I've worked around this by forcing the user to enter the same data twice. (blech.)

    I also get an image upload and I want the URL placed in a custom field. I don't have any workaround to this. So I have to copy the URL in later. (blech.)

    Is there any way to accomplish these two things?

    The form is here: http://www.pimpmysafari.com/submit

    Thanks!

    Posted 13 years ago on Friday August 6, 2010 | Permalink
  2. Here is a quick snippet to get the post image url into a custom key. See if you can't use this as a base to figure out part two of your question: http://pastie.org/1080289

    Values to change to make this work with your form:

    if($form['id'] != 1) return;

    Change "1" to the id of your form.

    $postimage = explode('|:|', $entry[29]);

    Change "29" to the id of your post image field.

    update_post_meta($postid, 'image', $postimage[0]);

    Update 'image' to whatever you want the custom field to be.

    Hope that helps. :)

    Posted 13 years ago on Friday August 6, 2010 | Permalink
  3. jangro
    Member

    Worked like a charm, thank you!

    It took me a while to figure out the field ids. For anyone else reading this, the easiest way that I could find was to add the field to the notification body which shows the ID. (though I'd already dug it out of the database before I found that.)

    Is there a more obvious place for the field IDs that I missed?

    Posted 13 years ago on Friday August 6, 2010 | Permalink
  4. Easiest way to see the field IDS is to view source or use a page inspector like FireBug in FireFox to view the page source and see what the field ids are. They are present in the HTML.

    Posted 13 years ago on Friday August 6, 2010 | Permalink
  5. Kevin Geary
    Member

    I'm not sure how to make this work. Where do you place the snippets???

    Posted 13 years ago on Saturday August 7, 2010 | Permalink
  6. Any custom code to use API hooks to change how Gravity Forms functions would be placed in your themes functions.php file.

    Posted 13 years ago on Sunday August 8, 2010 | Permalink
  7. Thankyou for this
    - Ali

    Posted 13 years ago on Saturday October 23, 2010 | Permalink
  8. I can't seem to get this to work, using 1.5.beta1

    here is form my export:

    http://pastie.org/1285755

    add_action("gform_post_submission", "update_form_post", 10, 2);
    function update_form_post($entry, $form) {
    
        if($form['id'] != 4) return;
    
        // update post image
        $postimage = explode('|:|', $entry[1]);
        $postid = $entry["post_id"];
        update_post_meta($postid, 'imageurl', $postimage[0]);
    
    }

    Any clue as to what I'm doing wrong here?

    I believe I've set the form and entry ids properly. I've tried with an existing custom field name and a non-existent field, no dice.

    Posted 13 years ago on Tuesday November 9, 2010 | Permalink
  9. 1.5 Beta 1 has a bug on the gform_post_submission hook. The entry information is not getting passed to that hook properly. Email me at alex@rocketgenius.com and I will send you another beta version with the fix.

    Posted 13 years ago on Wednesday November 10, 2010 | Permalink