Google Forms - Version 0.41

Version Description

No known upgrade issues.

Download this release

Release Info

Developer mpwalsh8
Plugin Icon wp plugin Google Forms
Version 0.41
Comparing to
See all releases

Code changes from version 0.40 to 0.41

Files changed (5) hide show
  1. index.php +2 -2
  2. readme.txt +19 -2
  3. wpgform-core.php +203 -77
  4. wpgform-debug.php +38 -0
  5. wpgform-options.php +99 -1
index.php CHANGED
@@ -4,8 +4,8 @@
4
  * Plugin Name: WordPress Google Form
5
  * Plugin URI: http://michaelwalsh.org/wordpress/wordpress-plugins/wpgform/
6
  * Description: Add Google Forms to a WordPress web site. Display a Google Form directly into your posts, pages or sidebar. Style the Google Form to match your existing theme and display a custom confirmation page after form submission.
7
- * Version: 0.40
8
- * Build: 0.40.$WCREV$
9
  * Last Modified: $WCDATE$
10
  * Author: Mike Walsh
11
  * Author URI: http://www.michaelwalsh.org
4
  * Plugin Name: WordPress Google Form
5
  * Plugin URI: http://michaelwalsh.org/wordpress/wordpress-plugins/wpgform/
6
  * Description: Add Google Forms to a WordPress web site. Display a Google Form directly into your posts, pages or sidebar. Style the Google Form to match your existing theme and display a custom confirmation page after form submission.
7
+ * Version: 0.41
8
+ * Build: 0.41.$WCREV$
9
  * Last Modified: $WCDATE$
10
  * Author: Mike Walsh
11
  * Author URI: http://www.michaelwalsh.org
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: Google Forms, Google Docs, Google, Spreadsheet, shortcode, forms
5
  Requires at least: 3.0
6
  Tested up to: 3.4.2
7
- Stable tag: 0.40
8
 
9
  Embeds a published, public Google Form in a WordPress post, page, or widget.
10
 
@@ -50,8 +50,10 @@ The WordPress Google Form shortcode `gform` supports a number of attributes that
50
  * __sendto__: Notify the "sendto" email address that a form has been submitted by setting the __email__ attribute to __on__. This will result in an email being sent to the "sendto" letting them know a form was submitted with the URL of the form along with the date and time of submission. The email message will always be sent to the blog administrator via Bcc.
51
  * __spreadsheet__: The full URL to the "Shared" Google Docs Spreadsheet which stores the form responses. You must be able to open this URL successfully from a browser for the link in the email to work properly. This attribute is used in conjunction with the __email__ attribute, it has no effect when the __email__ attribute is not turned __on__.
