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.

WordPress Google Form v0.46-beta-15 now available

This afternoon I uploaded WordPress Google Form v0.46-beta-15 which addresses a CAPTCHA problem.  CAPTCHA requires Validation and unless Validation was specifically enabled for the form, the Validation code wasn’t loaded and hence CAPTCHA wasn’t running.

I also added some new default CSS to account for some of the CSS changes Google has made lately.  Google has actually made quite a few CSS changes so I need to make sure it is all covered.

This morning Google also made some changes to Check Boxes and Radio Buttons adding more text which is subject to the language problem.  The quick fix is to hide the new text using Custom CSS:

div.ss-printable-hint { display: none; }

Download the latest beta and please provide feedback on any issues you run into.

Google Forms Beta (31802 downloads )

WordPress Google Form v0.46-beta-14 available

This afternoon I uploaded WordPress Google Form v0.46-beta-14 which addresses a problem with certain parts of Google Forms (usually the buttons, required text, and disclaimer text) being displayed in a foreign language.  I wrote up some details on why this happens in a previous post.

GForm_SS_39

GForm_SS_38

GForm_SS_40

If you are having this issue, please download the beta and provide me some feedback.  I think I am going to move a few items from the Options tab to the Advanced Options tab before I release it.

Google Forms Beta (31802 downloads )

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 (31802 downloads )

Logging Google Form Submissions

For a while I have wanted to have a log of form submissions. My interest in this has mostly been to understand the source of spam submissions but there are other reasons too. With all of the changes Google Forms have undergone recently, this seemed like a good time to add this functionality as I chase down what Google changed to cause multi-page forms not to work.

The logging functionality I have implemented will only work with forms defined using the new Custom Post Type (CPT) as the log data is stored as Post Meta data attached to the CPT for the form.  In my current build I am working with all submissions are logged however there will be a setting to turn it on and off (default will be off) when I make a beta release available (hopefully today).

Access to the log is via a sub-menu selection from the Google Forms menu.

GForm_SS_33The log itself is implemented using the standard WordPress List Table class which provides a standard look and feel which WordPress users will recognize.

GForm_SS_34

Log entries can be deleted (in bulk or individually  but right now that is the only operation.  Is there some other operation that would make sense?  Export might make sense but I’ll defer on that for now.

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 (9932 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 (24384 downloads )

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

This morning I updated the beta version of Email Users 4.4.1 to beta-5.  This version updates a number of the links within the plugin which referred to the old plugin home page on MarvinLabs.com which are no longer in existance.

I hope this is the final beta release before 4.4.1 goes out.  All I am waiting for is some updates to language translation files.

Email Users Custom List (9932 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 (24384 downloads )

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

This evening I updated the beta version of Email Users 4.4.1 to beta-4.  This version addresses the issue with user settings reverting which was reported here, here, and here.  I have implemented the solution proposed by @maximinime on the WordPress Support Forums.

Email Users Custom List (9932 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 (24384 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 (9932 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 (24384 downloads )