最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How do I add the same contact form to multiple wordpress sites and capture the response in one place or database?

programmeradmin2浏览0评论

I own a network of 100+ Wordpress based websites. All website are separate installations of Wordpress and are on different servers. I would like to

  1. create one contact form
  2. have it shown in the sidebar all of my Wordpress websites and
  3. capture the responses in one database (instead of getting 100's of emails).

Ideally the form would be created and hosted in one place and then embedded into the other blogs (via iframe or other method?). That way I'd only have to make changes to the form in one place and have them apply to all sites.

I know there are countless plugins for creating contact forms, but none that would seem to address this situation. Any help would be greatly appreciated. Further, I'm not opposed to hiring someone to help with this situation if it's beyond the scope of this websites.

All the best, JB

I own a network of 100+ Wordpress based websites. All website are separate installations of Wordpress and are on different servers. I would like to

  1. create one contact form
  2. have it shown in the sidebar all of my Wordpress websites and
  3. capture the responses in one database (instead of getting 100's of emails).

Ideally the form would be created and hosted in one place and then embedded into the other blogs (via iframe or other method?). That way I'd only have to make changes to the form in one place and have them apply to all sites.

I know there are countless plugins for creating contact forms, but none that would seem to address this situation. Any help would be greatly appreciated. Further, I'm not opposed to hiring someone to help with this situation if it's beyond the scope of this websites.

All the best, JB

Share Improve this question asked Feb 6, 2011 at 14:44 John BatesJohn Bates 31 silver badge2 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 2

the easiest way i can think of is to use a plugin that creates a form by shortcode like contact form 7 for example and I'll break it in to easy steps.

  • Create the form on your main site or what ever site you would like to manage the forms data through.

  • Create a page template with no header or footer just a plain loop and call the_content.

  • Create a new page , add the Form's shortcode to it and set the template as your new page template.

  • Get the URL of that page and create an iframe to it.

  • On each site you would like to show the form just add the Iframe code to a sidebar text widget.

and that should do it.

Oh wait, you will probably need to add Contact form 7's Javascripts and css and i just read your question again and you are looking to save this forms in to database and since this plugin does'nt save to database on its own you can use an extenstion plugin called Contact Form 7 to Database or use a different forms plugin all together.

Hope this helps

It better you can develop a form with PHp / HTML and store the form in javascript function and test it submission to a database folder.

Call that javascript by jsut adding a script code to number of website and all the submission will go to one database

you can use this database to transfer the form queries and responses to Crm

Alright, for anyone seeking a solution here.

Here are the steps that work for me. Please note this is a hack, but it works. It is done using CF7 and ACF.

  1. Create your form on the main site.
  2. Create a function in your functions.php to print out (using do_shortcode) the general shortcode of your form (given by CF7)

    function get_general_field($variable) {
      if (get_current_blog_id() != 1) {
        switch_to_blog(1);
      }
      $custom_fields = do_shortcode(get_field($variable, 17284));
    
      if (ms_is_switched()) {
        restore_current_blog();
      }
      return $custom_fields;
    } 
    
  3. Now create a general ACF field group for your main site (make it appear only on site 1 for example, which include a text field for your "GENERAL FORM"

  4. You will create a private page on your main site, call it "GENERAL FIELDS" in which you will paste the shortcode from CF7.

  5. Now in your theme file, you can simply call the get_general_field('FIELD_NAME').

  6. At this point, the form will show, but you need to add css and js for ajax validation.

       if( class_exists( 'WPCF7' ) ) {
           function yuna_design_manually_enqueue_wpcf7_scripts() { 
           global $post;
           if( is_single() || strpos( $post->post_name, 'group' ) ) {
             if( function_exists( 'wpcf7_enqueue_scripts' ) )
               wpcf7_enqueue_scripts();
              if( function_exists( 'wpcf7_enqueue_styles' ) )
               wpcf7_enqueue_styles();
             }
          }
        add_filter( 'wpcf7_load_js', '__return_false' ); // Disable CF7 Js
        add_filter( 'wpcf7_load_css', '__return_false' ); // Disable CF7 CSS
        add_action( 'wp_enqueue_scripts', 'yuna_design_manually_enqueue_wpcf7_scripts' );
      }
    
  7. (Here is the hack) Now, everything is working but you have two errors in your console and a looping form who never calls back on subsites (other than main site #1). This is because it is calling the subsite for validation, and since you don't have a form with the proper id, it returns and error.

  8. (after some thoughts and testing, I think this might be optional) You need to modify two files from CF7 (I am using Version 5.1.7). First one is: contact-form-7/includes/rest-api. add the following code right after the opening of wpcf7_rest_api_init(){ :

      if (get_current_blog_id() != 1) {
         switch_to_blog(1);
      }
    

...where 1 is my main site id...

and also don't forget to add the following code, right at the end of that function (before the closing "}" ) :

if (ms_is_switched()) {
    restore_current_blog();
}
  1. you need to look for the 2 instances of "wpcf7.getId( $form )" inside contact-form-7/includes/js/scripts.js. You will find a dynamic link validation, which you'll need to make it static and pointing to your main site url. Basically this:

    url: wpcf7.apiSettings.getRoute( '/contact-forms/' + wpcf7.getId( $form ) + '/feedback' ),

will need to look like this:

url: 'HTTPS://YOURWEBSITEURL.COM/wp-json/contact-form-7/v1/contact-forms/' + wpcf7.getId( $form ) + '/feedback',

And voilà, test your form in a subsite and the ajax errors should be working fine. You now have one form usable for multiple sites in your wordpress setup.

Please note, this is quite temporary solution, a hack made for a project of mine and it would be great to have instead a multisite support for CF7, since this is not really a big tweaking to be done from plugin authors.

Please feel free to comment and add on this solution. I was looking a long time online and did not find a thing working properly.

Cheers,

Maxime Bellefleur

Wordpress integrator for small bussiness www.yunadesign

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论