Gravity Forms - Global forms for multisite - wordpress

I've a WordPress multi-site network with 20+ sites. and i'm using gravity forms for Contact/Signup/Subscription forms. I would like to create global form for my wordpress multisite installation. Is it possible that gravity forms save the form entries only into the main/parent site? I've tried using switch_to_blog() in children sites. but it is not working.any help would be appreciated :)

If you duplicate the form into all sites, you can make them all send their data to the main site by including this on the 'child' sites:
$formId = 1; //Put your form id here
add_filter('gform_confirmation_'.$formId, 'gform_confirmation', 10, 4);
function gform_confirmation($confirmation, $form, $entry, $is_ajax) {
//Switch to Main site
switch_to_blog(1);
//Insert the entry into the main site
$new_entry_id = \GFAPI::add_entry($entry);
//Switch back
restore_current_blog();
//Tidy up by deleting the entry from THIS site
$result = GFAPI::delete_entry($entry['id']);
return $confirmation;
}

Gravity forms stores data based on blog database table prefix,
in multisite all sites uses the same database but data are separated based on table prefix, the prefix are something like, wp_1_, wp_2_, wp_3_.....
if you have a site, like my.blog1.com with table prefix, wp_1_, gravity form store all the form entries of my.blog1.com to wp_1_rg_lead, wp_1_rg_lead_detail, wp_1_rg_lead_detail_long,
Now if you want to save those details on your parent install, you need to play around with the database and modify gravity form using hooks like gform_pre_submission or gform_after_submission
This post might help
http://www.endocreative.com/save-gravity-forms-data-custom-database-table/

Related

Wordpress: how to implement a sequence of pages other than template hierarchy

Being fairly new to Wordpress, I’m trying to understand how to implement a sequence of pages other than the sequence suggested by the template hierarchy.
Consider (as an example) a website where different products can be purchased. We have the custom post type “products”. Products can be selected and added to the cart. When the user wants to check out, he will be offered a sequence of pages for doing the checkout for one or more products.
What would be the best way to implement such a sequence? In normal websites, it is just a number of pages linking to each other. In Wordpress, at the time of writing the code the page id’s are unknown and will only be known after creating the pages in wp admin. After this, we can use the page id’s, but when rolling out to a different environment (for example from development to test or live), we have to create the pages again in wp admin, resulting in new page id’s. The page id’s will have to be altered in code. This is undesirable in my opinion, error prone, right?
Is there a way of dealing with this in Wordpress other than synchronizing databases? In other words, what is the best design for implementing a sequence of pages linking to each other, other than the normal wordpress template hierarchy flow?
As a solution I created a way to access permalinks based on logical id's both from php and javascript. When rolling out to a different environment only the mappings from logical id's to urls should be changed in one array in functions.php and you're done.
To enqueue your .js file in functions.php:
wp_register_script( 'aom_script', get_template_directory_uri() . '/script.js', array('jquery') );
wp_localize_script( 'aom_script', 'my_js_permalinks', aom_get_page_permalinks() );
wp_enqueue_script('aom_script');
Code in functions.php for storing and accessing the permalinks:
function aom_get_page_permalinks() {
$page_permalinks = array(
"home"=>get_bloginfo('url'),
"someurl"=>get_permalink(14),
"anotherurl"=>get_permalink(16)
);
return $page_permalinks;
}
function aom_get_page_permalink($page_id) {
$page_permalinks = aom_get_page_permalinks();
return $page_permalinks[$page_id];
}
Now if you need a permalink in php:
aom_get_page_permalink('someurl');
And if you need a permalink in javascript:
my_js_permalinks.someurl;

Wordpress Form Submit button GETS (or POSTS) form data to external page

