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.

Targeting a specific form with gform_after_submission

  1. snails007
    Member

    I have a form (form id 3) embedded on a single post page and I am wanting it, once submitted, to publish the post that was just submitted and then change the post status of the single post that I am on to 'draft'.

    This works perfectly except that also I have 2 other forms on the site and the code below is targeting another form. So when the other form is submitted on it's page it is also changing the status of the page it is on to 'draft'.

    I only want to change the status to draft when I am using form number 3. What have I done wrong??

    // Action to change post status of project to draft after being selected
    add_action("gform_after_submission", "set_post_content", 10, 2);
    function set_post_content($form){
    
    	//only for form id
        if($form["id"] == 3)
           return $form;
    
        //getting post
        $post = get_post($post->ID);
    
        //changing post content
        $post->post_status  = "draft";
    
        //updating post
        wp_update_post($post);
    }
    Posted 12 years ago on Saturday May 5, 2012 | Permalink
  2. David Peralty

    If you want to target just that form, you'll want to use:
    gform_after_submission_3 then you don't need to have your if statement and it should work fine.

    Posted 12 years ago on Monday May 7, 2012 | Permalink