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.

Modify Post Data (Title) on Submission

  1. I'm working on a form that creates a Post where I want the post title to be dynamically generated from a number of other form fields (essentially, the title is a tracking code made up of other codes generated by other fields).

    Using a content template on the Post Title does exactly what I want except for one thing: depending on the values a certain field (Form Field 7), the way the title is constructed changes. So I need to write a custom function that will create the Post Title based on some if statements.

    Due to the way my site is managed, I prefer to do this as a plugin rather than in the themes functions.php file.

    Here's what I've written:

    add_filter("gform_post_data", "create_proposal_title", 10, 2);
    
    function create_proposal_title($post_data, $entry) {
    
    if ($entry['7'] == 'NEWPRG') {
        $post_data['post_title'] = $entry['7']."-".$entry['17']."-".$entry['3']."-".$entry['9']."-".$entry['id'];
    
        }
        return $post_data;
    
    }

    However, this isn't working. I'm not sure what I'm doing incorrectly. Is there anything obvious with my syntax of use of the filter?

    Posted 11 years ago on Thursday July 12, 2012 | Permalink
  2. David Peralty

    Have you tried putting this in the functions.php file to see if it works before moving it to a plugin architecture? I am worried that it isn't being called because you are separating it from the normal hook system of Gravity Forms.

    Posted 11 years ago on Thursday July 12, 2012 | Permalink
  3. Ah! Okay. I can try putting it in functions. The site is a big, institutional multisite installation so functions is already a beast. That's why I was trying to avoid it. But I see what you mean.

    Posted 11 years ago on Thursday July 12, 2012 | Permalink
  4. David Peralty

    I understand, but the first step is to make sure your code is working as you expect before we try to move it out of the functions file :) Let me know if it works or doesn't.

    Posted 11 years ago on Thursday July 12, 2012 | Permalink
  5. Okay, I moved the code into functions.php, and it's still not working. The post gets created, but the title is not set correctly.

    One question: for the if statement where I'm testing the value of form field #7 ($entry['7']), should I be testing against the Label for the selection of the Value? I assumed Value and that's what the code above reflects. (I've actually tried both, and it doesn't seem to help.)

    Posted 11 years ago on Thursday July 12, 2012 | Permalink
  6. I don't know if it's kosher to bump a thread in here, but I'm wondering if anyone has any thoughts about why this code wouldn't be working (as a plugin or in functions.php).

    Posted 11 years ago on Monday July 16, 2012 | Permalink
  7. David Peralty

    Can you post your functions.php file on pastebin or something similar and link it so I can take a look? What kind of Post Title are you currently getting?

    Posted 11 years ago on Monday July 16, 2012 | Permalink
  8. Hi David,

    I set up a test WP instance to try and work through this. I'm just using TwentyTen as my theme, so the functions.php file is the standard one for that theme, plus my custom function (at the bottom). You can see it here:

    http://pastebin.com/hq7Y67v2

    In addition, here's the XML (from the form export XML file) for field #7:

    http://pastebin.com/60AKftVP

    Any ideas you have are appreciated!
    Thanks!

    Posted 11 years ago on Monday July 16, 2012 | Permalink
  9. Oops, I meant to mention: My ultimate goal is for the post title to be a concatenation of several other form field values, but, for testing purposes, I'm just using a string right now.

    The title I'm getting when I use this function is just "Untitled."

    Posted 11 years ago on Monday July 16, 2012 | Permalink
  10. Cathy, can you echo the value of $entry["7"] to see what it contains? Be sure you are targetting the right field?

    Alternately, can you change the conditional to something that will always be TRUE, so you can be certain the code is processed no matter what the $entry object contains? This will make sure your function is being processed.

    We need to start at the beginning and figure out where the problem lies. Thanks.

    If you'd like to export the complete form I can install your form and then see how your function works.

    Posted 11 years ago on Monday July 16, 2012 | Permalink