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.

Append text to a custom field

  1. hunsford
    Member

    My theme uses a URL stored in a custom post field to display images, and my goal is for users to be able to provide a file name in Gravity Forms to which I can then prepend the remainder of the image URL.

    I've reviewed a thread about appending fields to post content (http://forum.gravityhelp.com/topic/question-on-post-forms), which is similar to what I'm hoping to accomplish, but I can't seem to get the modifications right. I appreciate any help.

    Posted 14 years ago on Friday February 19, 2010 | Permalink
  2. hunsford
    Member

    Perhaps the presubmission handler or the post-submission handler would be more appropriate for what I wish to do.

    My form has a field where users can upload an image for a post (i.e., Post Fields - Image). From that field, I'd like to be able to take the file name, prepend the remainder of the image URL, and insert it into a custom field on the form (i.e., Post Fields - Custom Field).

    The end result would be that after the user uploads an image file and submits the form, one of the Gravity Form handlers could be used to build the URL to that image and insert it into a custom field in the post. Is this possible?

    Posted 14 years ago on Monday February 22, 2010 | Permalink
  3. Yes, you want to use the post_submission hook.
    Try the following:

    add_filter("gform_post_submission", "create_custom_field", 10, 2);
    function create_custom_field($entry, $form){
    
        //NOTE: replace 1 with your actual form id
        if($form["id"] != 1)
            return;
    
        //Getting file name.
        //NOTE: replace 24 (in $entry[24] with your actual field id
        list($image_url, $filename) = explode("|:|", $entry[24]);
        $pathinfo = pathinfo($image_url);
        $filename = $pathinfo["basename"];
    
        //creating custom field
        $url = "http://your_photo_url/" . $filename;
        update_post_meta($entry["post_id"], "your_custom_field", $url);
    }
    Posted 14 years ago on Monday February 22, 2010 | Permalink
  4. Galaxico
    Member

    Hi, I am looking for this solution as well. This looks perfect, Alex. Thanks!

    One question I have is: In order to replace the "24" in $entry[24], where should I look to actually find the "filed id"? Thanks =)

    Posted 14 years ago on Friday March 12, 2010 | Permalink
  5. Galaxico
    Member

    Nevermind, I was checked the source code on the "create form" page and found it there =)

    Posted 14 years ago on Friday March 12, 2010 | Permalink

This topic has been resolved and has been closed to new replies.