Constantly Amazed by jQuery

I am constantly amazed by what one can do with jQuery.  If it were not for jQuery, I don’t think I would have continued working on WordPress Google Forms.  I’ve used jQuery to adapt check box parameters so they will pass from PHP (used by WordPress) to Python (used by Google for form process).  I’ve used jQuery to implement CAPTCHA.  I’ve used jQuery to implement multiple columns.  And now I am using jQuery to work-around the language issues which have recently become a problem.

Recently Google changed the structure of Google Forms.  The new version no longer supports the hl=XX (where XX is a language parameter such as en or fr) parameter.  For most instances this isn’t a problem.

However, there are some cases where Google thinks the server hosting WordPress (and hence WordPress Google Forms) is located in a certain part of the globe and therefore should receive Google Forms with some of the boiler plate text in the native language suitable for the location.  Awesome.  Google thinks I need German buttons and text.  I don’t speak German nor do any of my users however the server is physically located in Germany. Now what?

Over the past couple of days I been implementing jQuery that finds the default text which Google is serving in  a native language and allowing WordPress Google Forms to override it.  I am doing this with jQuery.  Fortunately Google adds numerous CSS classes to their forms so most of the replacements can be accomplished in a single line of jQuery.  However, there is one situation where it isn’t so simple.

If you employ a multiple choice question, Google provides an option to add an “Other” choice where the user can type in another answer.  Again, very nice of them.  However the “Other” text is one of those that Google serves up in a localized language and more importantly, it isn’t wrapped in a SPAN or a DIV with a CSS class that makes it easy to select.

Here is one of the questions on one of my development forms.  You can see I’ve already overridden the “hint” (which is also new):

GForm_SS_42

Here is the same question with the “Other” text overridden:

GForm_SS_43

So how do we select just the “Other” text but only when using a multiple select widget which employs an Other choice? jQuery and Javascript to the rescue:

$("div.ss-radio label:last+span.ss-q-other-container").prev().contents().filter(function() {
        return this.nodeType == Node.TEXT_NODE;
    })[0].nodeValue = "<<<<Other:";

This snippet of jQuery (which I got some help on from this thread on StackOverflow) combined with Javascript selects the one case there is and replaces it with my override.  Pretty slick eh?

Look for another beta update today with more override options.

Why are my buttons in Chinese?

Periodically I get a question from someone using WordPress Google Form asking why their buttons (and some other text) is in Chinese (or some other language but Chinese is the most common)?

If you haven’t run into this problem, consider yourself lucky!  The problem manifests itself similar to the images below.

GForm_SS_35 GForm_SS_36

As near as I can tell, this problem happens when the Web server that is running WordPress Google Form is geographically located in a part of the world where Google thinks it should serve up a particular language.

So how do you fix it?  In the previous version of Google Forms, the solution was simple:  Add &hl=en to your form URL and Google would deliver the content in the specificed language (in the case English) – refer to to this post for more details.  Unfortunately the new version of Google Forms doesn’t support this language parameter so I have been at a loss to help people who find themselves in this situation.

For several days I have been trying to find a solution.  Adding cookies to the wp_remote_get() request, .htaccess entries, PHP locale settings, etc.  Nothing made a difference.

While at the gym this morning it dawned on me that there isn’t any reason why I couldn’t “fix” the problem by processing the HTML that Google generates with jQuery.  So that is what I have done.

GForm_SS_37

 

I have renamed the Debug tab to Advanced Options and added the ability to define the text that will appear on the Submit, Back, and Continue buttons as well as the text which indicates fields are Required.

WordPress Google Form v0.46-beta-13 available

This afternoon I uploaded WordPress Google Form v0.46-beta-13.  Yes, this is the 13th beta release of WordPress Google Form v0.46.  Why so many?  Mostly because made a significant change to Google Forms at about the same time I was introducing a major change to WordPress Google Forms.

This release adds a new feature – the ability to log form submissions.  This is something I’ve wanted to do for a while.  The next update will include some settings to control the log (on, off, entries per page, etc.)  but in this beta release, it is on and shows 10 entries per page.  There is a known bug in the pagination of the log file.  The URL to move between pages is wrong and I haven’t been able to determine how to add the CPT and page information which the URL requires to be valid.

Most importantly, this beta release addresses a major bug with multi-page Google Forms AND Google Forms with checkboxes that are created with the new version of Google Forms.  This functionality needs testing so please put it through its paces.

Google Forms Beta (7976 downloads )

Emai-Users v4.4.3-beta 1 now available

