Contact Form 7 Multi-Step Forms - Version 2.0

Version Description

Added Form Tags to Form Tag Generator. No more needing to update the Additional Settings tab.
Added error alert when form is too large.
Fixed Deprecated: preg_replace() error message.
Fixed certain instances where the "Please fill out the form on the previous page" messages displayed unexpectedly. Fixed issue where it was possible to type in the url of the next step after receiving validation errors on the current step.

Download this release

Release Info

Developer webheadllc
Plugin Icon 128x128 Contact Form 7 Multi-Step Forms
Version 2.0
Comparing to
See all releases

Code changes from version 1.6 to 2.0

contact-form-7-multi-step-module.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.mymonkeydo.com/contact-form-7-multi-step-module/
5
  Description: Enables the Contact Form 7 plugin to create multi-page, multi-step forms.
6
  Author: Webhead LLC.
7
  Author URI: http://webheadcoder.com
8
- Version: 1.6
9
  */
10
  /* Copyright 2012 Webhead LLC (email: info at webheadcoder.com)
11
 
@@ -24,10 +24,63 @@ Version: 1.6
24
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
  */
26
 
27
- define( 'CF7MSM_VERSION', '1.6' );
 
28
  define( 'CF7MSM_FREE_TEXT_PREFIX_RADIO', '_wpcf7_radio_free_text_' );
29
  define( 'CF7MSM_FREE_TEXT_PREFIX_CHECKBOX', '_wpcf7_checkbox_free_text_' );
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  /**
32
  * Load modules after plugins loaded to check for hidden module.
33
  */
@@ -37,11 +90,9 @@ function cf7msm_load_modules() {
37
  //hack to let contact-form-7-modules be activated.
38
  //next time require it to be activated instead of copying it in!
39
  if (!is_admin() || !isset($_GET['action']) || $_GET['action'] != 'activate' ) {
40
- require_once(plugin_dir_path(__FILE__) . 'module-hidden.php');
41
  }
42
  }
43
- require_once(plugin_dir_path(__FILE__) . 'module-session.php');
44
- require_once(plugin_dir_path(__FILE__) . 'module-back.php');
45
  }
46
  add_action('plugins_loaded', 'cf7msm_load_modules', 2);
47
 
