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.

Auto-Populate the Post Title from Taxonomy & Date

  1. So... I have a form that let's the user select a "Start Date", "End Date" and a "Subject" (it's for a school). The "Subject" is a list generated by a set of custom taxonomies. The "Start" and "End" dates right to custom fields "start_date" and "end_date". What I would like to do is auto-populate the post Title so that it is: "subject-start_date-end_date". Or some format similar thereof.

    The problem I'm running into is neither the date-picker field nor the taxonomy allow for "create content template" to work. If they did this would be a no-brainer. But as it is I have yet to figure it out.

    Thoughts?

    Posted 6 years ago on Thursday May 31, 2012 | Permalink
  2. David Peralty
    Administrator

    You could include a hidden field that is your post title, and then using gform_pre_submission you could merge the three form fields into your title.

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

    Posted 6 years ago on Thursday May 31, 2012 | Permalink
  3. AH!

    Yes, I had the field hidden... I had not yet (remembered?) tried pre_submission!

    Brilliant!

    Posted 6 years ago on Thursday May 31, 2012 | Permalink
  4. Got it.
    For those interested, here's the way to do it...

    add_filter("gform_pre_submission_filter_6", "add_title");
    function add_title($form){
    
    if ($_POST["input_35"] == '28') {
        $plan_title  = "Handwriting";
    } elseif ($_POST["input_35"] == '29') {
        $plan_title  = "History";
    } elseif ($_POST["input_35"] == '31') {
        $plan_title  = "Homeroom";
    } elseif ($_POST["input_35"] == '27') {
        $plan_title  = "Math";
    } elseif ($_POST["input_35"] == '30') {
        $plan_title  = "Science";
    } elseif ($_POST["input_35"] == '26') {
        $plan_title  = "Shirley English";
    } elseif ($_POST["input_35"] == '25') {
        $plan_title  = "SWR";
    }
    	$plan_title .= " | " . $_POST['input_6'] . " - ";
        $plan_title .= $_POST['input_7'];
    
        $form ["postTitleTemplate"] = $plan_title;
        $form ["postTitleTemplateEnabled"] = true;
    
        //returning modified form object
        return $form;
    }

    Since it's coming from a taxonomy you have to reference the value ID # and give it a name (if you want a name.) If anyone knows a better way to fix that, let me know... but this works.

    Posted 6 years ago on Friday June 1, 2012 | Permalink