I have posted a beta release of Email-Users v4.4.3 for testing purposes. This build addresses a problem with using the new Meta Filter functionality with a set of users and also fixes a situation which can result in duplicate emails when Notifications (Page or Post) are sent by selecting both Roles and Users.

Email Users Beta (5001 downloads )

Email-Users v4.4.1-beta-6 now available

This morning I updated the beta version of Email Users 4.4.1 to beta-6.  This version incorporates updated Spanish and German language files and fixes a few remaining links within the plugin which referred to the old plugin home page on <a href=”http://www.marvinlabs.com”>MarvinLabs.com</a>.

I had hoped beta-5 would be the final beta release however I am still waiting for updated French language files before 4.4.1 is released.  Updates to other languages are welcome too however I no longer have the contact information for the Russian and Persian support files.

Email Users Custom List (5586 downloads )

Please download and test the beta release.  Report back any issues and I’ll do what I can to fix them quickly.

Email Users Beta (5001 downloads )

Email-Users 4.4.1-beta-3 available

This afternoon I updated the beta version of Email Users 4.4.1 to beta-3.  This version improves the Custom Group filter options by introducing a new Custom Group Meta Key filter.  It builds on the Custom Group Meta Filter but eliminates a lot of the work required if a filter on a Meta Key is desired instead of a Meta Key and Value pair.

For example the following code will yield a Send to Group Form with selections based on any possible value of a User Meta Key by the name of ‘department’:

add_action( 'mailusers_group_custom_meta_key_filter', 'send_to_departments', 5 );
function send_to_departments()
{
mailusers_register_group_custom_meta_key_filter('department', null, 'send_to_departments_label');
}
function send_to_departments_label($mk, $mv)
{
return(ucwords($mk) . ' = ' . ucwords($mv)) ;
}

The only required argument is the first one, which is the name of the Meta Key.  The second argument is an optional Meta Value and the third argument is an optional callback which accepts two strings, Meta Key and Meta Value, and returns a string which is used as the selection text on the form.

EU_SS_07

I have updated the example plugin again to create the filter which results in the image above, the examples I have done previously are still in the file however are commented out.  You can download it and drop it into  your plugins directory to see menus like shown in the beta-1 post.

Email Users Custom List (5586 downloads )

Please download and test the beta release.  Report back any issues and I’ll do what I can to fix them quickly.

Email Users Beta (5001 downloads )

WordPress Google Form v0.46 beta 9 available

I’ve updated the beta version of WordPress Google Form v0.46 this morning to beta-9. This beta update adds a significant new feature and one that has been requested a number of times: The ability to require an email address from the person filling out the form is now possible through a setting on the Google Form custom post type (this is not available through the old gform short code).

I would encourage migrating to the new short code and defining forms with the Google Forms Custom Post Type UI as that is where I am adding new functionality.  The way I added the User Email option should also allow me to allow form specific validation rules (e.g. URL required).

Download the beta release and please let me know if you run into any issues.

Google Forms Beta (7976 downloads )

WordPress Google Form v0.46 beta 6 available

I’ve updated the beta version of WordPress Google Form v0.46 to beta-6 and made it available for download from this site. This beta update addresses some typos which caused problems when running with debug enabled and temporarily increases the HTTP_API timeout to 15 seconds to chase down a suspected problem with very large Google Spreadsheets. If increasing the timeout works then I will add another setting to the plugin to allow this to be changed on a per site basis.

Download the beta release and please let me know if you run into any issues.

Google Forms Beta (7976 downloads )

WordPress Google Form v0.46 beta 5 available

I’ve updated the beta version of WordPress Google Form v0.46 to beta-5 and made it available for download from this site. This beta update addresses an issue where content is floating to the wrong location. The addition of column support using jQuery Columnizer plugin injects several DIVs to wrap the column content and the DIVs which contain the columns are floated either left (default) or right. I have added some additional jQuery code to clear the floats at the end of the Google Form.

Download the beta release and please let me know if you run into any issues.

Google Forms Beta (7976 downloads )

WordPress Google Form v.046-beta-3 available

This morning I made WordPress Google Form v0.46-beta-3 available for download from this site. I have not posted this version to the WordPress plugin repository as it still needs some testing.  This beta release includes new checking to try and detect when the form data wasn’t actually posted to Google and if detected, will suppress the confirmation page (if used) so the Google error will not be missed by the user.

Download the beta release and please let me know if you run into any issues.

Google Forms Beta (7976 downloads )