@@ -73,12 +124,12 @@ add_action('init', 'cf7msm_init_sessions');
73
  function cf7msm_scripts() {
74
  $step = cf7msm_get('step');
75
  wp_enqueue_script('cf7msm',
76
- plugins_url('/resources/cf7msm.js', __FILE__),
77
  array('jquery'),
78
  CF7MSM_VERSION,
79
  true );
80
  wp_enqueue_style('cf7msm_styles',
81
- plugins_url('/resources/cf7msm.css', __FILE__),
82
  array(),
83
  CF7MSM_VERSION
84
  );
@@ -132,7 +183,7 @@ function cf7msm_remove($var_name) {
132
  }
133
  else {
134
  if ( isset( $_COOKIE[$var_name] ) ) {
135
- setcookie($var_name, '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN);
136
  }
137
  }
138
  }
@@ -145,31 +196,38 @@ function cf7msm_remove($var_name) {
145
  */
146
  function cf7msm_step_2($cf7) {
147
  $has_wpcf7_class = class_exists( 'WPCF7_ContactForm' ) && method_exists($cf7, 'prop');
 
148
  if ( $has_wpcf7_class ) {
149
  $formstring = $cf7->prop('form');
 
150
  }
151
  else {
152
  $formstring = $cf7->form;
 
153
  }
154
- //check if form has a step field
155
- if (!is_admin() && preg_match('/\[hidden step "(\d+)-(\d+)"\]/', $formstring, $matches)) {
156
- $step = cf7msm_get('step');
157
- if ( !isset($matches[1])
158
- || ($matches[1] != 1 && empty($step) )
159
- || ($matches[1] != 1 && ((int) $step) + 1 < $matches[1]) ) {
160
- if ( $has_wpcf7_class ) {
161
- $cf7->set_properties( array(
162
- 'form' => apply_filters('wh_hide_cf7_step_message', "Please fill out the form on the previous page")
163
- ) );
 
 
 
 
 
 
164
  }
165
- else {
166
- $cf7->form = apply_filters('wh_hide_cf7_step_message', "Please fill out the form on the previous page");
167
  }
168
  }
169
- if (count($matches) == 3 && $matches[1] != $matches[2]) {
170
- add_filter('wpcf7_ajax_json_echo', 'cf7msm_clear_success_message', 10, 2);
171
- }
172
  }
 
173
  return $cf7;
174
  }
175
  add_action('wpcf7_contact_form', 'cf7msm_step_2');
@@ -232,7 +290,6 @@ function cf7msm_store_data_steps_filter( $cf7_posted_data ) {
232
  if ($curr_step != $last_step) {
233
  $wpcf7 = WPCF7_ContactForm::get_current();
234
  $wpcf7->skip_mail = true;
235
- cf7msm_set('step', $curr_step);
236
  $posted_data = array_merge($prev_data, $cf7_posted_data);
237
  cf7msm_set('cf7msm_posted_data', $posted_data );
238
  }
@@ -244,6 +301,33 @@ function cf7msm_store_data_steps_filter( $cf7_posted_data ) {
244
  }
245
  add_filter( 'wpcf7_posted_data', 'cf7msm_store_data_steps_filter', 9 );
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  /**
248
  * Clean things up after mail has been sent.
249
  */
@@ -257,17 +341,27 @@ function cf7msm_mail_sent() {
257
  if ( $curr_step == $last_step ) {
258
  cf7msm_remove('step');
259
  cf7msm_remove('cf7msm_posted_data');
 
260
  }
261
  else {
262
- // redirect
263
- // for now only redirect when ajax is disabled.
 
264
  if ( !wpcf7_load_js() ) {
265
- $wpcf7 = WPCF7_ContactForm::get_current();
266
- $subject = $wpcf7->prop('additional_settings');
267
- $pattern = '/location\.replace\(\'([^\']*)\'\);/';
268
- preg_match( $pattern, $subject, $matches );
269
- if ( count( $matches ) == 2 ) {
270
- wp_redirect( esc_url( $matches[1] ) );
 
 
 
 
 
 
 
 
271
  exit;
272
  }
273
  }
@@ -276,72 +370,33 @@ function cf7msm_mail_sent() {
276
  }
277
  add_action( 'wpcf7_mail_sent', 'cf7msm_mail_sent' );
278
 
279
-
280
  /**
281
- * Handle a multi-step cf7 form for cf7 < 3.9
282
  */
283
- /*
284
- function cf7msm_store_data_steps(&$cf7) {
285
- if (isset($cf7->posted_data['step'])) {
286
- if (preg_match('/(\d+)-(\d+)/', $cf7->posted_data['step'], $matches)) {
287
- $curr_step = $matches[1];
288
- $last_step = $matches[2];
289
- }
290
-
291
- //for back button
292
- $prev_urls = cf7msm_get('cf7msm_prev_urls');
293
- if ( empty($prev_urls) ) {
294
- $prev_urls = array();
295
  }
296
- //example:
297
- // on step 1,
298
- // prev url {"2-3":"page-2"} will be set.
299
- // back button is pressed, key "1-3" is looked up and returns undefined
300
- // on step 2,
301
- // prev url {"3-3":"page-2"} will be set.
302
- // back button is pressed, key "2-3" is looked up and returns "page-1"
303
- // on step 3,
304
- // prev url {"4-3":"page-3"} will be set. - not used
305
- // back button is pressed, key "3-3" is looked up and returns "page-2"
306
- // step
307
- $prev_urls[ ($curr_step+1) . '-' . $last_step] = cf7msm_current_url();
308
- cf7msm_set('cf7msm_prev_urls', $prev_urls);
309
-
310
- $prev_data = cf7msm_get('cf7msm_posted_data', '' );
311
- if (!is_array($prev_data)) {
312
- $prev_data = array();
313
- }
314
- //remove empty [form] tags from posted_data so $prev_data can be stored.
315
- $fes = wpcf7_scan_shortcode();
316
- foreach ( $fes as $fe ) {
317
- if ( empty( $fe['name'] ) || $fe['type'] != 'form' )
318
- continue;
319
- unset($cf7->posted_data[$fe['name']]);
320
- }
321
- if ($curr_step != $last_step) {
322
- $cf7->skip_mail = true;
323
- cf7msm_set('step', $curr_step);
324
- $posted_data = array_merge($prev_data, $cf7->posted_data);
325
- cf7msm_set('cf7msm_posted_data', $posted_data );
326
- }
327
- else {
328
- $cf7->posted_data = array_merge($prev_data, $cf7->posted_data);
329
- cf7msm_remove('step');
330
- cf7msm_remove('cf7msm_posted_data');
331
- }
332
- }
333
  }
334
- */
335
 
336
  /**
337
- * Hide success message if form is redirecting to another page.
338
  */
339
- function cf7msm_clear_success_message($items, $result) {
340
- remove_filter('wpcf7_ajax_json_echo', 'cf7msm_clear_success_message');
341
- if ($items['mailSent'] && isset($items['onSentOk']) && count($items['onSentOk']) > 0) {
342
- $items['onSentOk'][] = "$('" . $items['into'] . "').find('div.wpcf7-response-output').css('opacity',0);";
 
 
343
  }
344
- return $items;
345
  }
346
 
347
  /**
@@ -361,12 +416,46 @@ function cf7msm_current_url() {
361
  return $page_url;
362
  }
363
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
  /************************************************************************************************************
365
  * Contact Form 7 has a nice success message after submitting its forms, but on a multi-step form,
366
  * this can cause confusion if it shows and the page immediately leaves to the next page.
367
  * The functions below hide the success messages on multi-step forms.
368
  ************************************************************************************************************/
369
 
 
 
 
 
 
 
 
 
 
 
 
370
  /**
371
  * Hide form when done.
372
  */
@@ -381,7 +470,8 @@ function cf7msm_hide_multistep_form($items, $result) {
381
  /**
382
  * Add filter to clear form if this is a multistep form.
383
  */
384
- function cf7msm_cf7_before_mail($cf7) {
 
385
  $step = cf7msm_get('step');
386
  if ( !empty( $step ) ) {
387
  add_filter('wpcf7_ajax_json_echo', 'cf7msm_hide_multistep_form', 10, 2);
5
  Description: Enables the Contact Form 7 plugin to create multi-page, multi-step forms.
6
  Author: Webhead LLC.
7
  Author URI: http://webheadcoder.com
8
+ Version: 2.0
9
  */
10
  /* Copyright 2012 Webhead LLC (email: info at webheadcoder.com)
11
 
24
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
  */
26
 
27
+ define( 'CF7MSM_VERSION', '2.0' );
28
+ define( 'CF7MSM_PLUGIN', __FILE__ );
29
  define( 'CF7MSM_FREE_TEXT_PREFIX_RADIO', '_wpcf7_radio_free_text_' );
30
  define( 'CF7MSM_FREE_TEXT_PREFIX_CHECKBOX', '_wpcf7_checkbox_free_text_' );
31
 
32
+
33
+ require_once(plugin_dir_path(CF7MSM_PLUGIN) . 'form-tags/module-multistep.php');
34
+ require_once(plugin_dir_path(CF7MSM_PLUGIN) . 'form-tags/module-session.php');
35
+ require_once(plugin_dir_path(CF7MSM_PLUGIN) . 'form-tags/module-back.php');
36
+
37
+
38
+ /**
39
+ * Print a warning if cf7 not installed or activated.
40
+ */
41
+ function contact_form_7_form_codes() {
42
+ global $pagenow;
43
+ if ( $pagenow != 'plugins.php' || function_exists('wpcf7_add_shortcode') )
44
+ return;
45
+ add_action('admin_notices', 'cfformfieldserror');
46
+ wp_enqueue_script('thickbox');
47
+ function cfformfieldserror() {
48
+ $out = '<div class="error" id="messages"><p>';
49
+ if(file_exists(WP_PLUGIN_DIR.'/contact-form-7/wp-contact-form-7.php')) {
50
+ $out .= 'The Contact Form 7 is installed, but <strong>you must activate Contact Form 7</strong> below for the Contact Form 7 Multi-Step Form to work code to work.';
51
+ } else {
52
+ $out .= 'The Contact Form 7 plugin must be installed for the Contact Form 7 Multi-Step Form to work. <a href="'.admin_url('plugin-install.php?tab=plugin-information&plugin=contact-form-7&from=plugins&TB_iframe=true&width=600&height=550').'" class="thickbox" title="Contact Form 7">Install Now.</a>';
53
+ }
54
+ $out .= '</p></div>';
55
+ echo $out;
56
+ }
57
+ }
58
+ add_action('plugins_loaded', 'contact_form_7_form_codes', 10);
59
+
60
+ /**
61
+ * Return the url with the plugin url prepended.
62
+ */
63
+ function cf7msm_url( $path ) {
64
+ return plugins_url( $path, CF7MSM_PLUGIN );
65
+ }
66
+
67
+ /**
68
+ * Tag generator helper scripts
69
+ */
70
+ function cf7msm_admin_enqueue_scripts( $hook_suffix ) {
71
+ if ( false === strpos( $hook_suffix, 'wpcf7' ) ) {
72
+ return;
73
+ }
74
+ wp_enqueue_script( 'cf7msm-admin-taggenerator',
75
+ cf7msm_url( 'form-tags/js/tag-generator.js' ),
76
+ array( 'jquery' ), CF7MSM_VERSION, true );
77
+
78
+ wp_enqueue_style( 'cf7msm-admin',
79
+ cf7msm_url( 'form-tags/css/styles.css' ),
80
+ array( 'contact-form-7-admin' ), CF7MSM_VERSION );
81
+ }
82
+ add_action( 'admin_enqueue_scripts', 'cf7msm_admin_enqueue_scripts' );
83
+
84
  /**
85
  * Load modules after plugins loaded to check for hidden module.
86
  */
90
  //hack to let contact-form-7-modules be activated.
91
  //next time require it to be activated instead of copying it in!
92
  if (!is_admin() || !isset($_GET['action']) || $_GET['action'] != 'activate' ) {
93
+ require_once(plugin_dir_path(CF7MSM_PLUGIN) . 'form-tags/module-hidden.php');
94
  }
95
  }
 
 
96
  }
97
  add_action('plugins_loaded', 'cf7msm_load_modules', 2);
98
 
124
  function cf7msm_scripts() {
125
  $step = cf7msm_get('step');
126
  wp_enqueue_script('cf7msm',
127
+ plugins_url('/resources/cf7msm.js', CF7MSM_PLUGIN),
128
  array('jquery'),
129
  CF7MSM_VERSION,
130
  true );
131
  wp_enqueue_style('cf7msm_styles',
132
+ plugins_url('/resources/cf7msm.css', CF7MSM_PLUGIN),
133
  array(),
134
  CF7MSM_VERSION
135
  );
183
  }
184
  else {
185
  if ( isset( $_COOKIE[$var_name] ) ) {
186
+ setcookie($var_name, '', 1, COOKIEPATH, COOKIE_DOMAIN);
187
  }
188
  }
189
  }
196
  */
197
  function cf7msm_step_2($cf7) {
198
  $has_wpcf7_class = class_exists( 'WPCF7_ContactForm' ) && method_exists($cf7, 'prop');
199
+ $form_id = '';
200
  if ( $has_wpcf7_class ) {
201
  $formstring = $cf7->prop('form');
202
+ $form_id = $cf7->id();
203
  }
204
  else {
205
  $formstring = $cf7->form;
206
+ $form_id = $cf7->id;
207
  }
208
+ if ( !empty( $_POST['_wpcf7'] ) && $_POST['_wpcf7'] == $form_id ) {
209
+ //check if form has a step field
210
+ if (!is_admin() &&
211
+ ( preg_match('/\[multistep "(\d+)-(\d+)-?(.*)"\]/', $formstring, $matches) || preg_match('/\[hidden step "(\d+)-(\d+)"\]/', $formstring, $matches) ) ) {
212
+ $step = cf7msm_get('step');
213
+ if ( !isset($matches[1])
214
+ || ($matches[1] != 1 && empty($step) )
215
+ || ($matches[1] != 1 && ((int) $step) + 1 < $matches[1]) ) {
216
+ if ( $has_wpcf7_class ) {
217
+ $cf7->set_properties( array(
218
+ 'form' => apply_filters('wh_hide_cf7_step_message', "Please fill out the form on the previous page")
219
+ ) );
220
+ }
221
+ else {
222
+ $cf7->form = apply_filters('wh_hide_cf7_step_message', "Please fill out the form on the previous page");
223
+ }
224
  }
225
+ if (count($matches) >= 3 && $matches[1] != $matches[2]) {
226
+ add_filter('wpcf7_ajax_json_echo', 'cf7msm_clear_success_message', 10, 2);
227
  }
228
  }
 
 
 
229
  }
230
+
231
  return $cf7;
232
  }
233
  add_action('wpcf7_contact_form', 'cf7msm_step_2');
290
  if ($curr_step != $last_step) {
291
  $wpcf7 = WPCF7_ContactForm::get_current();
292
  $wpcf7->skip_mail = true;
 
293
  $posted_data = array_merge($prev_data, $cf7_posted_data);
294
  cf7msm_set('cf7msm_posted_data', $posted_data );
295
  }
301
  }
302
  add_filter( 'wpcf7_posted_data', 'cf7msm_store_data_steps_filter', 9 );
303
 
304
+ /**
305
+ * Sets the current step if valid.
306
+ */
307
+ function cf7msm_set_step( $result, $tags ) {
308
+ if ( !empty( $_POST['step'] ) ) {
309
+ $step = $_POST['step'];
310
+ if (preg_match('/(\d+)-(\d+)/', $step, $matches)) {
311
+ $curr_step = $matches[1];
312
+ $last_step = $matches[2];
313
+ if ( $result->is_valid() ) {
314
+ if ($curr_step != $last_step) {
315
+ cf7msm_set('step', $curr_step);
316
+ }
317
+ }
318
+ else {
319
+ $stored_step = cf7msm_get('step');
320
+ if ( $stored_step >= $curr_step ) {
321
+ //reduce it so user cannot move onto next step.
322
+ cf7msm_set('step', intval( $curr_step ) - 1);
323
+ }
324
+ }
325
+ }
326
+ }
327
+ return $result;
328
+ }
329
+ add_filter( 'wpcf7_validate', 'cf7msm_set_step', 99, 2 );
330
+
331
  /**
332
  * Clean things up after mail has been sent.
333
  */
341
  if ( $curr_step == $last_step ) {
342
  cf7msm_remove('step');
343
  cf7msm_remove('cf7msm_posted_data');
344
+ cf7msm_remove('cf7msm_prev_urls');
345
  }
346
  else {
347
+ $wpcf7 = WPCF7_ContactForm::get_current();
348
+ $formstring = $wpcf7->prop('form');
349
+ // redirect when ajax is disabled.
350
  if ( !wpcf7_load_js() ) {
351
+ //get url from saved form, not $_POST. be safe.
352
+ $redirect_url = parse_form_for_multistep_url( $wpcf7 );
353
+ if ( empty( $redirect_url ) ) {
354
+ // if using old additional_settings way
355
+ $subject = $wpcf7->prop('additional_settings');
356
+ $pattern = '/location\.replace\(\'([^\']*)\'\);/';
357
+ preg_match( $pattern, $subject, $matches );
358
+ if ( count( $matches ) == 2 ) {
359
+ $redirect_url = $matches[1];
360
+ }
361
+ }
362
+ $redirect_url = apply_filters( 'cf7msm_redirect_url', $redirect_url, $wpcf7->id() );
363
+ if ( !empty( $redirect_url ) ) {
364
+ wp_redirect( esc_url( $redirect_url ) );
365
  exit;
366
  }
367
  }
370
  }
371
  add_action( 'wpcf7_mail_sent', 'cf7msm_mail_sent' );
372
 
 
373
  /**
374
+ * Fabricate additional_settings if this is a multistep form and on_sent_ok not set.
375
  */
376
+ function fabricate_additional_settings( $wpcf7 ) {
377
+ $on_sent_ok = $wpcf7->additional_setting( 'on_sent_ok', false );
378
+ if ( empty( $on_sent_ok ) ) {
379
+ $redirect_url = parse_form_for_multistep_url( $wpcf7 );
380
+ $redirect_url = apply_filters( 'cf7msm_redirect_url', $redirect_url, $wpcf7->id() );
381
+ if ( !empty( $redirect_url ) ) {
382
+ $properties = $wpcf7->get_properties();
383
+ $properties['additional_settings'] .= "\non_sent_ok: \"location.replace('" . esc_url( $redirect_url ) . "');\"
384
+ ";
385
+ $wpcf7->set_properties( $properties );
 
 
386
  }
387
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388
  }
 
389
 
390
  /**
391
+ * Go through a wpcf7 form's formstring and find the multistep url.
392
  */
393
+ function parse_form_for_multistep_url( $wpcf7 ) {
394
+ $formstring = $wpcf7->prop('form');
395
+ if (preg_match('/\[multistep "(\d+)-(\d+)-(.+)"\]/', $formstring, $matches)) {
396
+ if ( !empty( $matches[3] ) ) {
397
+ return $matches[3];
398
+ }
399
  }
 
400
  }
401
 
402
  /**
416
  return $page_url;
417
  }
418
 
419
+
420
+ /**
421
+ * note at top of form tags
422
+ */
423
+ function cf7msm_form_tag_header_text( $header_description ) {
424
+ $description = __( $header_description . ". For more details, see %s.", 'contact-form-7' );
425
+ $desc_link = wpcf7_link( __( 'https://wordpress.org/plugins/contact-form-7-multi-step-module/', 'contact-form-7' ), __( 'the plugin page on WordPress.org', 'contact-form-7' ), array('target' => '_blank' ) );
426
+ printf( esc_html( $description ), $desc_link );
427
+ }
428
+
429
+ /**
430
+ * Links to help the plugin.
431
+ */
432
+ function cf7msm_form_tag_footer_text() {
433
+ ?>
434
+ <p class="description" style="font-size:12px;margin-top:0;padding-top:0;font-style:normal;">Like the Multi-step addition to CF7? Let me know - <a href="http://webheadcoder.com/donate-cf7-multi-step-forms" target="_blank">Donate</a> and <a href="https://wordpress.org/support/view/plugin-reviews/contact-form-7-multi-step-module#postform" target="_blank">Review</a>.
435
+ </p>
436
+ <div style="position:absolute; right:25px; bottom:5px;">
437
+ <a href="http://webheadcoder.com" target="_blank"><img src="<?php echo cf7msm_url( '/resources/logo.png' )?>" width="40"></a>
438
+ </div>
439
+ <?php
440
+ }
441
+
442
  /************************************************************************************************************
443
  * Contact Form 7 has a nice success message after submitting its forms, but on a multi-step form,
444
  * this can cause confusion if it shows and the page immediately leaves to the next page.
445
  * The functions below hide the success messages on multi-step forms.
446
  ************************************************************************************************************/
447
 
448
+ /**
449
+ * Hide success message if form is redirecting to another page.
450
+ */
451
+ function cf7msm_clear_success_message($items, $result) {
452
+ remove_filter('wpcf7_ajax_json_echo', 'cf7msm_clear_success_message');
453
+ if ($items['mailSent'] && isset($items['onSentOk']) && count($items['onSentOk']) > 0) {
454
+ $items['onSentOk'][] = "$('" . $items['into'] . "').find('div.wpcf7-response-output').css('opacity',0);";
455
+ }
456
+ return $items;
457
+ }
458
+
459
  /**
460
  * Hide form when done.
461
  */
470
  /**
471
  * Add filter to clear form if this is a multistep form.
472
  */
473
+ function cf7msm_cf7_before_mail( $wpcf7 ) {
474
+ fabricate_additional_settings( $wpcf7 );
475
  $step = cf7msm_get('step');
476
  if ( !empty( $step ) ) {
477
  add_filter('wpcf7_ajax_json_echo', 'cf7msm_hide_multistep_form', 10, 2);
form-tags/css/styles.css ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ /* small fix to not show scrollbars, make insert section taller */
2
+ .tag-generator-panel .insert-box {
3
+ padding-left: 15px;
4
+ padding-right: 15px;
5
+ height: 90px;
6
+ }
7
+
form-tags/js/tag-generator.js ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($) {
2
+ $('form.tag-generator-panel .cf7msm-multistep .cf7msm-multistep-values').change(function(){
3
+ var current_step = $('input[name="values_current_step"]', $(this.form)).val();
4
+ var total_steps = $('input[name="values_total_steps"]', $(this.form)).val();
5
+ var next_url = $('input[name="next_url"]', $(this.form)).val();
6
+ var value = current_step + '-' + total_steps;
7
+ if ( next_url.length > 0 ) {
8
+ value += '-' + next_url;
9
+ }
10
+ $('input[name="values"]', $(this.form)).val( value );
11
+
12
+ if ( total_steps > 3 ) {
13
+ $(".cf7msm-faq", $(this.form)).fadeIn();
14
+ }
15
+ else {
16
+ $(".cf7msm-faq", $(this.form)).fadeOut();
17
+ }
18
+ });
19
+
20
+
21
+ })(jQuery);
form-tags/module-back.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* Copyright 2016 Webhead LLC (email: info at webheadcoder.com)
3
+
4
+ This program is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU General Public License
6
+ as published by the Free Software Foundation; either version 2
7
+ of the License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+
18
+ */
19
+
20
+ /**
21
+ * Initialize this wpcf7 shortcode.
22
+ */
23
+ function cf7msm_add_shortcode_back() {
24
+ if (function_exists('wpcf7_add_shortcode')) {
25
+ wpcf7_add_shortcode(
26
+ array( 'back', 'previous' ),
27
+ 'cf7msm_back_shortcode_handler',
28
+ true
29
+ );
30
+ }
31
+ }
32
+ add_action( 'wpcf7_init', 'cf7msm_add_shortcode_back' );
33
+
34
+ /**
35
+ * Handle the back form shortcode.
36
+ */
37
+ function cf7msm_back_shortcode_handler( $tag ) {
38
+ if (!class_exists('WPCF7_Shortcode') || !function_exists('wpcf7_form_controls_class'))
39
+ return;
40
+ $tag = new WPCF7_Shortcode( $tag );
41
+
42
+ $class = wpcf7_form_controls_class( $tag->type );
43
+
44
+ $atts = array();
45
+
46
+ $atts['class'] = $tag->get_class_option( $class );
47
+ $atts['id'] = $tag->get_option( 'id', 'id', true );
48
+ $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
49
+
50
+ $value = isset( $tag->values[0] ) ? $tag->values[0] : '';
51
+ if ( empty( $value ) ) {
52
+ if ( $tag->type == 'previous') {
53
+ $value = __( 'Previous', 'cpf7msm' );
54
+ }
55
+ else {
56
+ //using old version
57
+ $value = __( 'Back', 'cpf7msm' );
58
+ }
59
+ }
60
+
61
+ $atts['type'] = 'button';
62
+ $atts['value'] = $value;
63
+
64
+ $atts = wpcf7_format_atts( $atts );
65
+
66
+ $html = sprintf( '<input %1$s />', $atts );
67
+
68
+ return $html;
69
+ }
70
+
71
+
72
+ /**
73
+ * Add to the wpcf7 tag generator.
74
+ */
75
+ function cf7msm_add_tag_generator_back() {
76
+ if ( class_exists( 'WPCF7_TagGenerator' ) ) {
77
+ $tag_generator = WPCF7_TagGenerator::get_instance();
78
+ $tag_generator->add( 'previous', __( 'previous', 'cf7msm' ), 'cf7msm_previous_tag_pane' );
79
+ }
80
+ else if ( function_exists( 'wpcf7_add_tag_generator' ) ) {
81
+ wpcf7_add_tag_generator( 'back', __( 'Back button', 'wpcf7' ),
82
+ 'wpcf7-cf7msm-back', 'wpcf7_cf7msm_back', array( 'nameless' => 1 ) );
83
+ }
84
+ }
85
+ add_action( 'admin_init', 'cf7msm_add_tag_generator_back', 30 );
86
+
87
+
88
+ add_action( 'admin_init', 'cf7msm_add_tag_generator_back', 55 );
89
+
90
+
91
+
92
+ /**
93
+ * Multistep tag pane.
94
+ */
95
+ function cf7msm_previous_tag_pane( $contact_form, $args = '' ) {
96
+
97
+ $args = wp_parse_args( $args, array() );
98
+ ?>
99
+ <div class="control-box cf7msm-multistep">
100
+ <fieldset>
101
+ <legend><?php cf7msm_form_tag_header_text( 'Generate a form-tag for a previous button for a multistep form' ); ?></legend>
102
+ <table class="form-table">
103
+ <tbody>
104
+ <tr>
105
+ <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Label', 'contact-form-7' ) ); ?></label></th>
106
+ <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" />
107
+ <label for="tag-generator-panel-previous">
108
+ <span class="description">The label on the button.</span>
109
+ </label></td>
110
+ </tr>
111
+
112
+ <tr>
113
+ <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
114
+ <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
115
+ </tr>
116
+
117
+ <tr>
118
+ <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
119
+ <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
120
+ </tr>
121
+
122
+ </tbody>
123
+ </table>
124
+ </fieldset>
125
+ </div>
126
+ <div class="insert-box">
127
+ <input type="text" name="previous" class="tag code" readonly="readonly" onfocus="this.select()" />
128
+
129
+ <div class="submitbox">
130
+ <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
131
+ </div>
132
+
133
+ <br class="clear" />
134
+
135
+ <p class="description mail-tag"><label><?php echo esc_html( __( "This field should not be used on the Mail tab.", 'contact-form-7' ) ); ?></label></p>
136
+ <?php cf7msm_form_tag_footer_text();?>
137
+ </div>
138
+ <?php
139
+ }
140
+
141
+ /**
142
+ * Deprecated way to generate back tag.
143
+ */
144
+ function wpcf7_cf7msm_back( $contact_form ) {
145
+ ?>
146
+ <div id="wpcf7-cf7msm-back" class="hidden">
147
+ <form action="">
148
+ <table>
149
+ <tr>
150
+ <td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
151
+ <input type="text" name="id" class="idvalue oneline option" /></td>
152
+
153
+ <td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
154
+ <input type="text" name="class" class="classvalue oneline option" /></td>
155
+ </tr>
156
+
157
+ <tr>
158
+ <td><?php echo esc_html( __( 'Label', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
159
+ <input type="text" name="values" class="oneline" /></td>
160
+
161
+ <td></td>
162
+ </tr>
163
+ </table>
164
+
165
+ <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="back" class="tag" readonly="readonly" onfocus="this.select()" /></div>
166
+ </form>
167
+ </div>
168
+ <?php
169
+ }
170
+
171
+ ?>
module-hidden.php → form-tags/module-hidden.php RENAMED
@@ -1,5 +1,7 @@
1
  <?php
2
  /*
 
 
3
  Included if Contact Form 7 Modules: Hidden Fields is not active.
4
 
5
  Author: Katz Web Services, Inc.
@@ -30,13 +32,6 @@ Version: 1.2.1
30
 
31
 
32
  /* Shortcode handler */
33
-
34
- add_filter('wpcf7_form_elements', 'wpcf7_form_elements_return_false');
35
- function wpcf7_form_elements_return_false($form) {
36
- $brform = preg_replace('/<p>(<input\stype="hidden"(?:.*?))<\/p>/isme', "'<div class=\'hidden\' style=\'display:none;\'>'.\"\n\".str_replace('<br>', '', str_replace('<br />', '', stripslashes_deep('\\1'))).\"\n\".'</div>'", $form);
37
- return $brform;
38
- }
39
-
40
  add_action('plugins_loaded', 'contact_form_7_hidden_fields', 10);
41
 
42
  function contact_form_7_hidden_fields() {
@@ -46,7 +41,7 @@ function contact_form_7_hidden_fields() {
46
  wpcf7_add_shortcode( 'hidden*', 'wpcf7_hidden_shortcode_handler', true );
47
  } else {
48
  if($pagenow != 'plugins.php') { return; }
49
- add_action('admin_notices', 'cfhiddenfieldserror');
50
  wp_enqueue_script('thickbox');
51
  function cfhiddenfieldserror() {
52
  $out = '<div class="error" id="messages"><p>';
@@ -68,7 +63,7 @@ function contact_form_7_hidden_fields() {
68
  /* Shortcode handler */
69
 
70
  function wpcf7_hidden_shortcode_handler( $tag ) {
71
- if ( ! is_array( $tag ) )
72
  return '';
73
 
74
  $type = $tag['type'];
@@ -146,7 +141,8 @@ function wpcf7_hidden_shortcode_handler( $tag ) {
146
 
147
  /* Tag generator */
148
 
149
- add_action( 'admin_init', 'wpcf7_add_tag_generator_hidden', 30 );
 
150
 
151
  function wpcf7_add_tag_generator_hidden() {
152
  if(function_exists('wpcf7_add_tag_generator')) {
1
  <?php
2
  /*
3
+ Deprecated as of CF7MSM 2.0. Use multistep tag instead.
4
+
5
  Included if Contact Form 7 Modules: Hidden Fields is not active.
6
 
7
  Author: Katz Web Services, Inc.
32
 
33
 
34
  /* Shortcode handler */
 
 
 
 
 
 
 
35
  add_action('plugins_loaded', 'contact_form_7_hidden_fields', 10);
36
 
37
  function contact_form_7_hidden_fields() {
41
  wpcf7_add_shortcode( 'hidden*', 'wpcf7_hidden_shortcode_handler', true );
42
  } else {
43
  if($pagenow != 'plugins.php') { return; }
44
+ //add_action('admin_notices', 'cfhiddenfieldserror');
45
  wp_enqueue_script('thickbox');
46
  function cfhiddenfieldserror() {
47
  $out = '<div class="error" id="messages"><p>';
63
  /* Shortcode handler */
64
 
65
  function wpcf7_hidden_shortcode_handler( $tag ) {
66
+ if ( ! is_array( $tag ) || !function_exists( 'wpcf7_script_is' ) )
67
  return '';
68
 
69
  $type = $tag['type'];
141
 
142
  /* Tag generator */
143
 
144
+ /* do not show hidden tag in generator. it is deprecated */
145
+ //add_action( 'admin_init', 'wpcf7_add_tag_generator_hidden', 30 );
146
 
147
  function wpcf7_add_tag_generator_hidden() {
148
  if(function_exists('wpcf7_add_tag_generator')) {
form-tags/module-multistep.php ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* Copyright 2016 Webhead LLC (email: info at webheadcoder.com)
3
+
4
+ This program is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU General Public License
6
+ as published by the Free Software Foundation; either version 2
7
+ of the License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+
18
+ */
19
+
20
+ /**
21
+ * Initialize this wpcf7 shortcode.
22
+ */
23
+ function cf7msm_add_shortcode_multistep() {
24
+ if (function_exists('wpcf7_add_shortcode')) {
25
+ wpcf7_add_shortcode(
26
+ array( 'multistep', 'multistep*' ),
27
+ 'cf7msm_multistep_shortcode_handler',
28
+ true
29
+ );
30
+ }
31
+ }
32
+ add_action( 'wpcf7_init', 'cf7msm_add_shortcode_multistep' );
33
+
34
+ /**
35
+ * Add to the wpcf7 tag generator.
36
+ */
37
+ function cf7msm_add_tag_generator_multistep() {
38
+ if ( class_exists( 'WPCF7_TagGenerator' ) ) {
39
+ $tag_generator = WPCF7_TagGenerator::get_instance();
40
+ $tag_generator->add( 'multistep', __( 'multistep', 'cf7msm' ), 'cf7msm_multistep_tag_generator' );
41
+ }
42
+ }
43
+ add_action( 'admin_init', 'cf7msm_add_tag_generator_multistep', 30 );
44
+
45
+ /**
46
+ * Handle the multistep handler
47
+ * This shortcode lets the plugin determine if the form is a multi-step form
48
+ * and if it should redirect the user to step 1.
49
+ */
50
+ function cf7msm_multistep_shortcode_handler( $tag ) {
51
+ $tag = new WPCF7_Shortcode( $tag );
52
+ $validation_error = wpcf7_get_validation_error( $tag->name );
53
+ $class = wpcf7_form_controls_class( $tag->type, 'cf7msm-multistep' );
54
+ if ( $validation_error ) {
55
+ $class .= ' wpcf7-not-valid';
56
+ }
57
+ $class .= ' cf7msm-multistep';
58
+ if ( 'multistep*' === $tag->type ) {
59
+ $class .= ' wpcf7-validates-as-required';
60
+ }
61
+ $value = (string) reset( $tag->values );
62
+
63
+ $multistep_values = cf7msm_format_multistep_value( $value );
64
+ $step_value = $multistep_values['curr_step'] . '-' . $multistep_values['total_steps'];
65
+
66
+ $atts = array(
67
+ 'type' => 'hidden',
68
+ 'class' => $tag->get_class_option( $class ),
69
+ 'value' => $step_value,
70
+ 'name' => 'step'
71
+ );
72
+ $atts = wpcf7_format_atts( $atts );
73
+ $html = sprintf( '<input %1$s />%2$s', $atts, $validation_error );
74
+
75
+ //populate rest of form in hidden tags.
76
+ $submission = WPCF7_Submission::get_instance();
77
+
78
+ //get all posted data
79
+ foreach ($_POST as $name => $value) {
80
+ //add hidden elements for any not in current form.
81
+
82
+ //if multistep posted value is greater than current step, populate elements.
83
+
84
+ //print hidden elements
85
+ }
86
+
87
+ //$wpcf7 = WPCF7_ContactForm::get_current();
88
+
89
+ return $html;
90
+ }
91
+
92
+ /**
93
+ * Multistep tag pane.
94
+ */
95
+ function cf7msm_multistep_tag_generator( $contact_form, $args = '' ) {
96
+
97
+ $args = wp_parse_args( $args, array() );
98
+ ?>
99
+ <div class="control-box cf7msm-multistep">
100
+ <fieldset>
101
+ <legend><?php cf7msm_form_tag_header_text( 'Generate a form-tag to enable a multistep form' ); ?></legend>
102
+
103
+ <table class="form-table">
104
+ <tbody>
105
+ <tr>
106
+ <th scope="row">
107
+ <?php _e('Current Step', 'cf7msm'); ?>
108
+ </th>
109
+ <td>
110
+ <input id="tag-generator-panel-current-step" type="number" name="values_current_step" class="oneline cf7msm-multistep-values" min="1" />
111
+ <label for="tag-generator-panel-current-step">
112
+ <span class="description">The current step of this multi-step form.</span>
113
+ </label>
114
+ </td>
115
+ </tr>
116
+ <tr>
117
+ <th scope="row">
118
+ <?php _e('Total Steps', 'cf7msm'); ?>
119
+ </th>
120
+ <td>
121
+ <input id="tag-generator-panel-total-steps" type="number" name="values_total_steps" class="oneline cf7msm-multistep-values" min="1" />
122
+ <label for="tag-generator-panel-total-steps">
123
+ <span class="description">The total number of steps in your multi-step form.</span>
124
+ </label>
125
+ <br>
126
+ </td>
127
+ </tr>
128
+ <tr>
129
+ <th scope="row">
130
+ <?php _e('Next Page URL', 'cf7msm'); ?>
131
+ </th>
132
+ <td>
133
+ <input id="tag-generator-panel-next-url" type="text" name="next_url" class="oneline cf7msm-multistep-values" />
134
+ <br>
135
+ <label for="tag-generator-panel-next-url">
136
+ <span class="description">The URL of the page that contains the next form. (Leave blank on last step)</span>
137
+ </label>
138
+ </td>
139
+ </tr>
140
+ </tbody>
141
+ </table>
142
+ <p class="cf7msm-faq" style="display:none;">
143
+ <strong>Warning:</strong> Your form may be at risk of being too large for this plugin. <a href="">See here for more information.</a>
144
+ </p>
145
+ </fieldset>
146
+ </div>
147
+ <div class="insert-box">
148
+ <input type="hidden" name="values" value="" />
149
+ <input type="text" name="multistep" class="tag code" readonly="readonly" onfocus="this.select()" />
150
+
151
+ <div class="submitbox">
152
+ <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
153
+ </div>
154
+
155
+ <br class="clear" />
156
+
157
+ <p class="description mail-tag"><label><?php echo esc_html( __( "This field should not be used on the Mail tab.", 'contact-form-7' ) ); ?></label>
158
+ </p>
159
+ <?php cf7msm_form_tag_footer_text();?>
160
+ </div>
161
+ <?php
162
+ }
163
+
164
+ /**
165
+ * Return the step value and next url in an array. URL may be empty.
166
+ */
167
+ function cf7msm_format_multistep_value( $valueString ) {
168
+ $no_url = false;
169
+ $next_url = '';
170
+
171
+ $i = stripos( $valueString, '-' );
172
+ $curr_step = substr( $valueString, 0, $i );
173
+ $j = stripos( $valueString, '-', $i+1 );
174
+ if ( $j === FALSE ) {
175
+ $j = strlen( $valueString );
176
+ $no_url = true;
177
+ }
178
+ $total_steps = substr( $valueString, $i+1, $j-($i+1) );
179
+ if ( !$no_url ) {
180
+ $next_url = substr( $valueString, $j+1 );
181
+ }
182
+
183
+ return array(
184
+ 'curr_step' => $curr_step,
185
+ 'total_steps' => $total_steps,
186
+ 'next_url' => $next_url
187
+ );
188
+ }
189
+
190
+ /**
191
+ * Remove br from hidden tags.
192
+ */
193
+ function wpcf7_form_elements_return_false($form) {
194
+ return preg_replace_callback('/<p>(<input\stype="hidden"(?:.*?))<\/p>/ism', 'wpcf7_form_elements_return_false_callback', $form);
195
+ }
196
+ add_filter('wpcf7_form_elements', 'wpcf7_form_elements_return_false');
197
+
198
+ function wpcf7_form_elements_return_false_callback($matches = array()) {
199
+ return "\n".'<!-- CF7 Modules -->'."\n".'<div style=\'display:none;\'>'.str_replace('<br>', '', str_replace('<br />', '', stripslashes_deep($matches[1]))).'</div>'."\n".'<!-- End CF7 Modules -->'."\n";
200
+ }
module-session.php → form-tags/module-session.php RENAMED
@@ -17,29 +17,19 @@
17
 
18
  */
19
 
20
- add_action('plugins_loaded', 'contact_form_7_form_codes', 10);
21
-
22
- function contact_form_7_form_codes() {
23
- global $pagenow;
24
- if(function_exists('wpcf7_add_shortcode')) {
25
- wpcf7_add_shortcode( 'form', 'wpcf7_form_shortcode_handler', true );
26
- wpcf7_add_shortcode( 'form*', 'wpcf7_form_shortcode_handler', true );
27
- } else {
28
- if($pagenow != 'plugins.php') { return; }
29
- add_action('admin_notices', 'cfformfieldserror');
30
- wp_enqueue_script('thickbox');
31
- function cfformfieldserror() {
32
- $out = '<div class="error" id="messages"><p>';
33
- if(file_exists(WP_PLUGIN_DIR.'/contact-form-7/wp-contact-form-7.php')) {
34
- $out .= 'The Contact Form 7 is installed, but <strong>you must activate Contact Form 7</strong> below for the [form] code to work.';
35
- } else {
36
- $out .= 'The Contact Form 7 plugin must be installed for the Form Display code to work. <a href="'.admin_url('plugin-install.php?tab=plugin-information&plugin=contact-form-7&from=plugins&TB_iframe=true&width=600&height=550').'" class="thickbox" title="Contact Form 7">Install Now.</a>';
37
- }
38
- $out .= '</p></div>';
39
- echo $out;
40
- }
41
- }
42
  }
 
43
 
44
  /* Shortcode handler */
45
 
@@ -51,7 +41,14 @@ function wpcf7_form_shortcode_handler( $tag ) {
51
  $options = (array) $tag['options'];
52
  $values = (array) $tag['values'];
53
 
54
- if ( empty( $name ) )
 
 
 
 
 
 
 
55
  return '';
56
 
57
  $atts = '';
@@ -79,22 +76,22 @@ function wpcf7_form_shortcode_handler( $tag ) {
79
  $cf7msm_posted_data = cf7msm_get('cf7msm_posted_data');
80
 
81
  if ( !empty( $cf7msm_posted_data ) && is_array( $cf7msm_posted_data ) ) {
82
- $value = isset( $cf7msm_posted_data[$name] ) ? $cf7msm_posted_data[$name] : '';
83
  //check for free_text
84
  if ( !empty( $value ) ) {
85
  // if value is selected/not empty, set it to the free_text value.
86
- if ( isset( $cf7msm_posted_data[CF7MSM_FREE_TEXT_PREFIX_RADIO . $name] ) ) {
87
- $value = $cf7msm_posted_data[CF7MSM_FREE_TEXT_PREFIX_RADIO . $name];
88
  }
89
- else if ( isset( $cf7msm_posted_data[CF7MSM_FREE_TEXT_PREFIX_CHECKBOX . $name] ) ) {
90
  if ( is_array( $value ) ) {
91
  end($value);
92
  $last_key = key( $value );
93
  reset($value);
94
- $value[$last_key] = $cf7msm_posted_data[CF7MSM_FREE_TEXT_PREFIX_CHECKBOX . $name];
95
  }
96
  else {
97
- $value = $cf7msm_posted_data[CF7MSM_FREE_TEXT_PREFIX_CHECKBOX . $name];
98
  }
99
  }
100
  }
@@ -107,18 +104,68 @@ function wpcf7_form_shortcode_handler( $tag ) {
107
  return $value;
108
  }
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
- /* Tag generator */
 
 
 
112
 
113
- add_action( 'admin_init', 'wpcf7_add_tag_generator_form', 30 );
114
 
115
- function wpcf7_add_tag_generator_form() {
116
- if(function_exists('wpcf7_add_tag_generator')) {
117
- wpcf7_add_tag_generator( 'form', __( 'Form value', 'wpcf7' ),
118
- 'wpcf7-tg-pane-form', 'wpcf7_tg_pane_form' );
119
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  }
121
 
 
 
 
122
  function wpcf7_tg_pane_form() {
123
  ?>
124
  <div id="wpcf7-tg-pane-form" class="hidden">
@@ -140,4 +187,5 @@ function wpcf7_tg_pane_form() {
140
  </div>
141
  <?php
142
  }
 
143
  ?>
17
 
18
  */
19
 
20
+ /**
21
+ * Initialize this form shortcode.
22
+ */
23
+ function cf7msm_add_shortcode_form_field() {
24
+ if ( function_exists( 'wpcf7_add_shortcode' ) ) {
25
+ wpcf7_add_shortcode(
26
+ array( 'form', 'form*', 'multiform', 'multiform*' ),
27
+ 'wpcf7_form_shortcode_handler',
28
+ true
29
+ );
30
+ }
 
 
 
 
 
 
 
 
 
 
 
31
  }
32
+ add_action( 'wpcf7_init', 'cf7msm_add_shortcode_form_field' );
33
 
34
  /* Shortcode handler */
35
 
41
  $options = (array) $tag['options'];
42
  $values = (array) $tag['values'];
43
 
44
+ if ( !empty( $values ) ) {
45
+ $field_name = current( $values );
46
+ }
47
+ else if ( !empty( $name ) ) {
48
+ $field_name = $name;
49
+ }
50
+
51
+ if ( empty( $field_name ) )
52
  return '';
53
 
54
  $atts = '';
76
  $cf7msm_posted_data = cf7msm_get('cf7msm_posted_data');
77
 
78
  if ( !empty( $cf7msm_posted_data ) && is_array( $cf7msm_posted_data ) ) {
79
+ $value = isset( $cf7msm_posted_data[$field_name] ) ? $cf7msm_posted_data[$field_name] : '';
80
  //check for free_text
81
  if ( !empty( $value ) ) {
82
  // if value is selected/not empty, set it to the free_text value.
83
+ if ( isset( $cf7msm_posted_data[CF7MSM_FREE_TEXT_PREFIX_RADIO . $field_name] ) ) {
84
+ $value = $cf7msm_posted_data[CF7MSM_FREE_TEXT_PREFIX_RADIO . $field_name];
85
  }
86
+ else if ( isset( $cf7msm_posted_data[CF7MSM_FREE_TEXT_PREFIX_CHECKBOX . $field_name] ) ) {
87
  if ( is_array( $value ) ) {
88
  end($value);
89
  $last_key = key( $value );
90
  reset($value);
91
+ $value[$last_key] = $cf7msm_posted_data[CF7MSM_FREE_TEXT_PREFIX_CHECKBOX . $field_name];
92
  }
93
  else {
94
+ $value = $cf7msm_posted_data[CF7MSM_FREE_TEXT_PREFIX_CHECKBOX . $field_name];
95
  }
96
  }
97
  }
104
  return $value;
105
  }
106
 
107
+ /**
108
+ * Add to the wpcf7 tag generator.
109
+ */
110
+ function cf7msm_add_tag_generator_form_field() {
111
+ if ( class_exists( 'WPCF7_TagGenerator' ) ) {
112
+ $tag_generator = WPCF7_TagGenerator::get_instance();
113
+ $tag_generator->add( 'form-field', __( 'form field', 'cf7msm' ), 'cf7msm_form_field_tag_pane' );
114
+ }
115
+ else if ( function_exists( 'wpcf7_add_tag_generator' ) ) {
116
+ wpcf7_add_tag_generator( 'form', __( 'Form value', 'wpcf7' ),
117
+ 'wpcf7-tg-pane-form', 'wpcf7_tg_pane_form' );
118
+ }
119
+ }
120
+ add_action( 'admin_init', 'cf7msm_add_tag_generator_form_field', 30 );
121
 
122
+ /**
123
+ * Form tag pane.
124
+ */
125
+ function cf7msm_form_field_tag_pane( $contact_form, $args = '' ) {
126
 
127
+ $args = wp_parse_args( $args, array() );
128
 
129
+ ?>
130
+ <div class="control-box cf7msm-multistep">
131
+ <fieldset>
132
+ <legend><?php cf7msm_form_tag_header_text( 'Generate a form-tag to show a field from a previous form in a multistep form' ); ?></legend>
133
+
134
+ <table class="form-table">
135
+ <tbody>
136
+ <tr>
137
+ <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
138
+ <td><input type="text" name="values" class="tg-name oneline" id="tag-generator-panel-name" />
139
+ <br>
140
+ <label for="tag-generator-panel-name">
141
+ <span class="description">The name of the field from a form in a previous step.</span>
142
+ </label>
143
+ </td>
144
+ </tr>
145
+ </tbody>
146
+ </table>
147
+ </fieldset>
148
+ </div>
149
+ <div class="insert-box">
150
+ <input type="hidden" name="values" value="" />
151
+ <input type="text" name="multiform" class="tag code" readonly="readonly" onfocus="this.select()" />
152
+
153
+ <div class="submitbox">
154
+ <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
155
+ </div>
156
+
157
+ <br class="clear" />
158
+
159
+ <p class="description mail-tag"><label><?php echo esc_html( __( "This field should not be used on the Mail tab.", 'cf7msm' ) ); ?></label>
160
+ </p>
161
+ <?php cf7msm_form_tag_footer_text();?>
162
+ </div>
163
+ <?php
164
  }
165
 
166
+ /**
167
+ * Deprecated way to generate form tag
168
+ */
169
  function wpcf7_tg_pane_form() {
170
  ?>
171
  <div id="wpcf7-tg-pane-form" class="hidden">
187
  </div>
188
  <?php
189
  }
190
+
191
  ?>
module-back.php DELETED
@@ -1,83 +0,0 @@
1
- <?php
2
- /**
3
- ** A base module for [back]
4
- **/
5
-
6
- /* Shortcode handler */
7
-
8
- add_action( 'init', 'cf7msm_add_shortcode_back' );
9
-
10
- function cf7msm_add_shortcode_back() {
11
- if (function_exists('wpcf7_add_shortcode'))
12
- wpcf7_add_shortcode( 'back', 'cf7msm_back_shortcode_handler' );
13
- }
14
-
15
- function cf7msm_back_shortcode_handler( $tag ) {
16
- if (!class_exists('WPCF7_Shortcode') || !function_exists('wpcf7_form_controls_class'))
17
- return;
18
- $tag = new WPCF7_Shortcode( $tag );
19
-
20
- $class = wpcf7_form_controls_class( $tag->type );
21
-
22
- $atts = array();
23
-
24
- $atts['class'] = $tag->get_class_option( $class );
25
- $atts['id'] = $tag->get_option( 'id', 'id', true );
26
- $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
27
-
28
- $value = isset( $tag->values[0] ) ? $tag->values[0] : '';
29
-
30
- if ( empty( $value ) )
31
- $value = __( 'Back', 'cpf7msm' );
32
-
33
- $atts['type'] = 'button';
34
- $atts['value'] = $value;
35
-
36
- $atts = wpcf7_format_atts( $atts );
37
-
38
- $html = sprintf( '<input %1$s />', $atts );
39
-
40
- return $html;
41
- }
42
-
43
-
44
- /* Tag generator */
45
-
46
- add_action( 'admin_init', 'cf7msm_add_tag_generator_back', 55 );
47
-
48
- function cf7msm_add_tag_generator_back() {
49
- if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
50
- return;
51
-
52
- wpcf7_add_tag_generator( 'back', __( 'Back button', 'wpcf7' ),
53
- 'wpcf7-cf7msm-back', 'wpcf7_cf7msm_back', array( 'nameless' => 1 ) );
54
- }
55
-
56
- function wpcf7_cf7msm_back( $contact_form ) {
57
- ?>
58
- <div id="wpcf7-cf7msm-back" class="hidden">
59
- <form action="">
60
- <table>
61
- <tr>
62
- <td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
63
- <input type="text" name="id" class="idvalue oneline option" /></td>
64
-
65
- <td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
66
- <input type="text" name="class" class="classvalue oneline option" /></td>
67
- </tr>
68
-
69
- <tr>
70
- <td><?php echo esc_html( __( 'Label', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
71
- <input type="text" name="values" class="oneline" /></td>
72
-
73
- <td></td>
74
- </tr>
75
- </table>
76
-
77
- <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="back" class="tag" readonly="readonly" onfocus="this.select()" /></div>
78
- </form>
79
- </div>
80
- <?php
81
- }
82
-
83
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,9 +1,10 @@
1
  === Plugin Name ===
2
  Contributors: webheadllc
 
3
  Tags: contact form 7, multistep form, form, multiple pages, store form
4
  Requires at least: 3.4.1
5
- Tested up to: 4.4
6
- Stable tag: 1.6
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -11,21 +12,45 @@ Enables the Contact Form 7 plugin to create multi-page, multi-step forms.
11
 
12
  == Description ==
13
 
14
- Note: If you have a caching plugin or on a host with aggressive caching (i.e. WPEngine), this plugin may not work for you. See FAQs for more details.
15
-
16
  I needed a contact form that spanned across multiple pages and in the end would send an email with all the info collected. This plugin does just that. This plugin requires the Contact Form 7 Wordpress plugin.
17
 
18
  Sample of this working is at [http://webheadcoder.com/contact-form-7-multi-step-form/](http://webheadcoder.com/contact-form-7-multi-step-form/)
19
 
20
  **Usage**
21
 
22
- I write horrible instructions, but luckily Michael at RoseAppleMedia understood it and created a great tutorial!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- [youtube https://www.youtube.com/watch?v=jlMQpwD5l1Q]
25
 
 
26
 
 
27
 
28
- Instructions:
 
 
 
 
 
 
 
29
 
30
  1. Create a contact form 7 form as you normally would.
31
 
@@ -41,33 +66,42 @@ In a contact form, to retrieve fields from previous forms you can use something
41
 
42
  In a contact form you users may want to go back to a previous step to change some info they entered. To allow the user to go back, add the `[back "Previous Step"]` button to the form.
43
 
44
- **Additional Info**
45
  The hidden field is taken directly from the "Contact Form 7 Modules". If you have that installed, the Multi-Step plugin will use that.
46
 
47
- This plugin does not support File Uploads. If you need to use file uploads make sure to place it on the last step.
48
 
49
- This plugin only works when the forms are on separate pages. Many have asked to make it load via ajax so all forms can reside on one page. This plugin does not support that. You can try it on your own, but it is harder than it seems.
50
 
51
 
52
  == Frequently Asked Questions ==
53
 
 
 
 
 
 
 
54
  = I keep getting the "Please fill out the form on the previous page" message. What's wrong? =
55
 
56
- If you have everything set up correctly and you get a message saying, "Please fill out the form on the previous page" after submitting the first form, then it's probably your caching system not allowing cookies (and possibly sessions) to be set in the normal way. No workarounds or fixes are planned at this time. (This issue can be resolved on WPEngine [http://wordpress.org/support/topic/please-fill-out-previous-form-error?replies=4](http://wordpress.org/support/topic/please-fill-out-previous-form-error?replies=4)).
57
 
58
 
59
  = How can I show a summary of what the user entered or show fields from previous steps? =
60
 
61
- As stated in the instructions: "In a contact form, to retrieve fields from previous forms you can use something like `[form your-email]` where "your-email" is the name of the field from the previous form."
62
 
 
63
 
64
- = Why aren't you answering my question? =
65
 
66
- This plugin is free for a reason. Please go through the video tutorial provided by RoseAppleMedia carefully to make sure you have the plugin set up correctly.
67
 
 
68
 
 
 
 
 
 
 
69
 
70
- == Changelog ==
71
 
72
  = 1.6 =
73
  Added support for when contact form 7 ajax is disabled.
1
  === Plugin Name ===
2
  Contributors: webheadllc
3
+ Donate Link: http://webheadcoder.com/donate-cf7-multi-step-forms
4
  Tags: contact form 7, multistep form, form, multiple pages, store form
5
  Requires at least: 3.4.1
6
+ Tested up to: 4.4.2
7
+ Stable tag: 2.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
12
 
13
  == Description ==
14
 
 
 
15
  I needed a contact form that spanned across multiple pages and in the end would send an email with all the info collected. This plugin does just that. This plugin requires the Contact Form 7 Wordpress plugin.
16
 
17
  Sample of this working is at [http://webheadcoder.com/contact-form-7-multi-step-form/](http://webheadcoder.com/contact-form-7-multi-step-form/)
18
 
19
  **Usage**
20
 
21
+ 1. Create a contact form 7 form as you normally would.
22
+
23
+ 1. Place your cursor at the end of the form.
24
+
25
+ 1. On the "Form" tab of the Contact Form 7 form, click on the button named "multistep".
26
+
27
+ 1. In the popup, type in the current step and total steps in your multi-step process. For example, if this is the first form in a total of 3 forms, type in "1" for Current Step and "3" in Total Steps.
28
+
29
+ 1. The Next Page URL is the url that contains your next form. If this form is the last step, you can leave it blank or fill it in to redirect the user to another page.
30
+
31
+ 1. Click "Insert Tag"
32
+
33
+ 1. Repeat for each form in your multi-step form process.
34
+
35
+
36
+ **Additional Tags**
37
+ `[multiform "your-name"]` - The `multiform` form-tag can be used to display a field from a previous step. Replace `your-name` with the name of your field.
38
+
39
+ `[previous "Go Back"]` - The `previous` form-tag can be used to display a button to go to a previous step. Replace `Go Back` with text you want to show in the button.
40
 
 
41
 
42
+ **What this plugin DOES NOT do:**
43
 
44
+ * This plugin does not support file uploads on every form. If you need to use file uploads make sure to place it on the last step.
45
 
46
+ * This plugin does not load another form on the same page. It only works when the forms are on separate pages. Many have asked to make it load via ajax so all forms can reside on one page. This plugin does not support that.
47
+
48
+ * This plugin does not support large forms with many steps. See [http://webheadcoder.com/too-many-cookies/](http://webheadcoder.com/too-many-cookies/) for more details and suggestions.
49
+
50
+
51
+ **pre 2.0 Instructions:**
52
+
53
+ The instructions below are only for older versions of the plugin. This is only kept here for reference and will be removed in the next release.
54
 
55
  1. Create a contact form 7 form as you normally would.
56
 
66
 
67
  In a contact form you users may want to go back to a previous step to change some info they entered. To allow the user to go back, add the `[back "Previous Step"]` button to the form.
68
 
 
69
  The hidden field is taken directly from the "Contact Form 7 Modules". If you have that installed, the Multi-Step plugin will use that.
70
 
 
71
 
 
72
 
73
 
74
  == Frequently Asked Questions ==
75
 
76
+
77
+ = Why "place your cursor at the end of the form" before inserting the multistep tag? =
78
+
79
+ The `multistep` form tag is a hidden field and tries not to add any spacing to your form. In this effort, anything directly after this tag may be hidden. To prevent this, add a carriage return after the `multistep` form tag, or just follow the directions and place the form tag at the end of the form.
80
+
81
+
82
  = I keep getting the "Please fill out the form on the previous page" message. What's wrong? =
83
 
84
+ If you have everything set up correctly and you get a message saying, "Please fill out the form on the previous page" after submitting the first form, then it's probably your caching system not allowing cookies to be set in the normal way. No workarounds or fixes are planned at this time. You will need to turn off caching for the affected pages.
85
 
86
 
87
  = How can I show a summary of what the user entered or show fields from previous steps? =
88
 
89
+ `[multiform "your-name"]` - The multiform form-tag can be used to display a field from a previous step. Replace `your-name` with the name of your field.
90
 
91
+ = My form values aren't being sent in the email. I get [multiform "your-name"] instead of the actual person's name. =
92
 
93
+ The multiform form-tag should only be used on the Form tab. On the Mail tab follow the instructions from the Contact Fom 7 documentation. So if you wanted to show the `your-name` field, type `[your-name]`.
94
 
 
95
 
96
+ == Changelog ==
97
 
98
+ = 2.0 =
99
+ Added Form Tags to Form Tag Generator. No more needing to update the Additional Settings tab.
100
+ Added error alert when form is too large.
101
+ Fixed Deprecated: preg_replace() error message.
102
+ Fixed certain instances where the "Please fill out the form on the previous page" messages displayed unexpectedly.
103
+ Fixed issue where it was possible to type in the url of the next step after receiving validation errors on the current step.
104
 
 
105
 
106
  = 1.6 =
107
  Added support for when contact form 7 ajax is disabled.
resources/cf7msm.js CHANGED
@@ -6,7 +6,7 @@ jQuery(document).ready(function($) {
6
  var cf7_form = $(step_field[0].form);
7
  $.each(cf7msm_posted_data, function(key, val){
8
  if (key == 'cf7msm_prev_urls') {
9
- cf7_form.find('.wpcf7-back').click(function(e) {
10
  window.location.href = val[step_field.val()];
11
  e.preventDefault();
12
  });
6
  var cf7_form = $(step_field[0].form);
7
  $.each(cf7msm_posted_data, function(key, val){
8
  if (key == 'cf7msm_prev_urls') {
9
+ cf7_form.find('.wpcf7-back, .wpcf7-previous').click(function(e) {
10
  window.location.href = val[step_field.val()];
11
  e.preventDefault();
12
  });
resources/logo.png ADDED
Binary file