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.

Use form entry number as post name

  1. sascha
    Member

    Hi there, when submitting a post via a form I would like to use the "running" form entry number as part of the post title. I.e. if its the fifth entry in that particular form the post title would be:
    "job_ID_5"

    In another form it would be "office_ID_302" if it is the 302nd entry in that form.

    Hope that is clear...
    Is there a way to achieve this?

    Posted 12 years ago on Thursday December 1, 2011 | Permalink
  2. Hi, Sascha,

    I will be reviewing this today and get back with you soon.

    Posted 12 years ago on Thursday December 1, 2011 | Permalink
  3. Sascha,

    You can grab out the form entry id and append it to your post title using code like the example below:

    [php]
    add_filter("gform_post_data", "change_post_title", 10, 3);
    function change_post_title($post_data, $form, $lead){
        //only change post title on form id 3
        if($form["id"] != 3)
        return $post_data;
        //get entry id from lead array and build new post title
        $post_data["post_title"] = "test_" . $lead["id"];
        return $post_data;
    }

    Happy coding!

    Posted 12 years ago on Thursday December 1, 2011 | Permalink
  4. sascha
    Member

    Thank you Dana,
    that works great! One thing: is there a way to also save that new post title in the entries database of GF? Just so I can identify it..

    Posted 12 years ago on Saturday December 3, 2011 | Permalink
  5. Sascha,

    I can't think of any easy way to do that. The entry id is not available until the form entry has been created in the database, so it would require a form field to be updated directly using database queries after the entry is saved. The entry id is available to the post since the form entry exists at the point we are modifying the post title. I think the easiest way to identify the post is to display the Entry Id field in the admin in the entry listing for the form. You can use that ID to match it back to the post since that id will be in the post title.

    Posted 12 years ago on Monday December 12, 2011 | Permalink

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