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.

Automatically create forms with WP 3 Network mode, modifying wp-config.php

  1. Do you have any more detailed explanation of how to automatically create forms with WP network mode? I saw in the new version overview the info below but I'm not a coder and still had some questions.
    What is typically replaced in the "full/path/to/"? Is that gf_import.xml file automatically created or should it already exist? If it's created, where should it go within the WP folders (that might answer my first question about the path...). I know these are probably basic questions but I tried a few ways of modifying the wp-config.php and ended up getting errors. Thanks.

    =========== from the new version release notes
    When a new site is created, Gravity Forms can automatically import forms into that new site using the standard Gravity Forms XML export file. You can pre-define the export file to import in your wp-config.php file by adding define(“GF_IMPORT_FILE”, “full/path/to/gf_import.xml”);
    Along with the ability to create forms automatically in WordPress 3.0 Network mode, themes can now include a form export file and tell Gravity Forms to create a form(s) when the theme is activated. You can pre-define the export file to import in your themes function.php file by adding define(“GF_THEME_IMPORT_FILE”, “gf_import.xml”);
    ============

    Posted 13 years ago on Wednesday August 25, 2010 | Permalink
  2. You place the export XML file anyway you want on your web server. There is no designated place. You can place it in your wp-content/uploads folder if you would like. Or you can place it in the root. It's up to you.

    The full path is the absolute path to the file on the web server. You may need to contact your web host to ask what the absolute path to the file would be if you are unsure. You could also use a global WordPress variable to determine the absolute path. This variable is ABSPATH.

    An example of this variable in use with the export file located in the wp-content/uploads folder:

    define("GF_IMPORT_FILE", ABSPATH . "wp-content/uploads/export.xml");

    But you can place the export file wherever you want as long as you path to it correctly.

    Posted 13 years ago on Wednesday August 25, 2010 | Permalink
  3. Thanks Carl. That really helps!

    Posted 13 years ago on Wednesday August 25, 2010 | Permalink
  4. I have been attempting to get a form to import on a new site creation for a while now. Can't seem to get it to take.

    I have this in my theme's functions.php file towards the end:

    define('GF_THEME_IMPORT_FILE', ABSPATH.'wp-content/themes/mycustomtheme/gform.xml');

    Yet it won't import at all when I do this. As far as I can tell the link to the file is accurate since it is in the same folder as the functions.php. Any thoughts or suggestions?

    Posted 13 years ago on Monday March 7, 2011 | Permalink
  5. When using the GF_THEME_IMPORT_FILE functionality you don't use an absolute path, it assumes it's in the theme folder itself. So if you place the gform.xml file in the theme folder can simply do:

    define('GF_THEME_IMPORT_FILE', 'gform.xml');

    Posted 13 years ago on Monday March 7, 2011 | Permalink
  6. I am also trying to get GF_THEME_IMPORT_FILE to work. The XML file that I have is in the theme folder and I am defining the variable in my theme's functions.php file. It's doesn't seem to be firing. The theme is on an multisite installation so it should work for each site that uses this theme but it's not working. Is there multisite support for themes using GF_THEME_IMPORT_FILE?

    If it is firing off, is there some way that I can tell if why it isn't working?

    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  7. One more thought... I am using a child theme and the code below is returning the name of the parent theme. It may think that the form is already loaded. Could this be the problem?

    $themes = get_option("gf_imported_theme_file");

    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  8. I don't think it is related to the child theme. The function in gravityforms.php calls get_stylesheet_directory:

    [php]
    GFExport::import_file(get_stylesheet_directory() . "/" . GF_THEME_IMPORT_FILE);

    That will return the child directory if one is being used:
    http://codex.wordpress.org/Function_Reference/get_stylesheet_directory

    Is this still not working?

    Posted 11 years ago on Thursday February 14, 2013 | Permalink
  9. No, it's not working. The code I am referring to is line 438 in gravityforms.php:
    $themes = get_option("gf_imported_theme_file");

    It is returning the name of the parent theme. I don't know if that is the source of the problem or not. Here is what I am doing.
    Create a new blog in my multisite setup
    the default theme is twenty twelve
    I activate the child theme with this in the child theme functions.php define('GF_THEME_IMPORT_FILE', 'gform.xml');

    This should kick off when the child theme is activated, right?

    This will be a nice time saver for my multisite implementation and I am looking forward to making it work. What is the next step in figuring this out?

    Posted 11 years ago on Friday February 15, 2013 | Permalink
  10. According to the documentation: http://www.gravityhelp.com/documentation/page/Advanced_Configuration_Options#GF_THEME_IMPORT_FILE the path to the file should be a URL not a filesystem path. Can you change that and see if it works?

    Posted 11 years ago on Monday February 18, 2013 | Permalink
  11. I initially pointed it to an Amazon S3 public url and that didn't work so I tried the relative path as mentioned higher up in this thread which also didn't work. My implementation for this feature is on a multisite environment where the domain is different every time. Can I use a WP function like get_stylesheet_directory() to form the path instead?

    So instead of this:
    define("GF_THEME_IMPORT_FILE", "http://www.domain.com/path/to/gf_import.xml");

    It would look like this:
    define('GF_THEME_IMPORT_FILE', get_stylesheet_directory() . '/gf_import.xml');

    Posted 11 years ago on Thursday February 21, 2013 | Permalink
  12. Or more appropriately, get_stylesheet_directory_uri(). :)
    define('GF_THEME_IMPORT_FILE', get_stylesheet_directory_uri() . '/gf_import.xml');

    Posted 11 years ago on Thursday February 21, 2013 | Permalink
  13. Yes, you can use that WordPress function in your theme's functions.php. You should try to echo that constant somewhere to be sure it contains what you think it does, as a debugging step.

    Posted 11 years ago on Saturday February 23, 2013 | Permalink