Please Note: We are no longer using forums to facilitate standard support. 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.

Can Pages be created from form submissions?

  1. I thought I read earlier that Pages could not be created (only posts) but was wondering if I was imagining that. Is there any word on creating Pages using form submissions? Just curious.

    Thanks

    Posted 5 years ago on Friday November 27, 2009 | Permalink
  2. That can't be done via the UI, but the following code snippet will get the job done.
    Place it in your template's functions.php file. Make sure to replace XXX with the appropriate form id.

    add_filter("gform_post_data", "set_post_type", 10, 2);
    function set_post_type($post_data, $form){
        if($form["id"] == XXX){
            $post_data["post_type"] = "page";
        }
        return $post_data;
    }
    Posted 5 years ago on Friday November 27, 2009 | Permalink
  3. Thanks Alex. I see I will just replace XXX with the ID of the form I want to use to create Pages. I can also see how to extend this even further to add things like the page template and parent page. Thank you for posting this.

    Posted 5 years ago on Saturday November 28, 2009 | Permalink
  4. Yes, you can basically manipulate the post however you want with this.

    Posted 5 years ago on Saturday November 28, 2009 | Permalink
  5. is anyone online that can help me install this. I just purchased it and can't find any documentation for installation...thanks, I am so frustrated!

    Posted 5 years ago on Saturday November 28, 2009 | Permalink
  6. This is a off topic for this thread, I've replied in a new thread in the support forum below.

    http://forum.gravityhelp.com/topic/installating-gravity-forms?replies=1#post-1857

    Posted 5 years ago on Saturday November 28, 2009 | Permalink
  7. Hi there. I've tried the above but all I get is a blank browser page and find this in my php error log:


    [21-Jan-2010 14:14:26] PHP Fatal error: Cannot redeclare set_post_type() in /Users/dani/Code/WP/wpmu/wp-content/themes/avartti-theme/functions.php on line 163

    Posted 5 years ago on Thursday January 21, 2010 | Permalink
  8. Jan Egbert
    Member

    I had the same problem. I solved it by changing:

    set_post_type()

    to:

    formXXX_post_type()

    If you think of all the possibilities this will offer for custom post types...

    Posted 5 years ago on Thursday January 21, 2010 | Permalink
  9. We will be expanding the post field functionality to support custom post types (and pages) as an option in the field editor once WordPress 3.0 is released and custom post types become easier to access.

    Posted 5 years ago on Thursday January 21, 2010 | Permalink
  10. flameboyuk
    Member

    I there. Thanks for the help. I got the blank screens too and although the screen no longer goes white, your fix didn't work for me. It doesn't even give me the option to edit posts anymore. Any ideas?

    Posted 5 years ago on Monday April 26, 2010 | Permalink
  11. dannybull
    Member

    The following code worked for me (I'm running WordPress 2.8.4):

    add_filter("gform_post_data", "change_post_type", 10, 2);
    function change_post_type($post_data, $form){
        //only change post type on form id X
        if($form["id"] != 1) // You need to change your form ID here
           return $post_data;
    
    	   // Add other page data to change
    	   $post_data["post_type"] = "page";
    	   $post_data["post_parent"] = 42;
        return $post_data;
    }
    Posted 5 years ago on Monday August 23, 2010 | Permalink
  12. How can this:

    $post_data["post_parent"] = 42;

    be changed to pass the ParentId from the form?

    Posted 4 years ago on Sunday November 21, 2010 | Permalink
  13. Just to clarify, do you want to change it so that the "post_parent" is set to the page/post that the form is embedded to?

    Posted 4 years ago on Monday November 22, 2010 | Permalink
  14. senat
    Member

    Hi, I have tried all of the above codes in the functions.php file, is that the wrong file? Or is this some kind of conflict? I get the following error no matter which one:

    HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

    Posted 3 years ago on Wednesday October 19, 2011 | Permalink
  15. senat
    Member

    Hi, is there a way to generate a page as per "We will be expanding the post field functionality to support custom post types (and pages) as an option in the field editor once WordPress 3.0 is released and custom post types become easier to access."

    Or do I still need to modify functions.php?

    Posted 3 years ago on Wednesday October 19, 2011 | Permalink
  16. A 500 internal server error means you have a syntax error in the file you just modified. Please post your functions.php to pastebin.com or pastie.org and we'll help you find the error. If you have access to logging on your host, the error should be logged as well.

    Posted 3 years ago on Wednesday October 19, 2011 | Permalink
  17. senat
    Member

    Thanks, it's here
    http://pastie.org/2725128

    Posted 3 years ago on Wednesday October 19, 2011 | Permalink
  18. senat
    Member

    Oh also
    [19-Oct-2011 17:58:20] PHP Fatal error: Cannot redeclare set_post_type() (previously declared in /home1/carclubb/public_html/diaperdeals/wp-includes/post.php:1323) in /home1/carclubb/public_html/diaperdeals/wp-content/themes/freshlife1/functions.php on line 28

    Posted 3 years ago on Wednesday October 19, 2011 | Permalink
  19. Looks like the function name set_post_type is being used by WordPress, which is why you have this error. Rename the function, on two lines (22 and 23 in the pastie). Anything that won't conflict, like senat_set_post_type. Change that on both lines and see if that works. It will get rid of the fatal error for sure.

    Thanks for the troubleshooting information. It helps a lot.

    Posted 3 years ago on Wednesday October 19, 2011 | Permalink

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

Support Tickets

Open A New Support Ticket
 Open A New Priority Support Ticket *

* Developer license holders only