We have a wordpress website that does marketing display, but now we want to allow a customer to submit an email and selection to a separate website with a landing page that will handle the backend DB work and finish them in the other website.
Something like,
www.ourmarket.com/getdata (on Submit button click GETS to...)
www.ouradminsite/landingpage.aspx (which processes the data that the use will not see then...)
www.ouradminsite/login.aspx (where the user can now login)
I am not familiar with WP at all, but I was able to create a page with a form that has the textbox/combobox I need.
I thought it would be something simple, but somehow it seems not. I read about AJAX and doing something in functions.php and creating a custom .js file, but when working on the marketing site I find no way to add this type of function in.
My fall back is to have the WP page just have a link to a generic landing page where they enter data, but it would be visually jarring to the customer unless I duplicate the WP site for one page.
Is there an easy way to just tell WP to redirect to an external page with a GET?
UPDATE--------------
I like to think I'm making progress. I found a link that may have given me a good start. I added a function to the functions.php file located in my WP theme. It starts like this:
add_action("gform_post_submission_4", "set_post_content", 10, 2);
function set_post_content($entry, $form){
//Gravity Forms has validated the data
//Our Custom Form Submitted via PHP will go here
// Lets get the IDs of the relevant fields and prepare an email message
$message = print_r($entry, true);
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
// Send
mail('myuser#mycompany.com', 'Getting the Gravity Form Field IDs', $message);
**wp_redirect("http://my.hearbuilder.com/hellomoto.aspx",301);**
}
From there I tried to edit the function to do that wp_redirect, just a simple one to start. This is added under the mail statement:
wp_redirect("http://my.hearbuilder.com/hellomoto.aspx",301);
From this link, when I fill out the form I can get the email, but the new page did not display. I added the exit; line and still got the same result, the page seems like it hangs.
The end result is that I need to have the new website landing page display (after it processes the data from the Wordpress form.
What am I still missing?
yes use wp_redirect()
if($_POST):
$textbox=$_POST['textboxname'];
$url= 'url'.'?custom=hello&textbox='.$textbox.'&anothervalue='.$anothervalue;
wp_redirect($url);
exit;
endif;
you can easily add the variables to the string as needed. The easiest way to control the url properly is to post the information to the same page , catch the post and redirect (place before get_header call or any output has started)
The other way is php Curl which is more difficult esp when dealing with .asp pages, but if you have access to the other server it makes figuring it out easier!

Return a unique number to the customer after apply on our form (wordpress)

I'm making a web site with Wordpress, in which there is a form that has to be filled by customers. I want for every customer that will apply, after complete the filling and get the success message, to get via email a unique number and then contact with the company for the rest procedures. I'm also using contact-form-7 plugin for the form. Any idea or any plugin that could do this automatically? Even if code is needed, let me know!
Thanks in advance!
You could use the contact-form-7-dynamic-text-extension plugin.
Install the plugin, add
/* Generate Quote Ticket */
function genTicketString() {
return substr(md5(uniqid(mt_rand(), true)), 0, 8);
}
add_shortcode('quoteticket', 'genTicketString');
to your functions.php and add
Your Reference number: [dynamictext ticket "quoteticket"]
to your form in contact form 7. (or make this field invisible through css)
Lastly, add [ticket] to your e-mail body.
Found this solution on http://wordpress.org/support/topic/contact-form-7-generating-reference-number and was written by AMCD.

How to create a profile page in Wordpress Multisite

I can't find a way to create a front-end profile page for all users under Wordpress Multisite Network. I also wanted the profile page to be on the main site and not on sub-sites if possible. I don't want to use any social network plugins like buddypress.. I just want to create a page like http://mainsite.com/profile/username
Is there a way to accomplish this?
Maybe you might check out Buddypress which is a social layer on top of Wordpress and is able to do what you need (i.e. something like http://mainsite.com/profile/username).
Link: http://buddypress.org/
More specifically, in Buddypress the default behaviour is http://mainsite.com/members/username
I have noticed that you have edited the question and that you are looking for a way to accomplish this without any plugin. There are a series of tags in Wordpress to show the author's data. So basically you could create a page and then use the_author_meta tags. For example the following code echoes the first and last name of a user whose name is stored in $userID:
<?php
$pagename = $userID;
echo the_author_meta(user_firstname, $userID );
echo the_author_meta(user_lastname, $userID );
?>
Please note that the variable $pagename is empty in case you use a static page as home page, but it is not your case.
Source: https://codex.wordpress.org/Template_Tags/the_author_meta

Hide other domains' menus from node edit form on a Drupal site using domain access

I'm in the process of making some improvements to a live Drupal site that's using the Domain Access module to run a number of microsites. I'm trying to find a way of restricting the menus a user can post content to from the node edit screen. A user on one of the domains should only be able to post content to menus associated with that domain.
Is there a simple way of achieving this? I'm guessing there are some hooks I could use, but so far I have been unable to identify them. I'd prefer not to have to install further modules to achieve this and to be able to add some code to the current site to alter the forms. The site is struggling with the large number of modules we've had to install on it already.
According to the readme for the module, you need to set some specific permissions in user management:
To enable this feature, you should grant the 'edit domain nodes' and
(optionally) the 'delete domain nodes' permission to some roles. Then assign
individual users accounts to specific domains to assign them as Domain Editors.
From my experience many moons ago with the module, you can check the global $user object and figure out what domains the user should have access to. You can then use a form alter to remove any options from the select box that you don't want them seeing. As always with Drupal though, it's better to let someone else write the code - so if the Domain module provides this functionality, use it!
Here is some updated code for Drupal 7:
/**
* Implements hook_form_FORM_ID_alter().
*/
function MYMODULE_form_page_node_form_alter(&$form, &$form_state) {
global $_domain;
if (isset($_domain['domain_id'])) { // only display domain's primary links
$menus[domain_conf_variable_get($_domain['domain_id'], 'menu_main_links_source')] = $_domain['sitename'].' Main menu';
}
if (isset($menus)) {
$options = menu_parent_options($menus, $form['#node']->type);
$form['menu']['link']['parent']['#options'] = $options;
}
}
Eventually found a way of fixing this for the particular project I have been working on: in module_form_alter I've added the following:-
global $_domain;
if (isset($_domain['domain_id'])) { // only display domain's primary links
$menus[domain_conf_variable_get($_domain['domain_id']
,'menu_primary_links_source')] = $_domain['sitename'].' Primary links';
}
if ( isset($menus) ) {
$options = menu_parent_options($menus, $form['menu']['#item']);
$form['menu']['parent']['#options'] = $options;
}
This restricts the menu options to just the current domain's primary links menu which is just what we wanted.
Thanks to Fabian who pointed me in the right direction earlier.

Resources