52
  * __unitethemehack__: Off by default, this attribute should be enabled, `unitethemehack='on'`, when using the [Unite theme from Paralleus](http://themeforest.net/item/unite-wordpress-business-magazine-theme/90959). The Unite theme manipulates the submit button(s) on a page, the result of which is a button that prevents the Google form from being submitted. Turning this attribute on enables a hack which inserts *class="noStyle"* to all submit buttons, preventing Unite from mucking with them.
 
 
53
 
54
- `[gform form='https://docs.google.com/spreadsheet/viewform?hl=en_US&pli=1&formkey=ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678#gid=0' confirm='http://www.example.com/thankyou/' style='ajax' class='mygform' legal='off' prefix='mygform-' br='on' title='on' maph1h2='on' email='on' spreadsheet='https://docs.google.com/spreadsheet/ccc?key=0AgBHWDGsX0PUdE56R1ZldXo4a0N3VTNMNEpSemdGV3c' unitethemehack='off']`
55
 
56
  == Frequently Asked Questions ==
57
 
@@ -101,6 +103,12 @@ label.ss-q-title:after {
101
  = I don't like the redirection behavior of the custom confirmation, can you change it back to the way it worked in v0.10? =
102
  Unfortunately not. I understand that the older behavior is preferable as it looks cleaner for the end user however there is no way to support multi-page Google Forms using the old model. The requirement to support multi-page Google Forms is a higher priority than the older confirmation model based on the overwhelming feedback received to support multi-page forms. In v0.26 a new confirmation behavior was introduced which uses AJAX to update the page with the content from the custom confirmation page. In v0.27 the redirection mechanism has returned to be the default behavior but if the AJAX methodology is preferred, it is available by setting the `style='ajax'` attribute within the shortcode.
103
 
 
 
 
 
 
 
104
  == CSS ==
105
 
106
  As of 2011-09-21, Google Forms make use of 20+ CSS class definitions. By default, the WordPress Google Form plugin includes CSS declarations for all of the classes however the bulk of them are empty. The default CSS sets the font and makes the entry boxes wider. The default CSS that ships with WordPress Google Form can optionally be turned off via the WordPress Google Form settings.
@@ -195,6 +203,15 @@ tr.ss-gridrow {}
195
  No known upgrade issues.
196
 
197
  == Changelog ==
 
 
 
 
 
 
 
 
 
198
 
199
  = Version 0.40 =
200
  * Removed leftover debug code. Again. :-(
4
  Tags: Google Forms, Google Docs, Google, Spreadsheet, shortcode, forms
5
  Requires at least: 3.0
6
  Tested up to: 3.4.2
7
+ Stable tag: 0.41
8
 
9
  Embeds a published, public Google Form in a WordPress post, page, or widget.
10
 
50
  * __sendto__: Notify the "sendto" email address that a form has been submitted by setting the __email__ attribute to __on__. This will result in an email being sent to the "sendto" letting them know a form was submitted with the URL of the form along with the date and time of submission. The email message will always be sent to the blog administrator via Bcc.
51
  * __spreadsheet__: The full URL to the "Shared" Google Docs Spreadsheet which stores the form responses. You must be able to open this URL successfully from a browser for the link in the email to work properly. This attribute is used in conjunction with the __email__ attribute, it has no effect when the __email__ attribute is not turned __on__.
52
  * __unitethemehack__: Off by default, this attribute should be enabled, `unitethemehack='on'`, when using the [Unite theme from Paralleus](http://themeforest.net/item/unite-wordpress-business-magazine-theme/90959). The Unite theme manipulates the submit button(s) on a page, the result of which is a button that prevents the Google form from being submitted. Turning this attribute on enables a hack which inserts *class="noStyle"* to all submit buttons, preventing Unite from mucking with them.
53
+ * __validation__: Off by default, this attribute can be enabled, `validation='on'`, to add jQuery based form validation support using the [jQuery Validate Plugin](http://bassistance.de/jquery-plugins/jquery-plugin-validation/). Enabling this optional attribute will allow inline checking without form submission to Google (which also does checking for required fields). Error messages can be styled using the *gform-error* CSS class.
54
+ * __captcha__: Off by default, this attribute can be enabled, `captcha='on'`, to add a simple math based [CAPTCHA](http://en.wikipedia.org/wiki/CAPTCHA) to the Google Form. The CAPTCHA only appears for the final submit on multi-page forms. The CAPTCHA error message can be styled using the *gform-error* CSS class.
55
 
56
+ `[gform form='https://docs.google.com/spreadsheet/viewform?hl=en_US&pli=1&formkey=ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678#gid=0' confirm='http://www.example.com/thankyou/' style='ajax' class='mygform' legal='off' prefix='mygform-' br='on' title='on' maph1h2='on' email='on' spreadsheet='https://docs.google.com/spreadsheet/ccc?key=0AgBHWDGsX0PUdE56R1ZldXo4a0N3VTNMNEpSemdGV3c' unitethemehack='off' validation='on' captcha='on']`
57
 
58
  == Frequently Asked Questions ==
59
 
103
  = I don't like the redirection behavior of the custom confirmation, can you change it back to the way it worked in v0.10? =
104
  Unfortunately not. I understand that the older behavior is preferable as it looks cleaner for the end user however there is no way to support multi-page Google Forms using the old model. The requirement to support multi-page Google Forms is a higher priority than the older confirmation model based on the overwhelming feedback received to support multi-page forms. In v0.26 a new confirmation behavior was introduced which uses AJAX to update the page with the content from the custom confirmation page. In v0.27 the redirection mechanism has returned to be the default behavior but if the AJAX methodology is preferred, it is available by setting the `style='ajax'` attribute within the shortcode.
105
 
106
+ = Can I change the range of values the CAPCTHA is based on?
107
+ Not at this time.
108
+
109
+ = Can I changer the math operator the CAPTCHA is based on?
110
+ Not at this time.
111
+
112
  == CSS ==
113
 
114
  As of 2011-09-21, Google Forms make use of 20+ CSS class definitions. By default, the WordPress Google Form plugin includes CSS declarations for all of the classes however the bulk of them are empty. The default CSS sets the font and makes the entry boxes wider. The default CSS that ships with WordPress Google Form can optionally be turned off via the WordPress Google Form settings.
203
  No known upgrade issues.
204
 
205
  == Changelog ==
206
+
207
+ = Version 0.41 =
208
+ * Added simple math based CAPTCHA support.
209
+ * Reintroduced jQuery Validation for checking required fields.
210
+ * Improved support for multiple forms on one page.
211
+ * Fixed several bugs where CSS prefix, when used, was not output in some places.
212
+ * Moved Debug control to their own tab on the settings page.
213
+ * Added new Debug options to facilicate chasing down HTTP API issues.
214
+ * Fixed bug where the CSS prefix, when used, was not being applied properly to elements which had more than one class. Only the first class was properly prefixed.
215
 
216
  = Version 0.40 =
217
  * Removed leftover debug code. Again. :-(
wpgform-core.php CHANGED
@@ -79,6 +79,13 @@ function wpgform_get_default_plugin_options()
79
  ,'enable_debug' => 0
80
  ,'serialize_post_vars' => 0
81
  ,'bcc_blog_admin' => 1
 
 
 
 
 
 
 
82
  ) ;
83
 
84
  return apply_filters('wpgform_default_plugin_options', $default_plugin_options) ;
@@ -111,7 +118,7 @@ function wpgform_get_plugin_options()
111
  foreach ($default_options as $key => $value)
112
  {
113
  if (!array_key_exists($key, $plugin_options))
114
- $plugin_options[$key] = null ;
115
  }
116
 
117
  return $plugin_options ;
@@ -188,6 +195,36 @@ class wpGForm
188
  */
189
  static $posted = false ;
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  /**
192
  * Constructor
193
  */
@@ -291,6 +328,31 @@ class wpGForm
291
  // Breaks between labels and inputs?
292
  $br = $options['br'] === 'on' ;
293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  // Output the H1 title included in the Google Form?
295
  $title = $options['title'] === 'on' ;
296
 
@@ -347,7 +409,22 @@ class wpGForm
347
  // Retrieve the HTML from the URL
348
 
349
  if (is_wp_error(self::$response))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  return '<div class="gform-google-error">Unable to retrieve Google Form. Please try reloading this page.</div>' ;
 
351
  else
352
  $html = self::$response['body'] ;
353
 
@@ -436,11 +513,6 @@ class wpGForm
436
  $html = preg_replace('/h1>/i', 'h2>', $html) ;
437
  }
438
 
439
- // Augment class names with some sort of a prefix?
440
-
441
- if (!is_null($prefix))
442
- $html = preg_replace('/ class="/i', " class=\"{$prefix}", $html) ;
443
-
444
  // Augment labels with some sort of a suffix?
445
 
446
  if (!is_null($suffix))
@@ -474,13 +546,16 @@ class wpGForm
474
  $html = str_replace($action, 'action=""', $html) ;
475
  $action = preg_replace(array('/^action=/i', '/"/'), array('', ''), $action) ;
476
  $action = base64_encode(serialize($action)) ;
 
477
 
 
478
  $html = preg_replace('/<\/form>/i',
479
- "<input type=\"hidden\" value=\"{$action}\" name=\"gform-action\"></form>", $html) ;
480
  }
481
  else
482
  {
483
  $action = null ;
 
484
  }
485
 
486
  // The Unite theme from Paralleus mucks with the submit buttons
@@ -519,9 +594,64 @@ class wpGForm
519
  // Need to fix the name arguments for checkboxes so PHP will pass them as an array correctly.
520
  // This jQuery script reformats the checkboxes so that Googles Python script will read them.
521
 
522
- $js = sprintf('
523
  <script type="text/javascript">
524
  jQuery(document).ready(function($) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
  $("div.%sss-form-container input:checkbox").each(function(index) {
526
  this.name = this.name + \'[]\';
527
  });
@@ -531,51 +661,31 @@ jQuery(document).ready(function($) {
531
  $("div.%sss-form-container :input").attr("disabled", true);
532
  ', $prefix) ;
533
 
534
- /*
535
- // Serialize the POST variables?
536
- if ($wpgform_options['serialize_post_vars'] == 1)
537
- {
538
- $js .= sprintf('
539
- $("#%sss-form").submit(function(event) {
540
- //$("#%sss-form").children().each(function(){
541
- $.each($("#%sss-form input, #%sss-form textarea"), function() {
542
- //access to form element via $(this)
543
- $(this).val($.base64Encode($(this).val()));
544
- alert($(this).val());
545
- });
546
- });
547
- //var i = 0;
548
- //$.each($("#%sss-form input:text, #%sss-form input:hidden #%sss-form textarea"), function(i,v) {
549
- //$.each($("#%sss-form input, #%sss-form textarea"), function(i,v) {
550
- //var theTag = v.tagName;
551
- //var theElement = $(v);
552
- //var theValue = theElement.val();
553
- //alert(i + ": " + theValue) ;
554
- //$(v).val($.base64Encode($(v).val()));
555
- //alert($.base64Encode(theValue)) ;
556
- //i++;
557
- //});
558
-
559
-
560
- //alert("waiting ...");
561
- //});', $prefix, $prefix, $prefix, $prefix, $prefix, $prefix, $prefix, $prefix, $prefix) ;
562
- }
563
- */
564
-
565
  // Before closing the <script> tag, is this the confirmation
566
  // AND do we have a custom confirmation page or alert message?
567
 
568
- if (self::$posted && is_null($action) && !is_null($alert))
 
 
569
  $js .= PHP_EOL . 'alert("' . $alert . '") ;' ;
 
570
 
571
  // Load the confirmation URL via AJAX?
572
- if (self::$posted && is_null($action) && !is_null($confirm) && $style === WPGFORM_CONFIRM_AJAX)
 
 
 
573
  $js .= PHP_EOL . '$("body").load("' . $confirm . '") ;' ;
 
574
 
575
  // Load the confirmation URL via Redirect?
576
- if (self::$posted && is_null($action) && !is_null($confirm) && $style === WPGFORM_CONFIRM_REDIRECT)
 
 
 
577
  //printf('<h2>%s::%s</h2>', basename(__FILE__), __LINE__) ;
578
  $js .= PHP_EOL . 'window.location.replace("' . $confirm . '") ;' ;
 
579
 
580
  $js .= '
581
  });
@@ -618,7 +728,43 @@ jQuery(document).ready(function($) {
618
  else
619
  $debug = '' ;
620
 
621
- return $debug . $js . $css . $html ;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622
  }
623
 
624
  /**
@@ -642,34 +788,14 @@ jQuery(document).ready(function($) {
642
 
643
  $wpgform_options = wpgform_get_plugin_options() ;
644
 
645
- //print_r($_POST) ;
646
- // Are POST variables base64 encoded?
647
- /*
648
- if ($wpgform_options['serialize_post_vars'] == 1)
649
- {
650
- foreach ($_POST as $key => $value)
651
- {
652
- // Need to handle parameters passed as array values
653
- // separately because of how Python (used Google)
654
- // handles array arguments differently than PHP does.
655
-
656
- //if (is_array($_POST[$key]))
657
- //{
658
- //$pa = &$_POST[$key] ;
659
- //foreach ($pa as $pv)
660
- //$body .= preg_replace($patterns, $replacements, $key) . '=' . rawurlencode($pv) . '&' ;
661
- //}
662
- //else
663
- //{
664
- $_POST[$key] = base64_decode($value) ;
665
- //}
666
- }
667
- }
668
- //print_r($_POST) ;
669
- */
670
  if (WPGFORM_DEBUG) wpgform_whereami(__FILE__, __LINE__, 'ProcessGForm') ;
671
  if (WPGFORM_DEBUG) wpgform_preprint_r($_POST) ;
672
 
 
 
 
 
 
673
  $action = unserialize(base64_decode($_POST['gform-action'])) ;
674
  unset($_POST['gform-action']) ;
675
  $options = $_POST['gform-options'] ;
@@ -784,6 +910,8 @@ jQuery(document).ready(function($) {
784
  'email' => 'off', // Send an email confirmation to blog admin on submission
785
  'sendto' => null, // Send an email confirmation to a specific address on submission
786
  'spreadsheet' => false, // Google Spreadsheet URL
 
 
787
  'unitethemehack' => 'off', // Send an email confirmation to blog admin on submission
788
  'style' => WPGFORM_CONFIRM_REDIRECT // How to present the custom confirmation after submit
789
  ), $atts) ;
@@ -903,20 +1031,18 @@ function wpgform_head()
903
 
904
  $wpgform_options = wpgform_get_plugin_options() ;
905
 
906
- /*
907
- // Load Base64 Encode/Decode jQuery plugin?
908
- if ($wpgform_options['serialize_post_vars'] == 1)
909
- {
910
- wp_enqueue_script('gform-jquery-base64',
911
- plugins_url(plugin_basename(dirname(__FILE__) . '/js/jquery.base64.js')), array('jquery'));
912
- }
913
- */
914
-
915
  // Load default gForm CSS?
916
  if ($wpgform_options['default_css'] == 1)
917
  {
918
  wp_enqueue_style('gform',
919
  plugins_url(plugin_basename(dirname(__FILE__) . '/gforms.css'))) ;
920
  }
 
 
 
 
 
 
 
921
  }
922
  ?>
79
  ,'enable_debug' => 0
80
  ,'serialize_post_vars' => 0
81
  ,'bcc_blog_admin' => 1
82
+ ,'fsockopen_transport' => 0
83
+ ,'streams_transport' => 0
84
+ ,'curl_transport' => 0
85
+ ,'local_ssl_verify' => 0
86
+ ,'ssl_verify' => 0
87
+ ,'http_request_timeout' => 0
88
+ ,'http_request_timeout_value' => 30
89
  ) ;
90
 
91
  return apply_filters('wpgform_default_plugin_options', $default_plugin_options) ;
118
  foreach ($default_options as $key => $value)
119
  {
120
  if (!array_key_exists($key, $plugin_options))
121
+ $plugin_options[$key] = $default_options[$key] ;
122
  }
123
 
124
  return $plugin_options ;
195
  */
196
  static $posted = false ;
197
 
198
+ /**
199
+ * Property to indicate Javascript output state
200
+ */
201
+ static $wpgform_js = false ;
202
+
203
+ /**
204
+ * Property to indicate CSS output state
205
+ */
206
+ static $wpgform_css = false ;
207
+
208
+ /**
209
+ * Property to indicate Debug output state
210
+ */
211
+ static $wpgform_debug = false ;
212
+
213
+ /**
214
+ * Property to store unique form id
215
+ */
216
+ static $wpgform_form_id = 1 ;
217
+
218
+ /**
219
+ * Property to store unique form id
220
+ */
221
+ static $wpgform_submitted_form_id = null ;
222
+
223
+ /**
224
+ * Property to store captcha values
225
+ */
226
+ static $wpgform_captcha = null ;
227
+
228
  /**
229
  * Constructor
230
  */
328
  // Breaks between labels and inputs?
329
  $br = $options['br'] === 'on' ;
330
 
331
+ // Use jQuery validation?
332
+ $validation = $options['validation'] === 'on' ;
333
+
334
+ // Display CAPTCHA?
335
+ $captcha = $options['captcha'] === 'on' ;
336
+ $captcha_html = '' ;
337
+
338
+ if ($captcha)
339
+ {
340
+ $a = rand(0, 19) ;
341
+ $b = rand(5, 24) ;
342
+ $c = $a + $b ;
343
+
344
+ self::$wpgform_captcha = array('a' => $a, 'b' => $b, 'c' => $c) ;
345
+
346
+ $captcha_html .= '<div style="margin-top: 5px; display: none;" class="gform-captcha">' ;
347
+ $captcha_html .= sprintf('<div class="%sss-item %sss-item-required %sss-text">', $prefix, $prefix, $prefix) ;
348
+ $captcha_html .= sprintf('<div class="%sss-form-entry">', $prefix) ;
349
+ $captcha_html .= sprintf('<label for="gform-captcha" class="%sss-q-title">What is %s + %s ?', $prefix, $a, $b) ;
350
+ $captcha_html .= sprintf('<span class="%sss-required-asterisk">*</span></label>', $prefix) ;
351
+ $captcha_html .= sprintf('<label for="gform-captcha" class="%sss-q-help"></label>', $prefix) ;
352
+ $captcha_html .= sprintf('<input style="width: 100px;" type="text" id="gform-captcha" class="%sss-q-short" value="" name="gform-captcha">', $prefix) ;
353
+ $captcha_html .= '</div></div></div>' ;
354
+ }
355
+
356
  // Output the H1 title included in the Google Form?
357
  $title = $options['title'] === 'on' ;
358
 
409
  // Retrieve the HTML from the URL
410
 
411
  if (is_wp_error(self::$response))
412
+ {
413
+ printf('<h2>%s::%s</h2>', basename(__FILE__), __LINE__) ;
414
+ print '<pre>' ;
415
+ print_r(self::$response) ;
416
+ print '</pre>' ;
417
+ $error_string = self::$response->get_error_message();
418
+ echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
419
+ if (WPGFORM_DEBUG)
420
+ {
421
+ //wpgform_whereami(__FILE__, __LINE__, 'ConstructGForm') ;
422
+ //wpgform_preprint_r(self::$respone) ;
423
+
424
+ }
425
+
426
  return '<div class="gform-google-error">Unable to retrieve Google Form. Please try reloading this page.</div>' ;
427
+ }
428
  else
429
  $html = self::$response['body'] ;
430
 
513
  $html = preg_replace('/h1>/i', 'h2>', $html) ;
514
  }
515
 
 
 
 
 
 
516
  // Augment labels with some sort of a suffix?
517
 
518
  if (!is_null($suffix))
546
  $html = str_replace($action, 'action=""', $html) ;
547
  $action = preg_replace(array('/^action=/i', '/"/'), array('', ''), $action) ;
548
  $action = base64_encode(serialize($action)) ;
549
+ $wgformid = self::$wpgform_form_id++ ;
550
 
551
+ // Add some hidden input fields to faciliate control of subsquent actions
552
  $html = preg_replace('/<\/form>/i',
553
+ "<input type=\"hidden\" value=\"{$action}\" name=\"gform-action\"><input type=\"hidden\" value=\"{$wgformid}\" name=\"gform-form-id\"></form>", $html) ;
554
  }
555
  else
556
  {
557
  $action = null ;
558
+ $wgformid = self::$wpgform_form_id++ ;
559
  }
560
 
561
  // The Unite theme from Paralleus mucks with the submit buttons
594
  // Need to fix the name arguments for checkboxes so PHP will pass them as an array correctly.
595
  // This jQuery script reformats the checkboxes so that Googles Python script will read them.
596
 
597
+ $js = '
598
  <script type="text/javascript">
599
  jQuery(document).ready(function($) {
600
+ ' ;
601
+
602
+ // Did short code specify a CSS prefix?
603
+ if (!is_null($prefix)) $js .= sprintf('
604
+ $("#ss-form [class]").each(function(i, el) {
605
+ var c = $(this).attr("class").split(" ");
606
+ for (var i = 0; i < c.length; ++i) {
607
+ $(this).removeClass(c[i]).addClass("%s" + c[i]);
608
+ }
609
+ });
610
+ ', $prefix) ;
611
+
612
+ // Is CAPTCHA enabled?
613
+ if ($captcha) $js .= sprintf('
614
+ $.validator.methods.equal = function(value, element, param) {
615
+ return value == param;
616
+ };
617
+ $("#ss-form").append(\'%s\');
618
+ if ($("#ss-form input[type=submit][name=submit]").length) {
619
+ $("div.gform-captcha").show();
620
+ $.validator.addClassRules("gform-captcha", {
621
+ required: true
622
+ });
623
+ $("#ss-form").validate({
624
+ errorClass: "gform-error",
625
+ rules: {
626
+ "gform-captcha": {
627
+ equal: %s
628
+ }
629
+ },
630
+ messages: {
631
+ "gform-captcha": "Incorrect answer."
632
+ }
633
+ });
634
+ }
635
+ ', $captcha_html, self::$wpgform_captcha['c']) ;
636
+
637
+ // Include jQuery validation?
638
+ if ($validation) $js .= sprintf('
639
+ $("div > .ss-item-required textarea").addClass("gform-required");
640
+ $("div > .ss-item-required input:not(.ss-q-other").addClass("gform-required");
641
+ $("div > .%sss-item-required textarea").addClass("gform-required");
642
+ $("div > .%sss-item-required input:not(.%sss-q-other").addClass("gform-required");
643
+
644
+ $.validator.addClassRules("gform-required", {
645
+ required: true
646
+ });
647
+
648
+ $("#ss-form").validate({
649
+ errorClass: "gform-error"
650
+ }) ;
651
+ ', $prefix, $prefix, $prefix) ;
652
+
653
+ // Always include the jQuery to clean up the checkboxes
654
+ $js .= sprintf('
655
  $("div.%sss-form-container input:checkbox").each(function(index) {
656
  this.name = this.name + \'[]\';
657
  });
661
  $("div.%sss-form-container :input").attr("disabled", true);
662
  ', $prefix) ;
663
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
664
  // Before closing the <script> tag, is this the confirmation
665
  // AND do we have a custom confirmation page or alert message?
666
 
667
+ if (self::$posted && is_null($action) && !is_null($alert) &&
668
+ (self::$wpgform_submitted_form_id == self::$wpgform_form_id - 1))
669
+ {
670
  $js .= PHP_EOL . 'alert("' . $alert . '") ;' ;
671
+ }
672
 
673
  // Load the confirmation URL via AJAX?
674
+ if (self::$posted && is_null($action) && !is_null($confirm) &&
675
+ (self::$wpgform_submitted_form_id == self::$wpgform_form_id - 1) &&
676
+ $style === WPGFORM_CONFIRM_AJAX)
677
+ {
678
  $js .= PHP_EOL . '$("body").load("' . $confirm . '") ;' ;
679
+ }
680
 
681
  // Load the confirmation URL via Redirect?
682
+ if (self::$posted && is_null($action) && !is_null($confirm) &&
683
+ (self::$wpgform_submitted_form_id == self::$wpgform_form_id - 1) &&
684
+ $style === WPGFORM_CONFIRM_REDIRECT)
685
+ {
686
  //printf('<h2>%s::%s</h2>', basename(__FILE__), __LINE__) ;
687
  $js .= PHP_EOL . 'window.location.replace("' . $confirm . '") ;' ;
688
+ }
689
 
690
  $js .= '
691
  });
728
  else
729
  $debug = '' ;
730
 
731
+ // Assemble final HTML to return. To handle pages with more than one
732
+ // form, Javascript, CSS, and debug control should only be rendered once!
733
+
734
+ $onetime_html = '' ;
735
+
736
+ if (WPGFORM_DEBUG)
737
+ {
738
+ printf('<h2>Form Id: %s</h2>', self::$wpgform_form_id - 1) ;
739
+ if (!is_null(self::$wpgform_submitted_form_id))
740
+ printf('<h2>Submitted Form Id: %s</h2>', self::$wpgform_submitted_form_id) ;
741
+ else
742
+ printf('<h2>No Submitted Form Id:</h2>') ;
743
+ }
744
+
745
+ if (!self::$wpgform_js)
746
+ {
747
+ if (is_null(self::$wpgform_submitted_form_id) ||
748
+ self::$wpgform_submitted_form_id == self::$wpgform_form_id - 1)
749
+ {
750
+ $onetime_html .= $js ;
751
+ self::$wpgform_js = true ;
752
+ }
753
+ }
754
+
755
+ if (!self::$wpgform_css)
756
+ {
757
+ $onetime_html .= $css ;
758
+ self::$wpgform_css = true ;
759
+ }
760
+
761
+ if (!self::$wpgform_debug)
762
+ {
763
+ $onetime_html .= $debug ;
764
+ self::$wpgform_debug = true ;
765
+ }
766
+
767
+ return $onetime_html . $html ;
768
  }
769
 
770
  /**
788
 
789
  $wpgform_options = wpgform_get_plugin_options() ;
790
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
791
  if (WPGFORM_DEBUG) wpgform_whereami(__FILE__, __LINE__, 'ProcessGForm') ;
792
  if (WPGFORM_DEBUG) wpgform_preprint_r($_POST) ;
793
 
794
+ // Need the form ID to handle multiple forms per page
795
+ self::$wpgform_submitted_form_id = $_POST['gform-form-id'] ;
796
+ unset($_POST['gform-form-id']) ;
797
+
798
+ // Need the action which was saved during form construction
799
  $action = unserialize(base64_decode($_POST['gform-action'])) ;
800
  unset($_POST['gform-action']) ;
801
  $options = $_POST['gform-options'] ;
910
  'email' => 'off', // Send an email confirmation to blog admin on submission
911
  'sendto' => null, // Send an email confirmation to a specific address on submission
912
  'spreadsheet' => false, // Google Spreadsheet URL
913
+ 'captcha' => 'off', // Display a CAPTCHA when enabled
914
+ 'validation' => 'off', // Use jQuery validation for required fields
915
  'unitethemehack' => 'off', // Send an email confirmation to blog admin on submission
916
  'style' => WPGFORM_CONFIRM_REDIRECT // How to present the custom confirmation after submit
917
  ), $atts) ;
1031
 
1032
  $wpgform_options = wpgform_get_plugin_options() ;
1033
 
 
 
 
 
 
 
 
 
 
1034
  // Load default gForm CSS?
1035
  if ($wpgform_options['default_css'] == 1)
1036
  {
1037
  wp_enqueue_style('gform',
1038
  plugins_url(plugin_basename(dirname(__FILE__) . '/gforms.css'))) ;
1039
  }
1040
+
1041
+ // Load the jQuery Validate from the Microsoft CDN, it isn't
1042
+ // available from the Google CDN or I'd load it from there!
1043
+ wp_register_script('jquery-validate',
1044
+ 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.js',
1045
+ array('jquery'), false, true) ;
1046
+ wp_enqueue_script('jquery-validate') ;
1047
  }
1048
  ?>
wpgform-debug.php CHANGED
@@ -22,6 +22,44 @@ $wpgform_debug_content = '' ;
22
  add_action('init', 'wpgform_debug', 0) ;
23
  add_action('wp_footer', 'wpgform_show_debug_content') ;
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  /**
26
  * Debug action to examine server variables
27
  *
22
  add_action('init', 'wpgform_debug', 0) ;
23
  add_action('wp_footer', 'wpgform_show_debug_content') ;
24
 
25
+ // In debug mode several filters can be disabled for debugging purposes.
26
+
27
+ $wpgform_options = wpgform_get_plugin_options() ;
28
+
29
+ // Change the HTTP Time out
30
+ if ($wpgform_options['http_request_timeout'] == 1)
31
+ {
32
+ if (is_int($wpgform_options['http_request_timeout_value'])
33
+ || ctype_digit($wpgform_options['http_request_timeout_value']))
34
+ {
35
+ add_filter('http_request_timeout',
36
+ function($timeout) {
37
+ $wpgform_options = wpgform_get_plugin_options() ;
38
+ return $wpgform_options['http_request_timeout'] ;
39
+ }) ;
40
+ }
41
+ }
42
+
43
+ // Disable fsockopen transport?
44
+ if ($wpgform_options['fsockopen_transport'] == 1)
45
+ add_filter('use_fsockopen_transport', '__return_false') ;
46
+
47
+ // Disable streams transport?
48
+ if ($wpgform_options['streams_transport'] == 1)
49
+ add_filter('use_streams_transport', '__return_false') ;
50
+
51
+ // Disable curl transport?
52
+ if ($wpgform_options['curl_transport'] == 1)
53
+ add_filter('use_curl_transport', '__return_false') ;
54
+
55
+ // Disable local ssl verify?
56
+ if ($wpgform_options['local_ssl_verify'] == 1)
57
+ add_filter('https_local_ssl_verify', '__return_false') ;
58
+
59
+ // Disable ssl verify?
60
+ if ($wpgform_options['ssl_verify'] == 1)
61
+ add_filter('https_ssl_verify', '__return_false') ;
62
+
63
  /**
64
  * Debug action to examine server variables
65
  *
wpgform-options.php CHANGED
@@ -101,7 +101,8 @@ function wpgform_options_page()
101
  <li><a href="#gform-tabs-1">Options</a></li>
102
  <li><a href="#gform-tabs-2">FAQs</a></li>
103
  <li><a href="#gform-tabs-3">Usage</a></li>
104
- <li><a href="#gform-tabs-4">About</a></li>
 
105
  </ul>
106
  <div id="gform-tabs-1">
107
  <form method="post" action="options.php">
@@ -239,6 +240,13 @@ function wpgform_options_page()
239
  ?>
240
  </div>
241
  <div id="gform-tabs-4">
 
 
 
 
 
 
 
242
  <h4>About WordPress Google Form</h4>
243
  <p>An easy to implement integration of a Google Form with WordPress. This plugin allows you to leverage the power of Google Docs Spreadsheets and Forms to collect data while retaining the look and feel of your WordPress based web site. The forms can optionally be styled to better integrate with your WordPress theme.</p>
244
  <p>WordPress Google Form is based on the <a href="http://codex.wordpress.org/HTTP_API"><b>WordPress HTTP API</b></a> and in particular, the <a href="http://codex.wordpress.org/Function_API/wp_remote_get"><b>wp_remote_get()</b></a> and <a href="http://codex.wordpress.org/Function_API/wp_remote_post"><b>wp_remote_post()</b></a> functions for retrieving and posting the form. WordPress Google Form also makes use of the <a href="http://codex.wordpress.org/Function_Reference/wp_kses"><b>wp_kses()</b></a> function for processing the HTML retrieved from Google and extracting the relevant parts of the form.</p><p>If you find this plugin useful, please consider <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DK4MS3AA983CC" target="_blank">making small donation towards this plugin</a> to help keep it up to date.</p>
@@ -359,6 +367,7 @@ function wpgform_settings_input()
359
  </fieldset></td>
360
  </tr>
361
  -->
 
362
  <tr valign="top">
363
  <th scope="row"><label>Enable Debug</label></th>
364
  <td><fieldset>
@@ -376,8 +385,97 @@ function wpgform_settings_input()
376
  </label>
377
  </fieldset></td>
378
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  </table>
380
  <br /><br />
 
 
 
 
 
 
 
 
 
 
381
  <?php
382
  }
383
  ?>
101
  <li><a href="#gform-tabs-1">Options</a></li>
102
  <li><a href="#gform-tabs-2">FAQs</a></li>
103
  <li><a href="#gform-tabs-3">Usage</a></li>
104
+ <li><a href="#gform-tabs-4">Debug</a></li>
105
+ <li><a href="#gform-tabs-5">About</a></li>
106
  </ul>
107
  <div id="gform-tabs-1">
108
  <form method="post" action="options.php">
240
  ?>
241
  </div>
242
  <div id="gform-tabs-4">
243
+ <form method="post" action="options.php">
244
+ <?php settings_fields('wpgform_options') ; ?>
245
+ <?php wpgform_settings_debug() ; ?>
246
+ <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
247
+ </form>
248
+ </div>
249
+ <div id="gform-tabs-5">
250
  <h4>About WordPress Google Form</h4>
251
  <p>An easy to implement integration of a Google Form with WordPress. This plugin allows you to leverage the power of Google Docs Spreadsheets and Forms to collect data while retaining the look and feel of your WordPress based web site. The forms can optionally be styled to better integrate with your WordPress theme.</p>
252
  <p>WordPress Google Form is based on the <a href="http://codex.wordpress.org/HTTP_API"><b>WordPress HTTP API</b></a> and in particular, the <a href="http://codex.wordpress.org/Function_API/wp_remote_get"><b>wp_remote_get()</b></a> and <a href="http://codex.wordpress.org/Function_API/wp_remote_post"><b>wp_remote_post()</b></a> functions for retrieving and posting the form. WordPress Google Form also makes use of the <a href="http://codex.wordpress.org/Function_Reference/wp_kses"><b>wp_kses()</b></a> function for processing the HTML retrieved from Google and extracting the relevant parts of the form.</p><p>If you find this plugin useful, please consider <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DK4MS3AA983CC" target="_blank">making small donation towards this plugin</a> to help keep it up to date.</p>
367
  </fieldset></td>
368
  </tr>
369
  -->
370
+ <!--
371
  <tr valign="top">
372
  <th scope="row"><label>Enable Debug</label></th>
373
  <td><fieldset>
385
  </label>
386
  </fieldset></td>
387
  </tr>
388
+ -->
389
+ </table>
390
+ <br /><br />
391
+ <input name="wpgform_options[enable_debug]" type="hidden" id="wpgform_enable_debug" value="<?php echo $wpgform_options['enable_debug'] ; ?>" />
392
+ <input name="wpgform_options[fsockopen_transport]" type="hidden" id="wpgform_fsockopen_transport" value="<?php echo $wpgform_options['fsockopen_transport'] ; ?>" />
393
+ <input name="wpgform_options[streams_transport]" type="hidden" id="wpgform_streams_transport" value="<?php echo $wpgform_options['streams_transport'] ; ?>" />
394
+ <input name="wpgform_options[curl_transport]" type="hidden" id="wpgform_curl_transport" value="<?php echo $wpgform_options['curl_transport'] ; ?>" />
395
+ <input name="wpgform_options[ssl_verify]" type="hidden" id="wpgform_ssl_verify" value="<?php echo $wpgform_options['ssl_verify'] ; ?>" />
396
+ <input name="wpgform_options[local_ssl_verify]" type="hidden" id="wpgform_local_ssl_verify" value="<?php echo $wpgform_options['local_ssl_verify'] ; ?>" />
397
+ <input name="wpgform_options[http_request_timeout]" type="hidden" id="wpgform_http_request_timeout" value="<?php echo $wpgform_options['http_request_timeout'] ; ?>" />
398
+ <input name="wpgform_options[http_request_timeout_value]" type="hidden" id="wpgform_http_request_timeout_value" value="<?php echo $wpgform_options['http_request_timeout_value'] ; ?>" />
399
+ <?php
400
+ }
401
+
402
+ /**
403
+ * wpgform_settings_debug()
404
+ *
405
+ * Build the form content and populate with any current plugin settings.
406
+ *
407
+ * @return none
408
+ */
409
+ function wpgform_settings_debug()
410
+ {
411
+ $wpgform_options = wpgform_get_plugin_options() ;
412
+ ?>
413
+ <table class="form-table">
414
+ <tr valign="top">
415
+ <th scope="row"><label>Enable Debug</label></th>
416
+ <td><fieldset>
417
+ <label for="gform_enable_debug">
418
+ <table style="padding: 0px;" border="0" cellpadding="0" cellspacing="0">
419
+ <tr>
420
+ <td style="padding: 5px 0px; vertical-align: top;">
421
+ <input name="wpgform_options[enable_debug]" type="checkbox" id="gform_enable_debug" value="1" <?php checked('1', $wpgform_options['enable_debug']) ; ?> />
422
+ </td>
423
+ <td style="padding: 5px;">
424
+ Enabling debug will collect data during the form rendering and processing process.<p>The data is added to the page footer but hidden with a link appearing above the form which can toggle the display of the debug data. This data is useful when trying to understand why the plugin isn't operating as expected.</p><p>When debugging is enabled, specific transports employed by the <a href="http://codex.wordpress.org/HTTP_API">WordPress HTTP API</a> can optionally be disabled. While rarely required, disabling transports can be useful when the plugin is not communcating correctly with the Google Docs API. <i>Extra care should be taken when disabling transports as other aspects of WordPress may not work correctly.</i> The <a href="http://wordpress.org/extend/plugins/core-control/">WordPress Core Control</a> plugin is recommended for advanced debugging of <a href="http://codex.wordpress.org/HTTP_API">WordPress HTTP API issues.</a></p>
425
+ </td>
426
+ </tr>
427
+ </table>
428
+ </label>
429
+ </fieldset></td>
430
+ </tr>
431
+ <tr valign="top">
432
+ <th scope="row"><label>WordPress HTTP API<br/>Transport Control</label></th>
433
+ <td><fieldset>
434
+ <label for="gform_fsockopen_transport">
435
+ <input name="wpgform_options[fsockopen_transport]" type="checkbox" id="gform_fsockopen_transport" value="1" <?php checked('1', $wpgform_options['fsockopen_transport']) ; ?> />
436
+ Disable <i><b>FSockOpen</b></i> Transport</label>
437
+ <br />
438
+ <label for="gform_streams_transport">
439
+ <input name="wpgform_options[streams_transport]" type="checkbox" id="gform_streams_transport" value="1" <?php checked('1', $wpgform_options['streams_transport']) ; ?> />
440
+ Disable <i><b>Streams</b></i> Transport</label>
441
+ <br />
442
+ <label for="gform_curl_transport">
443
+ <input name="wpgform_options[curl_transport]" type="checkbox" id="gform_curl_transport" value="1" <?php checked('1', $wpgform_options['curl_transport']) ; ?> />
444
+ Disable <i><b>cURL</b></i> Transport</label>
445
+ <br />
446
+ <label for="gform_ssl_verify">
447
+ <input name="wpgform_options[ssl_verify]" type="checkbox" id="gform_ssl_verify" value="1" <?php checked('1', $wpgform_options['ssl_verify']) ; ?> />
448
+ Disable <i><b>SSL Verify</b></i></label>
449
+ <br />
450
+ <label for="gform_local_ssl_verify">
451
+ <input name="wpgform_options[local_ssl_verify]" type="checkbox" id="gform_local_ssl_verify" value="1" <?php checked('1', $wpgform_options['local_ssl_verify']) ; ?> />
452
+ Disable <i><b>Local SSL Verify</b></i></label>
453
+ </fieldset></td>
454
+ </tr>
455
+ <tr valign="top">
456
+ <th scope="row"><label>HTTP Request Timeout</label></th>
457
+ <td><fieldset>
458
+ <label for="gform_http_request_timeout">
459
+ <input name="wpgform_options[http_request_timeout]" type="checkbox" id="gform_http_request_timeout" value="1" <?php checked('1', $wpgform_options['http_request_timeout']) ; ?> />
460
+ Change <i><b>HTTP Request Timeout</b></i></label>
461
+ <br />
462
+ <label for="gform_http_request_timeout_value">
463
+ <input name="wpgform_options[http_request_timeout_value]" type="text" id="wpgform_http_request_timeout_value" value="<?php echo $wpgform_options['http_request_timeout_value'] ; ?>" /><br />
464
+ <small>(in seconds)</small></label>
465
+ </fieldset></td>
466
+ </tr>
467
  </table>
468
  <br /><br />
469
+ <input name="wpgform_options[sc_posts]" type="hidden" id="wpgform_sc_posts" value="<?php echo $wpgform_options['sc_posts'] ; ?>" />
470
+ <input name="wpgform_options[sc_widgets]" type="hidden" id="wpgform_sc_widgets" value="<?php echo $wpgform_options['sc_widgets'] ; ?>" />
471
+ <input name="wpgform_options[default_css]" type="hidden" id="wpgform_default_css" value="<?php echo $wpgform_options['default_css'] ; ?>" />
472
+ <input name="wpgform_options[custom_css]" type="hidden" id="wpgform_custom_css" value="<?php echo $wpgform_options['custom_css'] ; ?>" />
473
+ <input name="wpgform_options[custom_css_styles]" type="hidden" id="wpgform_custom_css_styles" value="<?php echo $wpgform_options['custom_css_styles'] ; ?>" />
474
+ <input name="wpgform_options[donation_message]" type="hidden" id="wpgform_donation_message" value="<?php echo $wpgform_options['donation_message'] ; ?>" />
475
+ <input name="wpgform_options[email_format]" type="hidden" id="wpgform_email_format" value="<?php echo $wpgform_options['email_format'] ; ?>" />
476
+ <input name="wpgform_options[browser_check]" type="hidden" id="wpgform_browser_check" value="<?php echo $wpgform_options['browser_check'] ; ?>" />
477
+ <input name="wpgform_options[serialize_post_vars]" type="hidden" id="wpgform_serialize_post_vars" value="<?php echo $wpgform_options['serialize_post_vars'] ; ?>" />
478
+ <input name="wpgform_options[bcc_blog_admin]" type="hidden" id="wpgform_bcc_blog_admin" value="<?php echo $wpgform_options['bcc_blog_admin'] ; ?>" />
479
  <?php
480
  }
481
  ?>