Google Forms - Version v0.11

Version Description

No known upgrade issues.

Download this release

Release Info

Developer mpwalsh8
Plugin Icon wp plugin Google Forms
Version v0.11
Comparing to
See all releases

Code changes from version 0.10 to v0.11

Files changed (3) hide show
  1. gforms.css +7 -1
  2. readme.txt +23 -6
  3. wpgform-core.php +202 -21
gforms.css CHANGED
@@ -17,6 +17,10 @@ body.ss-base-body {}
17
  div.errorbox-good {}
18
  div.ss-attribution {}
19
  div.ss-footer {}
 
 
 
 
20
  div.ss-form {}
21
  div.ss-form-container {
22
  font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
@@ -46,7 +50,9 @@ hr.ss-email-break {}
46
  input.ss-q-short {
47
  width: 300px;
48
  }
49
- label.ss-q-help {}
 
 
50
  label.ss-q-radio {}
51
  label.ss-q-title {
52
  font-weight: bold;
17
  div.errorbox-good {}
18
  div.ss-attribution {}
19
  div.ss-footer {}
20
+ div.ss-footer-txt, div.ss-logo {
21
+ display: none;
22
+ }
23
+
24
  div.ss-form {}
25
  div.ss-form-container {
26
  font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
50
  input.ss-q-short {
51
  width: 300px;
52
  }
53
+ label.ss-q-help {
54
+ display: block;
55
+ }
56
  label.ss-q-radio {}
57
  label.ss-q-title {
58
  font-weight: bold;
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: mpwalsh8
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DK4MS3AA983CC
4
  Tags: Google Forms, Google Docs, Google, Spreadsheet, shortcode, forms
5
  Requires at least: 3.0
6
- Tested up to: 3.2.1
7
  Stable tag: 0.10
8
 
9
  Embeds a published, public Google Form in a WordPress post, page, or widget.
@@ -29,7 +29,7 @@ Currently, this plugin only supports Google Forms that are "Published as a web p
29
 
30
  == Usage ==
31
 
32
- The WordPress Google Form shortcode `gform` suupports a number of attributes that allow further control and customization of the Google Form.
33
 
34
  `[gform form='<full_url_to_Google_Form>' confirm='<full_url_to_confirmation_page>' class='<value>' legal='on|off' br='on|off' prefix='<value>' suffix='<value>']`
35
 
@@ -40,8 +40,10 @@ The WordPress Google Form shortcode `gform` suupports a number of attributes tha
40
  * __br__: For a <br> tag to be inserted between the form label and the input text box by setting the *br* attribute to *on*. This will result in the form label and the input box being stacked on top of one another.
41
  * __prefix__: Google Forms make use 20+ CSS classes. If you use multiple forms and want to style them each differently, you can add a _prefix_ which will be added to beginning of each class name used in the Google Form.
42
  * __suffix__: Append a character string to the end of each form label. This can also be accomplished using CSS, refer to the CSS section.
 
 
43
 
44
- `[gform form='https://docs.google.com/spreadsheet/viewform?hl=en_US&pli=1&formkey=ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678#gid=0' confirm='http://www.example.com/thankyou/' class='mygform' legal='off' prefix='mygform-' br='on']`
45
 
46
  == Frequently Asked Questions ==
47
 
@@ -51,7 +53,7 @@ Yes, there are two ways to change the style (aka apearance) of the form.
51
  1. By adding the necessary CSS to your theme's style sheet.
52
  1. Through the WordPress Google Form custom CSS setting.
53
 
54
- Google Forms include plenty of [CSS](http://en.wikipedia.org/wiki/Cascading_Style_Sheets) hooks. Refer to the **CSS** section for further details on styling the form.
55
 
56
  = Do you have a demo running? =
57
  Yes, see a demo here: [Demo of WordPress Google Form plugin](http://michaelwalsh.org/wordpress/wordpress-plugins/wpgform/)
@@ -89,7 +91,7 @@ There are two ways to customize the Google Form CSS.
89
 
90
  = Default Google Form CSS =
91
 
92
- As of 2011-10-07, the following is are the CSS classes which Google Forms make use of. The CSS below represents the default CSS provided by WordPress Google Form. These CSS definitions can be copied and pasted into your theme CSS or the WordPress Google Form custom CSS setting and changed as desired.
93
 
94
  `
95
  label.gform-error {
@@ -101,6 +103,10 @@ body.ss-base-body {}
101
  div.errorbox-good {}
102
  div.ss-attribution {}
103
  div.ss-footer {}
 
 
 
 
104
  div.ss-form {}
105
  div.ss-form-container {
106
  font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
@@ -130,7 +136,9 @@ hr.ss-email-break {}
130
  input.ss-q-short {
131
  width: 300px;
132
  }
133
- label.ss-q-help {}
 
 
134
  label.ss-q-radio {}
135
  label.ss-q-title {
136
  font-weight: bold;
@@ -165,6 +173,15 @@ No known upgrade issues.
165
 
166
  == Changelog ==
167
 
 
 
 
 
 
 
 
 
 
168
  = Version 0.10 =
169
 
170
  * Added support for required fields using the jQuery Validate plugin.
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DK4MS3AA983CC
4
  Tags: Google Forms, Google Docs, Google, Spreadsheet, shortcode, forms
5
  Requires at least: 3.0
6
+ Tested up to: 3.3.1
7
  Stable tag: 0.10
8
 
9
  Embeds a published, public Google Form in a WordPress post, page, or widget.
29
 
30
  == Usage ==
31
 
32
+ The WordPress Google Form shortcode `gform` supports a number of attributes that allow further control and customization of the Google Form.
33
 
34
  `[gform form='<full_url_to_Google_Form>' confirm='<full_url_to_confirmation_page>' class='<value>' legal='on|off' br='on|off' prefix='<value>' suffix='<value>']`
35
 
40
  * __br__: For a <br> tag to be inserted between the form label and the input text box by setting the *br* attribute to *on*. This will result in the form label and the input box being stacked on top of one another.
41
  * __prefix__: Google Forms make use 20+ CSS classes. If you use multiple forms and want to style them each differently, you can add a _prefix_ which will be added to beginning of each class name used in the Google Form.
42
  * __suffix__: Append a character string to the end of each form label. This can also be accomplished using CSS, refer to the CSS section.
43
+ * __title__: By default Google Forms have title wrapped in a <h1> tag. If you do not want to include this form title as part of the form, add `title='off'` to your shortcode usage. The <h1> content is removed from the form.
44
+ * __maph1h2: By default Google Forms have title wrapped in a <h1> tag. If you want the form title but not as an <h1> element, add `maph1h2='on'` to your shortcode usage. The <h1> elements will be mapped to <h2> elements. The CSS class attributes remain unchanged.
45
 
46
+ `[gform form='https://docs.google.com/spreadsheet/viewform?hl=en_US&pli=1&formkey=ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678#gid=0' confirm='http://www.example.com/thankyou/' class='mygform' legal='off' prefix='mygform-' br='on' title='on' maph1h2='on']`
47
 
48
  == Frequently Asked Questions ==
49
 
53
  1. By adding the necessary CSS to your theme's style sheet.
54
  1. Through the WordPress Google Form custom CSS setting.
55
 
56
+ Google Forms include plenty of [CSS](http://en.wikipedia.org/wiki/Cascading_Style_Sheets) hooks. Refer to the **CSS** section for further details on styling the form. There are also some CSS solutions posted to questions users have raised in the Tips and Tricks section of [this page](http://michaelwalsh.org/wordpress/wordpress-plugins/wpgform/tips-and-tricks/).
57
 
58
  = Do you have a demo running? =
59
  Yes, see a demo here: [Demo of WordPress Google Form plugin](http://michaelwalsh.org/wordpress/wordpress-plugins/wpgform/)
91
 
92
  = Default Google Form CSS =
93
 
94
+ As of 2012-01-07, the following is are the CSS classes which Google Forms make use of. The CSS below represents the default CSS provided by WordPress Google Form. These CSS definitions can be copied and pasted into your theme CSS or the WordPress Google Form custom CSS setting and changed as desired.
95
 
96
  `
97
  label.gform-error {
103
  div.errorbox-good {}
104
  div.ss-attribution {}
105
  div.ss-footer {}
106
+ div.ss-footer-txt, div.ss-logo {
107
+ display: none;
108
+ }
109
+
110
  div.ss-form {}
111
  div.ss-form-container {
112
  font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
136
  input.ss-q-short {
137
  width: 300px;
138
  }
139
+ label.ss-q-help {
140
+ display: block;
141
+ }
142
  label.ss-q-radio {}
143
  label.ss-q-title {
144
  font-weight: bold;
173
 
174
  == Changelog ==
175
 
176
+ = Version 0.11 =
177
+ * Re-architected plugin to support multi-page Google Forms.
178
+ * Fixed bug which resulted in form being redisplayed when using default confirmation.
179
+ * Deprecated use of jQuery Validaor plugin, it is no longer needed as Google is now doing required field checking and validation as part of the new architecture.
180
+ * New CSS styles added to support new architecture and confirmation page rendering.
181
+ * Default CSS style for div.ss-q-help changed to `display: block;`.
182
+ * New attribute *title* added to allow supressing for form title.
183
+ * New attribute *maph1h2* added to map H1 elements to H2 elements.
184
+
185
  = Version 0.10 =
186
 
187
  * Added support for required fields using the jQuery Validate plugin.
wpgform-core.php CHANGED
@@ -28,7 +28,7 @@ define('WPGFORM_PATH', WP_PLUGIN_DIR.'/'.dirname(plugin_basename(__FILE__))) ;
28
  */
29
  function wpgform_init()
30
  {
31
- $wpgform_options = get_option('wpgform_options') ;
32
 
33
  if ($wpgform_options['sc_posts'] == 1)
34
  add_shortcode('wpgform', 'wpgform_shortcode') ;
@@ -38,7 +38,42 @@ function wpgform_init()
38
 
39
  add_action('template_redirect', 'wpgform_head') ;
40
 
41
- add_action('wp_footer', 'wpgform_footer') ;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  }
43
 
44
  /**
@@ -104,6 +139,7 @@ add_shortcode('gform', array('wpGForm', 'RenderGForm')) ;
104
  * @author Mike Walsh <mike@walshcrew.com>
105
  * @access public
106
  * @see wp_remote_get()
 
107
  * @see RenderGForm()
108
  * @see ConstructGForm()
109
  */
@@ -165,6 +201,7 @@ class wpGForm
165
  {
166
  $prefix = $options['prefix'] ;
167
  }
 
168
  // Label Suffix? Optional
169
  if (!$options['suffix'])
170
  {
@@ -178,30 +215,90 @@ class wpGForm
178
  // Breaks between labels and inputs?
179
  $br = $options['br'] === 'on' ;
180
 
 
 
 
 
 
 
181
  // Google Legal Stuff?
182
  $legal = $options['legal'] !== 'off' ;
183
 
 
 
 
184
  // WordPress converts all of the ampersand characters to their
185
  // appropriate HTML entity or some variety of it. Need to undo
186
  // that so the URL can be actually be used.
187
 
188
  $form = str_replace(array('&#038;','&#38;','&amp;'), '&', $form) ;
189
- $confirm = str_replace(array('&#038;','&#38;','&amp;'), '&', $confirm) ;
 
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  // Retrieve the HTML from the URL
192
- $response = wp_remote_get($form, array('sslverify' => false)) ;
193
 
194
  if (is_wp_error($response))
195
- return '<div class="gform-error">Unable to retrieve Google Form.</div>' ;
196
  else
197
  $html = $response['body'] ;
198
 
199
-
200
  // Need to filter the HTML retrieved from the form and strip off the stuff
201
  // we don't want. This gets rid of the HTML wrapper from the Google page.
202
 
203
  $allowed_tags = array(
204
  'a' => array('href' => array(), 'title' => array(), 'target' => array())
 
205
  ,'abbr' => array('title' => array()),'acronym' => array('title' => array())
206
  ,'code' => array()
207
  ,'pre' => array()
@@ -214,6 +311,7 @@ class wpGForm
214
  ,'br' => array()
215
  ,'div' => array('class' => array())
216
  ,'h1' => array('class' => array())
 
217
  ,'label' => array('class' => array(), 'for' => array())
218
  ,'input' => array('id' => array(), 'name' => array(), 'class' => array(), 'type' => array(), 'value' => array())
219
  ,'select' => array('name' => array(), 'for' => array())
@@ -228,6 +326,8 @@ class wpGForm
228
  ,'td' => array('class' => array(), 'style' => array())
229
  ) ;
230
 
 
 
231
  $html = wp_kses($html, $allowed_tags) ;
232
 
233
  // Did we end up with anything prior to the first DIV? If so, remove it as
@@ -252,6 +352,19 @@ class wpGForm
252
  $html = preg_replace('#<script[^>]*>.*?</script>#is',
253
  '<!-- Google Forms unnessary Javascript removed -->' . PHP_EOL, $html) ;
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  // Augment class names with some sort of a prefix?
256
 
257
  if (!is_null($prefix))
@@ -270,8 +383,34 @@ class wpGForm
270
  // Hide Google Legal Stuff?
271
 
272
  if (!$legal)
273
- $html = preg_replace('/<div class="ss-legal"/i', '<div class="ss-legal" style="display:none;"', $html) ;
274
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  // By default Google will display it's own confirmation page which can't
276
  // be styled and is not contained within the web site. The plugin can
277
  // optionally add some Javascript to redirect to a different URL upon
@@ -279,29 +418,68 @@ class wpGForm
279
 
280
  // Redirect to a custom confirmation page instead of the Google default?
281
 
 
282
  if (!is_null($confirm))
283
  {
 
284
  // Need to modify the FORM tag and add some new attributes.
285
- $xtra_form_attrs = 'target="gform_iframe" onsubmit="submitted=true;"' ;
286
- $html = preg_replace("/<form/i", "<form {$xtra_form_attrs}", $html) ;
 
287
 
288
  // Need some extra HTML which must be inserted before the extract FORM HTML.
 
 
289
  $xtra_html = '<script type="text/javascript">var submitted=false;</script>' ;
290
- $xtra_html .= '<iframe name="gform_iframe" id="gform_iframe" style="display:none;" onload="if(submitted){window.location=\'' . $confirm . '\';}"></iframe>' ;
291
  }
292
  else
 
 
293
  $xtra_html = '' ;
 
 
 
294
 
295
  // Output custom CSS?
296
 
297
- $wpgform_options = get_option('wpgform_options') ;
298
 
299
  if ($wpgform_options['custom_css'] == 1)
300
  $css = '<style>' . $wpgform_options['custom_css_styles'] . '</style>' ;
301
  else
302
  $css = '' ;
303
 
304
- return $css . $xtra_html . $html ;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  }
306
 
307
  /**
@@ -311,13 +489,16 @@ class wpGForm
311
  */
312
  function RenderGForm($atts) {
313
  $params = shortcode_atts(array(
314
- 'form' => false, // Google Form URL
315
- 'confirm' => false, // Optional URL to redirect to instead of Google confirmation
316
- 'class' => 'gform', // Container element's custom class value
317
- 'legal' => 'on', // Display Google Legal Stuff
318
- 'br' => 'off', // Insert <br> tags between labels and inputs
319
- 'suffix' => null, // Add suffix character(s) to all labels
320
- 'prefix' => null // Add suffix character(s) to all labels
 
 
 
321
  ), $atts) ;
322
 
323
  return wpGForm::ConstructGForm($params) ;
@@ -331,7 +512,7 @@ class wpGForm
331
  */
332
  function wpgform_head()
333
  {
334
- $wpgform_options = get_option('wpgform_options') ;
335
 
336
  // Load default gForm CSS?
337
  if ($wpgform_options['default_css'] == 1)
28
  */
29
  function wpgform_init()
30
  {
31
+ $wpgform_options = wpgform_get_plugin_options() ;
32
 
33
  if ($wpgform_options['sc_posts'] == 1)
34
  add_shortcode('wpgform', 'wpgform_shortcode') ;
38
 
39
  add_action('template_redirect', 'wpgform_head') ;
40
 
41
+ //add_action('wp_footer', 'wpgform_footer') ;
42
+ }
43
+
44
+ /**
45
+ * Returns the default options for wpGForm.
46
+ *
47
+ * @since wpGForm 0.11
48
+ */
49
+ function wpgform_get_default_plugin_options()
50
+ {
51
+ $default_plugin_options = array(
52
+ 'sc_posts' => 1
53
+ ,'sc_widgets' => 1
54
+ ,'default_css' => 1
55
+ ,'custom_css' => 0
56
+ ,'custom_css_styles' => ''
57
+ ,'donation_message' => 0
58
+ ) ;
59
+
60
+ return apply_filters('wpgform_default_plugin_options', $default_plugin_options) ;
61
+ }
62
+
63
+ /**
64
+ * Returns the options array for the wpGForm plugin.
65
+ *
66
+ * @since wpGForm 0.11
67
+ */
68
+ function wpgform_get_plugin_options()
69
+ {
70
+ // Get the default options in case anything new has been added
71
+ $default_options = wpgform_get_default_plugin_options() ;
72
+
73
+ // Merge the default with any options currently saves by WordPress
74
+ $plugin_options = wp_parse_args(get_option('wpgform_options', array()), $default_options) ;
75
+
76
+ return $plugin_options ;
77
  }
78
 
79
  /**
139
  * @author Mike Walsh <mike@walshcrew.com>
140
  * @access public
141
  * @see wp_remote_get()
142
+ * @see wp_remote_post()
143
  * @see RenderGForm()
144
  * @see ConstructGForm()
145
  */
201
  {
202
  $prefix = $options['prefix'] ;
203
  }
204
+
205
  // Label Suffix? Optional
206
  if (!$options['suffix'])
207
  {
215
  // Breaks between labels and inputs?
216
  $br = $options['br'] === 'on' ;
217
 
218
+ // Output the H1 title included in the Google Form?
219
+ $title = $options['title'] === 'on' ;
220
+
221
+ // Map H1 tags to H2 tags? Apparently helps SEO ...
222
+ $maph1h2 = $options['maph1h2'] === 'on' ;
223
+
224
  // Google Legal Stuff?
225
  $legal = $options['legal'] !== 'off' ;
226
 
227
+ // Should form be set to readonly?
228
+ $readonly = $options['readonly'] === 'on' ;
229
+
230
  // WordPress converts all of the ampersand characters to their
231
  // appropriate HTML entity or some variety of it. Need to undo
232
  // that so the URL can be actually be used.
233
 
234
  $form = str_replace(array('&#038;','&#38;','&amp;'), '&', $form) ;
235
+ if (!is_null($confirm))
236
+ $confirm = str_replace(array('&#038;','&#38;','&amp;'), '&', $confirm) ;
237
 
238
+ // If we arrive here as a result of a POST then the Google Form was
239
+ // submitted (either completely or partially) so we need to act on
240
+ // the posted data appropriately. The user "submitting" the form
241
+ // doesn't actually do anything - it just tells us that the form was
242
+ // submitted and now the plugin needs to "really" submit it to Google,
243
+ // get the response, and display it as part of the WordPress content.
244
+
245
+ if (!empty($_POST))
246
+ {
247
+ $posted = true ;
248
+ //echo '<h1>Posted!</h1>' ;
249
+ //var_dump($_POST) ;
250
+ //var_dump($form) ;
251
+ $action = $_POST['gform-action'] ;
252
+ //var_dump($action) ;
253
+ unset($_POST['gform-action']) ;
254
+
255
+ $params = array() ;
256
+
257
+ // The name of the form fields are munged, they need
258
+ // to be restored before the parameters can be posted
259
+
260
+ foreach ($_POST as $key => $value)
261
+ {
262
+ $params[str_replace('_', '.', $key)] = $value ;
263
+ }
264
+
265
+ // Remove the action from the form and POST it
266
+
267
+ $form = str_replace($action, 'action=""', $form) ;
268
+
269
+ $response = wp_remote_post($action, array('sslverify' => false, 'body' => $params)) ;
270
+ //var_dump($response) ;
271
+
272
+ /*
273
+ if( is_wp_error( $response ) ) {
274
+ echo 'Something went wrong!';
275
+ } else {
276
+ echo 'Response:<pre>';
277
+ //print_r( $response );
278
+ echo '</pre>';
279
+ }
280
+ */
281
+ }
282
+ else
283
+ {
284
+ $posted = false ;
285
+ //echo '<h1>Not Posted!</h1>' ;
286
+ $response = wp_remote_get($form, array('sslverify' => false)) ;
287
+ }
288
+
289
  // Retrieve the HTML from the URL
 
290
 
291
  if (is_wp_error($response))
292
+ return '<div class="gform-error">Unable to retrieve Google Form. Please try reloading this page.</div>' ;
293
  else
294
  $html = $response['body'] ;
295
 
 
296
  // Need to filter the HTML retrieved from the form and strip off the stuff
297
  // we don't want. This gets rid of the HTML wrapper from the Google page.
298
 
299
  $allowed_tags = array(
300
  'a' => array('href' => array(), 'title' => array(), 'target' => array())
301
+ ,'b' => array()
302
  ,'abbr' => array('title' => array()),'acronym' => array('title' => array())
303
  ,'code' => array()
304
  ,'pre' => array()
311
  ,'br' => array()
312
  ,'div' => array('class' => array())
313
  ,'h1' => array('class' => array())
314
+ ,'i' => array()
315
  ,'label' => array('class' => array(), 'for' => array())
316
  ,'input' => array('id' => array(), 'name' => array(), 'class' => array(), 'type' => array(), 'value' => array())
317
  ,'select' => array('name' => array(), 'for' => array())
326
  ,'td' => array('class' => array(), 'style' => array())
327
  ) ;
328
 
329
+ // Process the HTML
330
+
331
  $html = wp_kses($html, $allowed_tags) ;
332
 
333
  // Did we end up with anything prior to the first DIV? If so, remove it as
352
  $html = preg_replace('#<script[^>]*>.*?</script>#is',
353
  '<!-- Google Forms unnessary Javascript removed -->' . PHP_EOL, $html) ;
354
 
355
+ // Allow H1 tags through if user wants them (which is the default)
356
+
357
+ if (!$title)
358
+ $html = preg_replace('#<h1[^>]*>.*?</h1>#is', '', $html) ;
359
+
360
+ // Map H1 tags to H2 tags?
361
+
362
+ if ($maph1h2)
363
+ {
364
+ $html = preg_replace('/<h1/i', '<h2', $html) ;
365
+ $html = preg_replace('/h1>/i', 'h2>', $html) ;
366
+ }
367
+
368
  // Augment class names with some sort of a prefix?
369
 
370
  if (!is_null($prefix))
383
  // Hide Google Legal Stuff?
384
 
385
  if (!$legal)
386
+ $html = preg_replace('/<div class="ss-legal"/i',
387
+ '<div class="ss-legal" style="display:none;"', $html) ;
388
+
389
+ // Need to extract form action and rebuild form tag,
390
+ // and add hidden field which contains the original
391
+ // action. This action is used to submit the form via
392
+ // wp_remote_post().
393
+
394
+ if (preg_match_all('/(action(\\s*)=(\\s*)([\"\'])?(?(1)(.*?)\\2|([^\s\>]+)))/', $html, $matches))
395
+ {
396
+ for ($i=0; $i< count($matches[0]); $i++)
397
+ {
398
+ //echo "<h1>matched $i: ".$matches[0][$i]."</h1>";
399
+ $action = $matches[0][$i] ;
400
+ }
401
+
402
+ $html = str_replace($action, 'action=""', $html) ;
403
+ $action = preg_replace('/^action/i', 'value', $action) ;
404
+
405
+ $html = preg_replace('/<\/form>/i',
406
+ "<input type=\"hidden\" {$action} name=\"gform-action\"></form>", $html) ;
407
+ }
408
+ else
409
+ {
410
+ $action = null ;
411
+ //print "<h1>A match was not found.</h1>";
412
+ }
413
+
414
  // By default Google will display it's own confirmation page which can't
415
  // be styled and is not contained within the web site. The plugin can
416
  // optionally add some Javascript to redirect to a different URL upon
418
 
419
  // Redirect to a custom confirmation page instead of the Google default?
420
 
421
+ /*
422
  if (!is_null($confirm))
423
  {
424
+ error_log(sprintf('%s::%s', basename(__FILE__), __LINE__)) ;
425
  // Need to modify the FORM tag and add some new attributes.
426
+ //$xtra_form_attrs = 'onsubmit="submitted=true;"' ;
427
+ //$xtra_form_attrs = 'target="gform_iframe" onsubmit="submitted=true;"' ;
428
+ //$html = preg_replace("/<form/i", "<form {$xtra_form_attrs}", $html) ;
429
 
430
  // Need some extra HTML which must be inserted before the extract FORM HTML.
431
+ //$xtra_html = '<script type="text/javascript">var submitted=false;</script>' ;
432
+ //$xtra_html .= '<iframe name="gform_iframe" id="gform_iframe" width="500" height="300" style="border: 2px solid yellow;display:block;" onload="if(submitted){window.location=\'' . $confirm . '\';}"></iframe>' ;
433
  $xtra_html = '<script type="text/javascript">var submitted=false;</script>' ;
 
434
  }
435
  else
436
+ {
437
+ error_log(sprintf('%s::%s', basename(__FILE__), __LINE__)) ;
438
  $xtra_html = '' ;
439
+ }
440
+ */
441
+ $xtra_html = '' ;
442
 
443
  // Output custom CSS?
444
 
445
+ $wpgform_options = wpgform_get_plugin_options() ;
446
 
447
  if ($wpgform_options['custom_css'] == 1)
448
  $css = '<style>' . $wpgform_options['custom_css_styles'] . '</style>' ;
449
  else
450
  $css = '' ;
451
 
452
+ // Output Javscript for form validation
453
+ $js = '
454
+ <script type="text/javascript">
455
+ jQuery(document).ready(function($) {
456
+
457
+ /*
458
+ $("div > .ss-item-required input").addClass("gform-required");
459
+ $("div > .ss-item-required textarea").addClass("gform-required");
460
+ $.validator.addClassRules("gform-required", {
461
+ required: true
462
+ });
463
+ //$("#ss-form").validate({
464
+ //errorClass: "gform-error"
465
+ //}) ;*/' ;
466
+
467
+ // Before closing the <script> tag, is the form read only?
468
+ if ($readonly) $js .= '
469
+ $("div.ss-form-container :input").attr("disabled", true);
470
+ ' ;
471
+
472
+ // Before closing the <script> tag, is this the confirmation
473
+ // AND do we have a custom confiormation page?
474
+ if ($posted && is_null($action) && !is_null($confirm))
475
+ $js .= PHP_EOL . 'window.location.replace("' . $confirm . '") ;' ;
476
+
477
+ $js .= '
478
+ });
479
+ </script>
480
+ ' ;
481
+
482
+ return $js . $css . $xtra_html . $html ;
483
  }
484
 
485
  /**
489
  */
490
  function RenderGForm($atts) {
491
  $params = shortcode_atts(array(
492
+ 'form' => false, // Google Form URL
493
+ 'confirm' => false, // Custom confirmation page URL to redirect to
494
+ 'class' => 'gform', // Container element's custom class value
495
+ 'legal' => 'on', // Display Google Legal Stuff
496
+ 'br' => 'off', // Insert <br> tags between labels and inputs
497
+ 'suffix' => null, // Add suffix character(s) to all labels
498
+ 'prefix' => null, // Add suffix character(s) to all labels
499
+ 'readonly' => 'off', // Set all form elements to disabled
500
+ 'title' => 'on', // Remove the H1 element(s) from the Form
501
+ 'maph1h2' => 'off' // Map H1 element(s) on the form to H2 element(s)
502
  ), $atts) ;
503
 
504
  return wpGForm::ConstructGForm($params) ;
512
  */
513
  function wpgform_head()
514
  {
515
+ $wpgform_options = wpgform_get_plugin_options() ;
516
 
517
  // Load default gForm CSS?
518
  if ($wpgform_options['default_css'] == 1)