Contact Form 7 Multi-Step Forms - Version 2.2

Version Description

Contact From 7 version 4.8 or above is required for this version.
fixed back button not working when using with Contact Form 7 version 4.8.
fixed fields from previous steps not showing up when using with Contact Form 7 version 4.8.
Thanks to @eddraw, updated deprecated functions.

Download this release

Release Info

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

Code changes from version 2.1 to 2.2

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: 2.1
9
  */
10
  /* Copyright 2012 Webhead LLC (email: info at webheadcoder.com)
11
 
@@ -24,7 +24,7 @@ Version: 2.1
24
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
  */
26
 
27
- define( 'CF7MSM_VERSION', '2.1' );
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_' );
@@ -48,16 +48,28 @@ require_once(plugin_dir_path(CF7MSM_PLUGIN) . 'form-tags/module-back.php');
48
  */
49
  function contact_form_7_form_codes() {
50
  global $pagenow;
51
- if ( $pagenow != 'plugins.php' || defined( 'WPCF7_PLUGIN' ) )
52
  return;
 
 
 
 
 
 
53
  add_action('admin_notices', 'cfformfieldserror');
54
  wp_enqueue_script('thickbox');
55
  function cfformfieldserror() {
56
  $out = '<div class="error" id="messages"><p>';
57
- if(file_exists(WP_PLUGIN_DIR.'/contact-form-7/wp-contact-form-7.php')) {
58
- $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.';
59
- } else {
60
- $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>';
 
 
 
 
 
 
61
  }
62
  $out .= '</p></div>';
63
  echo $out;
@@ -89,25 +101,6 @@ function cf7msm_admin_enqueue_scripts( $hook_suffix ) {
89
  }
90
  add_action( 'admin_enqueue_scripts', 'cf7msm_admin_enqueue_scripts' );
91
 
92
- /**
93
- * Load modules after plugins loaded to check for hidden module.
94
- */
95
- function cf7msm_load_modules() {
96
- if( version_compare( WPCF7_VERSION, '4.6' , '>=' ) ) {
97
- // cf7 4.6 has hidden field implemented.
98
- return;
99
- }
100
- $active_plugins = get_option( 'active_plugins', array() );
101
- if (!in_array('contact-form-7-modules/hidden.php', $active_plugins) && !in_array('contact-form-7-3rd-party-integration/hidden.php', $active_plugins)) {
102
- //hack to let contact-form-7-modules be activated.
103
- //next time require it to be activated instead of copying it in!
104
- if (!is_admin() || !isset($_GET['action']) || $_GET['action'] != 'activate' ) {
105
- require_once(plugin_dir_path(CF7MSM_PLUGIN) . 'form-tags/module-hidden.php');
106
- }
107
- }
108
- }
109
- add_action('plugins_loaded', 'cf7msm_load_modules', 2);
110
-
111
  /**
112
  * init_sessions()
113
  *
@@ -234,9 +227,6 @@ function cf7msm_step_2($cf7) {
234
  $cf7->form = apply_filters('wh_hide_cf7_step_message', __( 'Please fill out the form on the previous page', 'contact-form-7-multi-step-module' ), $form_id );
235
  }
236
  }
237
- if (count($matches) >= 3 && $matches[1] != $matches[2]) {
238
- add_filter('wpcf7_ajax_json_echo', 'cf7msm_clear_success_message', 10, 2);
239
- }
240
  }
241
 
242
  return $cf7;
@@ -277,7 +267,7 @@ function cf7msm_store_data_steps_filter( $cf7_posted_data ) {
277
  $prev_data = array();
278
  }
279
  //remove empty [form] tags from posted_data so $prev_data can be stored.
280
- $fes = wpcf7_scan_shortcode();
281
  foreach ( $fes as $fe ) {
282
  if ( empty( $fe['name'] ) || ( $fe['type'] != 'form' && $fe['type'] != 'multiform' ) )
283
  continue;
@@ -299,8 +289,6 @@ function cf7msm_store_data_steps_filter( $cf7_posted_data ) {
299
  }
300
  }
301
  if ($curr_step != $last_step) {
302
- $wpcf7 = WPCF7_ContactForm::get_current();
303
- $wpcf7->skip_mail = true;
304
  $posted_data = array_merge($prev_data, $cf7_posted_data);
305
  cf7msm_set('cf7msm_posted_data', $posted_data );
306
  }
@@ -312,6 +300,26 @@ function cf7msm_store_data_steps_filter( $cf7_posted_data ) {
312
  }
313
  add_filter( 'wpcf7_posted_data', 'cf7msm_store_data_steps_filter', 9 );
314
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  /**
316
  * Sets the current step if valid.
317
  */
@@ -381,23 +389,6 @@ function cf7msm_mail_sent() {
381
  }
382
  add_action( 'wpcf7_mail_sent', 'cf7msm_mail_sent' );
383
 
384
- /**
385
- * Fabricate additional_settings if this is a multistep form and on_sent_ok not set.
386
- */
387
- function fabricate_additional_settings( $wpcf7 ) {
388
- $on_sent_ok = $wpcf7->additional_setting( 'on_sent_ok', false );
389
- if ( empty( $on_sent_ok ) ) {
390
- $redirect_url = parse_form_for_multistep_url( $wpcf7 );
391
- $redirect_url = apply_filters( 'cf7msm_redirect_url', $redirect_url, $wpcf7->id() );
392
- if ( !empty( $redirect_url ) ) {
393
- $properties = $wpcf7->get_properties();
394
- $properties['additional_settings'] .= "\non_sent_ok: \"location.replace('" . esc_url( $redirect_url ) . "');\"
395
- ";
396
- $wpcf7->set_properties( $properties );
397
- }
398
- }
399
- }
400
-
401
  /**
402
  * Go through a wpcf7 form's formstring and find the multistep url.
403
  */
@@ -408,6 +399,7 @@ function parse_form_for_multistep_url( $wpcf7 ) {
408
  return $matches[3];
409
  }
410
  }
 
411
  }
412
 
413
  /**
@@ -450,42 +442,44 @@ function cf7msm_form_tag_footer_text() {
450
  <?php
451
  }
452
 
453
- /************************************************************************************************************
454
- * Contact Form 7 has a nice success message after submitting its forms, but on a multi-step form,
455
- * this can cause confusion if it shows and the page immediately leaves to the next page.
456
- * The functions below hide the success messages on multi-step forms.
457
- ************************************************************************************************************/
458
-
459
  /**
460
- * Hide success message if form is redirecting to another page.
461
  */
462
- function cf7msm_clear_success_message($items, $result) {
463
- remove_filter('wpcf7_ajax_json_echo', 'cf7msm_clear_success_message');
464
- if ($items['mailSent'] && isset($items['onSentOk']) && count($items['onSentOk']) > 0) {
465
- $items['onSentOk'][] = "$('" . $items['into'] . "').find('div.wpcf7-response-output').css('opacity',0);";
466
  }
467
- return $items;
468
- }
469
-
470
- /**
471
- * Hide form when done.
472
- */
473
- function cf7msm_hide_multistep_form($items, $result) {
474
- remove_filter('wpcf7_ajax_json_echo', 'cf7msm_hide_multistep_form');
475
- if ($items['mailSent'] && !isset($items['onSentOk'])) {
476
- $items['onSentOk'] = array("$('" . $items['into'] . " form').children().not('div.wpcf7-response-output').hide();");
477
  }
478
- return $items;
479
- }
480
 
481
- /**
482
- * Add filter to clear form if this is a multistep form.
483
- */
484
- function cf7msm_cf7_before_mail( $wpcf7 ) {
485
- fabricate_additional_settings( $wpcf7 );
486
- $step = cf7msm_get('step');
487
- if ( !empty( $step ) ) {
488
- add_filter('wpcf7_ajax_json_echo', 'cf7msm_hide_multistep_form', 10, 2);
 
 
 
 
 
 
 
 
489
  }
 
 
 
 
 
 
 
490
  }
491
- add_action( 'wpcf7_before_send_mail', 'cf7msm_cf7_before_mail', 8 );
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.2
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.2' );
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_' );
48
  */
49
  function contact_form_7_form_codes() {
50
  global $pagenow;
51
+ if ( $pagenow != 'plugins.php' )
52
  return;
53
+
54
+ $min_cf7_version = '4.7';
55
+
56
+ if ( defined( 'WPCF7_VERSION' ) && version_compare( WPCF7_VERSION, $min_cf7_version ) >= 0 ) {
57
+ return;
58
+ }
59
  add_action('admin_notices', 'cfformfieldserror');
60
  wp_enqueue_script('thickbox');
61
  function cfformfieldserror() {
62
  $out = '<div class="error" id="messages"><p>';
63
+ if ( defined( 'WPCF7_VERSION' ) && version_compare( WPCF7_VERSION, $min_cf7_version ) < 0 ) {
64
+ $out .= 'Please update the Contact Form 7 plugin. Contact Form 7 Multi-Step Form plugin requires Contact Form 7 version ' . $min_cf7_version . ' or above.';
65
+ }
66
+ else {
67
+ if(file_exists(WP_PLUGIN_DIR.'/contact-form-7/wp-contact-form-7.php')) {
68
+ $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.';
69
+ } else {
70
+ $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>';
71
+ }
72
+
73
  }
74
  $out .= '</p></div>';
75
  echo $out;
101
  }
102
  add_action( 'admin_enqueue_scripts', 'cf7msm_admin_enqueue_scripts' );
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  /**
105
  * init_sessions()
106
  *
227
  $cf7->form = apply_filters('wh_hide_cf7_step_message', __( 'Please fill out the form on the previous page', 'contact-form-7-multi-step-module' ), $form_id );
228
  }
229
  }
 
 
 
230
  }
231
 
232
  return $cf7;
267
  $prev_data = array();
268
  }
269
  //remove empty [form] tags from posted_data so $prev_data can be stored.
270
+ $fes = wpcf7_scan_form_tags();
271
  foreach ( $fes as $fe ) {
272
  if ( empty( $fe['name'] ) || ( $fe['type'] != 'form' && $fe['type'] != 'multiform' ) )
273
  continue;
289
  }
290
  }
291
  if ($curr_step != $last_step) {
 
 
292
  $posted_data = array_merge($prev_data, $cf7_posted_data);
293
  cf7msm_set('cf7msm_posted_data', $posted_data );
294
  }
300
  }
301
  add_filter( 'wpcf7_posted_data', 'cf7msm_store_data_steps_filter', 9 );
302
 
303
+ /**
304
+ * Skip sending the mail if this is a multi step form and not the last step.
305
+ */
306
+ function cf7msm_skip_send_mail( $skip_mail, $wpcf7 ) {
307
+ $tags = $wpcf7->scan_form_tags( array( 'type' => 'multistep' ) );
308
+ //if (isset($cf7_posted_data['step'])) {
309
+ if ( !empty( $tags ) ) {
310
+ $tag = current( $tags );
311
+ if ( preg_match('/(\d+)-(\d+)/', current( $tag['raw_values'] ), $matches) ) {
312
+ $curr_step = $matches[1];
313
+ $last_step = $matches[2];
314
+ }
315
+ if ($curr_step != $last_step) {
316
+ $skip_mail = true;
317
+ }
318
+ }
319
+ return $skip_mail;
320
+ }
321
+ add_filter( 'wpcf7_skip_mail', 'cf7msm_skip_send_mail', 10, 2 );
322
+
323
  /**
324
  * Sets the current step if valid.
325
  */
389
  }
390
  add_action( 'wpcf7_mail_sent', 'cf7msm_mail_sent' );
391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392
  /**
393
  * Go through a wpcf7 form's formstring and find the multistep url.
394
  */
399
  return $matches[3];
400
  }
401
  }
402
+ return '';
403
  }
404
 
405
  /**
442
  <?php
443
  }
444
 
 
 
 
 
 
 
445
  /**
446
+ *
447
  */
448
+ function cf7msm_setup_next_url($not_used) {
449
+ global $cf7msm_redirect_urls;
450
+ if ( empty( $cf7msm_redirect_urls ) ) {
451
+ $cf7msm_redirect_urls = array();
452
  }
453
+ $wpcf7 = WPCF7_ContactForm::get_current();
454
+ $redirect_url = parse_form_for_multistep_url( $wpcf7 );
455
+ $redirect_url = apply_filters( 'cf7msm_redirect_url', $redirect_url, $wpcf7->id() );
456
+ if ( !empty( $redirect_url ) ) {
457
+ $cf7msm_redirect_urls[$wpcf7->id()] = $redirect_url;
 
 
 
 
 
458
  }
 
 
459
 
460
+ return $not_used;
461
+ }
462
+ add_filter( 'wpcf7_form_action_url', 'cf7msm_setup_next_url' );
463
+
464
+ /**
465
+ * Set event listener instead of using soon to be removed onSentOk.
466
+ */
467
+ function cf7msm_footer() {
468
+ global $cf7msm_redirect_urls;
469
+ $js = '';
470
+ if ( !empty( $cf7msm_redirect_urls ) ) {
471
+ foreach( $cf7msm_redirect_urls as $id => $url ) {
472
+ $js .= 'if ( event.detail.contactFormId === "' . $id . '") { ';
473
+ $js .= sprintf('location.replace("%1$s");', esc_url( $url ) );
474
+ $js .= '}';
475
+ }
476
  }
477
+ ?>
478
+ <script type="text/javascript">
479
+ document.addEventListener( 'wpcf7mailsent', function( event ) {
480
+ <?php echo $js; ?>
481
+ }, false );
482
+ </script>
483
+ <?php
484
  }
485
+ add_action( 'wp_footer', 'cf7msm_footer', 90 );
form-tags/module-back.php CHANGED
@@ -40,9 +40,9 @@ add_action( 'wpcf7_init', 'cf7msm_add_shortcode_back' );
40
  * Handle the back form shortcode.
41
  */
42
  function cf7msm_back_shortcode_handler( $tag ) {
43
- if (!class_exists('WPCF7_Shortcode') || !function_exists('wpcf7_form_controls_class'))
44
  return;
45
- $tag = new WPCF7_Shortcode( $tag );
46
 
47
  $class = wpcf7_form_controls_class( $tag->type );
48
 
40
  * Handle the back form shortcode.
41
  */
42
  function cf7msm_back_shortcode_handler( $tag ) {
43
+ if (!class_exists('WPCF7_FormTag') || !function_exists('wpcf7_form_controls_class'))
44
  return;
45
+ $tag = new WPCF7_FormTag( $tag );
46
 
47
  $class = wpcf7_form_controls_class( $tag->type );
48
 
form-tags/module-hidden.php DELETED
@@ -1,188 +0,0 @@
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.
8
- Author URI: http://www.katzwebservices.com
9
- Version: 1.2.1
10
- */
11
-
12
- /* Copyright 2011 Katz Web Services, Inc. (email: info at katzwebservices.com)
13
-
14
- This program is free software; you can redistribute it and/or modify
15
- it under the terms of the GNU General Public License as published by
16
- the Free Software Foundation; either version 2 of the License, or
17
- (at your option) any later version.
18
-
19
- This program is distributed in the hope that it will be useful,
20
- but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
- GNU General Public License for more details.
23
-
24
- You should have received a copy of the GNU General Public License
25
- along with this program; if not, write to the Free Software
26
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
- */
28
-
29
- /**
30
- ** A base module for [hidden] and [hidden*]
31
- **/
32
-
33
-
34
- /* Shortcode handler */
35
- add_action('plugins_loaded', 'contact_form_7_hidden_fields', 10);
36
-
37
- function contact_form_7_hidden_fields() {
38
- global $pagenow;
39
- if (function_exists( 'wpcf7_add_form_tag' ) ) {
40
- wpcf7_add_form_tag( 'hidden', 'wpcf7_hidden_shortcode_handler', true );
41
- wpcf7_add_form_tag( 'hidden*', 'wpcf7_hidden_shortcode_handler', true );
42
- }
43
- else if(function_exists('wpcf7_add_shortcode')) {
44
- wpcf7_add_shortcode( 'hidden', 'wpcf7_hidden_shortcode_handler', true );
45
- wpcf7_add_shortcode( 'hidden*', 'wpcf7_hidden_shortcode_handler', true );
46
- }
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>';
53
- if(file_exists(WP_PLUGIN_DIR.'/contact-form-7/wp-contact-form-7.php')) {
54
- $out .= 'The Contact Form 7 is installed, but <strong>you must activate Contact Form 7</strong> below for the Hidden Fields Module to work.';
55
- } else {
56
- $out .= 'The Contact Form 7 plugin must be installed for the Hidden Fields Module 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>';
57
- }
58
- $out .= '</p></div>';
59
- echo $out;
60
- }
61
- }
62
- }
63
-
64
- /**
65
- ** A base module for [hidden], [hidden*]
66
- **/
67
-
68
- /* Shortcode handler */
69
-
70
- function wpcf7_hidden_shortcode_handler( $tag ) {
71
- if ( ! is_array( $tag ) || !function_exists( 'wpcf7_script_is' ) )
72
- return '';
73
-
74
- $type = $tag['type'];
75
- $name = $tag['name'];
76
- $options = (array) $tag['options'];
77
- $values = (array) $tag['values'];
78
-
79
- if ( empty( $name ) )
80
- return '';
81
-
82
- $atts = '';
83
- $id_att = '';
84
- $class_att = '';
85
- $size_att = '';
86
- $maxlength_att = '';
87
- $tabindex_att = '';
88
- $title_att = '';
89
-
90
- $class_att .= ' wpcf7-hidden';
91
-
92
- if ( 'hidden*' == $type )
93
- $class_att .= ' wpcf7-validates-as-required';
94
-
95
- foreach ( $options as $option ) {
96
- if ( preg_match( '%^id:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
97
- $id_att = $matches[1];
98
-
99
- } elseif ( preg_match( '%^class:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
100
- $class_att .= ' ' . $matches[1];
101
- }
102
- }
103
-
104
- $value = (string) reset( $values );
105
-
106
- if ( wpcf7_script_is() && $value && preg_grep( '%^watermark$%', $options ) ) {
107
- $class_att .= ' wpcf7-use-title-as-watermark';
108
- $title_att .= sprintf( ' %s', $value );
109
- $value = '';
110
- }
111
-
112
- if ( wpcf7_is_posted() )
113
- $value = stripslashes_deep( $_POST[$name] );
114
-
115
- if ( $id_att ) {
116
- $id_att = trim( $id_att );
117
- $atts .= ' id="' . trim( $id_att ) . '"';
118
- }
119
- if ( $class_att )
120
- $atts .= ' class="' . trim( $class_att ) . '"';
121
-
122
- global $post;
123
- if(is_object($post)) {
124
- if (strtolower($value) == 'post_title' || strtolower($value) == 'post-title') { $value = $post->post_title; }
125
- if (strtolower($value) == 'post_url') { $value = $post->guid; }
126
- if (strtolower($value) == 'post_category') {
127
- $categories = get_the_category();$catnames = array();
128
- foreach($categories as $cat) { $catnames[] = $cat->cat_name; }
129
- if(is_array($catnames)) { $value = implode(', ', $catnames); }
130
- }
131
- if (strtolower($value) == 'post_author') { $value = $post->post_author; }
132
- if (strtolower($value) == 'post_date') { $value = $post->post_date; }
133
- if (preg_match('/^custom_field\-(.*?)$/ism', $value)) {
134
- $custom_field = preg_replace('/custom_field\-(.*?)/ism', '$1', $value);
135
- $value = get_post_meta($post->ID, $custom_field, true) ? get_post_meta($post->ID, $custom_field, true) : '';
136
- }
137
- }
138
-
139
- $value = apply_filters('wpcf7_hidden_field_value', apply_filters('wpcf7_hidden_field_value_'.$id_att, $value));
140
-
141
- $html = '<input type="hidden" name="' . $name . '" value="' . esc_attr( $value ) . '"' . $atts . ' />';
142
-
143
- return $html;
144
- }
145
-
146
-
147
- /* Tag generator */
148
-
149
- /* do not show hidden tag in generator. it is deprecated */
150
- //add_action( 'admin_init', 'wpcf7_add_tag_generator_hidden', 30 );
151
-
152
- function wpcf7_add_tag_generator_hidden() {
153
- if(function_exists('wpcf7_add_tag_generator')) {
154
- wpcf7_add_tag_generator( 'hidden', __( 'Hidden field', 'wpcf7' ),
155
- 'wpcf7-tg-pane-hidden', 'wpcf7_tg_pane_hidden' );
156
- }
157
- }
158
-
159
- function wpcf7_tg_pane_hidden() {
160
- ?>
161
- <div id="wpcf7-tg-pane-hidden" class="hidden">
162
- <form action="">
163
-
164
- <table>
165
- <tr><td><?php echo esc_html( __( 'Name', 'wpcf7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
166
-
167
- <tr>
168
- <td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
169
- <input type="text" name="id" class="idvalue oneline option" /></td>
170
- </tr>
171
-
172
- <tr>
173
- <td><?php echo esc_html( __( 'Default value', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /><input type="text" name="values" class="oneline" /></td>
174
-
175
- <td>
176
- <br /><input type="checkbox" name="watermark" class="option" />&nbsp;<?php echo esc_html( __( 'Use this text as watermark?', 'wpcf7' ) ); ?>
177
- </td>
178
- </tr>
179
- </table>
180
-
181
- <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="hidden" class="tag" readonly="readonly" onfocus="this.select()" /></div>
182
-
183
- <div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code into the Mail fields below.", 'wpcf7' ) ); ?><br /><span class="arrow">&#11015;</span>&nbsp;<input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" /></div>
184
- </form>
185
- </div>
186
- <?php
187
- }
188
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
form-tags/module-multistep.php CHANGED
@@ -34,7 +34,7 @@ function cf7msm_add_shortcode_multistep() {
34
  'cf7msm_multistep_shortcode_handler',
35
  true
36
  );
37
- }
38
  }
39
  add_action( 'wpcf7_init', 'cf7msm_add_shortcode_multistep' );
40
 
@@ -55,7 +55,7 @@ add_action( 'admin_init', 'cf7msm_add_tag_generator_multistep', 30 );
55
  * and if it should redirect the user to step 1.
56
  */
57
  function cf7msm_multistep_shortcode_handler( $tag ) {
58
- $tag = new WPCF7_Shortcode( $tag );
59
  $validation_error = wpcf7_get_validation_error( $tag->name );
60
  $class = wpcf7_form_controls_class( $tag->type, 'cf7msm-multistep' );
61
  if ( $validation_error ) {
34
  'cf7msm_multistep_shortcode_handler',
35
  true
36
  );
37
+ }
38
  }
39
  add_action( 'wpcf7_init', 'cf7msm_add_shortcode_multistep' );
40
 
55
  * and if it should redirect the user to step 1.
56
  */
57
  function cf7msm_multistep_shortcode_handler( $tag ) {
58
+ $tag = new WPCF7_FormTag( $tag );
59
  $validation_error = wpcf7_get_validation_error( $tag->name );
60
  $class = wpcf7_form_controls_class( $tag->type, 'cf7msm-multistep' );
61
  if ( $validation_error ) {
form-tags/module-session.php CHANGED
@@ -42,8 +42,6 @@ add_action( 'wpcf7_init', 'cf7msm_add_shortcode_form_field' );
42
  /* Shortcode handler */
43
 
44
  function cf7msm_multiform_shortcode_handler( $tag ) {
45
- if ( ! is_array( $tag ) )
46
- return '';
47
  $type = $tag['type'];
48
  $name = $tag['name'];
49
  $options = (array) $tag['options'];
42
  /* Shortcode handler */
43
 
44
  function cf7msm_multiform_shortcode_handler( $tag ) {
 
 
45
  $type = $tag['type'];
46
  $name = $tag['name'];
47
  $options = (array) $tag['options'];
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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, contact, multi, step
5
  Requires at least: 4.5
6
- Tested up to: 4.7.2
7
- Stable tag: 2.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -16,6 +16,8 @@ I needed a contact form that spanned across multiple pages and in the end would
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 one page or post for each step in your multi-step form process. If you have 3 steps, create 3 pages/posts. You will need the urls to these when creating your forms.
@@ -98,6 +100,12 @@ The `multistep` form tag is a hidden field and tries not to add any spacing to y
98
 
99
  == Changelog ==
100
 
 
 
 
 
 
 
101
  = 2.1 =
102
  Use Contact Form 7's built-in hidden form tag if version 4.6 or above is present.
103
 
3
  Donate Link: http://webheadcoder.com/donate-cf7-multi-step-forms
4
  Tags: contact form 7, multistep form, form, multiple pages, store form, contact, multi, step
5
  Requires at least: 4.5
6
+ Tested up to: 4.8
7
+ Stable tag: 2.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
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
+ Requires Contact Form 7 version 4.8 or above.
20
+
21
  **Usage**
22
 
23
  1. Create one page or post for each step in your multi-step form process. If you have 3 steps, create 3 pages/posts. You will need the urls to these when creating your forms.
100
 
101
  == Changelog ==
102
 
103
+ = 2.2 =
104
+ **Contact From 7 version 4.8 or above is required for this version**.
105
+ fixed back button not working when using with Contact Form 7 version 4.8.
106
+ fixed fields from previous steps not showing up when using with Contact Form 7 version 4.8.
107
+ Thanks to @eddraw, updated deprecated functions.
108
+
109
  = 2.1 =
110
  Use Contact Form 7's built-in hidden form tag if version 4.6 or above is present.
111
 
resources/cf7msm.js CHANGED
@@ -1,16 +1,42 @@
 
1
  jQuery(document).ready(function($) {
2
- if (cf7msm_posted_data) {
 
 
 
3
  var step_field = $("input[name='step']");
4
  //multi step forms
5
  if (step_field.length > 0) {
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
  });
13
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  if ( ( key.indexOf('_') != 0 || key.indexOf('_wpcf7_radio_free_text_') == 0 || key.indexOf('_wpcf7_checkbox_free_text_') == 0 ) && key != 'step') {
15
  var field = cf7_form.find('*[name="' + key + '"]');
16
  if (field.length > 0) {
@@ -36,4 +62,119 @@ jQuery(document).ready(function($) {
36
  });
37
  } //end multi step forms
38
  }
39
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var cf7msm_ls;
2
  jQuery(document).ready(function($) {
3
+ var posted_data = cf7msm_posted_data;
4
+ if ( cf7msm_hasLs() ) {
5
+ cf7msm_ls = localStorage.getObject( 'cf7msm' );
6
+
7
  var step_field = $("input[name='step']");
8
  //multi step forms
9
  if (step_field.length > 0) {
10
  var cf7_form = $(step_field[0].form);
11
+ $.each(cf7msm_ls, function(key, val){
12
  if (key == 'cf7msm_prev_urls') {
13
  cf7_form.find('.wpcf7-back, .wpcf7-previous').click(function(e) {
14
  window.location.href = val[step_field.val()];
15
  e.preventDefault();
16
  });
17
  }
18
+ });
19
+ }
20
+ /*
21
+ //cf7msm3
22
+ posted_data = cf7msm_ls;
23
+ */
24
+ }
25
+ if (posted_data) {
26
+ var step_field = $("input[name='step']");
27
+ //multi step forms
28
+ if (step_field.length > 0) {
29
+ var cf7_form = $(step_field[0].form);
30
+ $.each(posted_data, function(key, val){
31
+ /*
32
+ //cf7msm3
33
+ if (key == 'cf7msm_prev_urls') {
34
+ cf7_form.find('.wpcf7-back, .wpcf7-previous').click(function(e) {
35
+ window.location.href = val[step_field.val()];
36
+ e.preventDefault();
37
+ });
38
+ }
39
+ */
40
  if ( ( key.indexOf('_') != 0 || key.indexOf('_wpcf7_radio_free_text_') == 0 || key.indexOf('_wpcf7_checkbox_free_text_') == 0 ) && key != 'step') {
41
  var field = cf7_form.find('*[name="' + key + '"]');
42
  if (field.length > 0) {
62
  });
63
  } //end multi step forms
64
  }
65
+
66
+ document.addEventListener( 'wpcf7mailsent', function( e ) {
67
+ if ( cf7msm_hasLs() ) {
68
+ var currStep = 0;
69
+ var names = [];
70
+ var currentInputs = {};
71
+ cf7msm_ls = localStorage.getObject('cf7msm');
72
+ if ( !cf7msm_ls ) {
73
+ cf7msm_ls = {};
74
+ }
75
+ $.each(e.detail.inputs, function(i){
76
+ var name = e.detail.inputs[i].name;
77
+ var value = e.detail.inputs[i].value;
78
+
79
+ //make it compatible with cookie version
80
+ if ( name.indexOf('[]') === name.length - 2 ) {
81
+ name = name.substring(0, name.length - 2 );
82
+ if ( $.inArray(name, names) === -1 ) {
83
+ currentInputs[name] = [];
84
+ }
85
+ currentInputs[name].push(value);
86
+ }
87
+ else {
88
+ currentInputs[name] = value;
89
+ }
90
+
91
+ //figure out prev url
92
+ if ( name === 'step' ) {
93
+ if ( value.indexOf("-") !== -1 ) {
94
+ var steps_prev_urls = {};
95
+ if ( cf7msm_ls && cf7msm_ls.steps_prev_urls ) {
96
+ steps_prev_urls = cf7msm_ls.cf7msm_prev_urls;
97
+ }
98
+ var stepParts = value.split('-');
99
+ currStep = parseInt( stepParts[0] );
100
+ var totalSteps = parseInt( stepParts[1] );
101
+ nextUrl = stepParts[2];
102
+ if ( currStep < totalSteps ) {
103
+ //is this the best way to get current url?
104
+ var nextStep = (1+parseInt(currStep)) + '-' + totalSteps;
105
+ steps_prev_urls[nextStep] = window.location.href;
106
+ // hide the success messages on multi-step forms
107
+ $('#' + event.detail.unitTag).find('div.wpcf7-mail-sent-ok').remove();
108
+ }
109
+ else if ( currStep === totalSteps ) {
110
+ // hide the form on final multi-step form
111
+ $(event.detail.unitTag + ' form').children().not('div.wpcf7-response-output').hide();
112
+ }
113
+ cf7msm_ls.cf7msm_prev_urls = steps_prev_urls;
114
+ }
115
+ }
116
+ else {
117
+ names.push(name);
118
+ }
119
+ });
120
+ /*
121
+ //cf7msm3
122
+ if ( currStep != 0 ) {
123
+ //this is a cf7msm form.
124
+ if ( cf7msm['step-' + currStep + '-names'] ) {
125
+ //clear past inputs for checkboxes
126
+ var pastInputNames = cf7msm['step-' + currStep + '-names'];
127
+ $.each(pastInputNames, function(i){
128
+ var name = pastInputNames[i];
129
+ delete cf7msm[name];
130
+ });
131
+ names = cf7msm_uniqueArray(cf7msm['step-' + currStep + '-names'], names);
132
+ }
133
+ //populate current
134
+ $.each(currentInputs, function(name, value){
135
+ cf7msm[name] = value;
136
+ });
137
+ cf7msm['step-' + currStep + '-names'] = names;
138
+ localStorage.setObject( 'cf7msm', cf7msm );
139
+ }
140
+ */
141
+ localStorage.setObject('cf7msm', cf7msm_ls);
142
+ }
143
+ }, false );
144
+ });
145
+
146
+ /**
147
+ * Given 2 arrays, return a unique array
148
+ * https://codegolf.stackexchange.com/questions/17127/array-merge-without-duplicates
149
+ */
150
+ function cf7msm_uniqueArray(i,x) {
151
+ h = {}
152
+ n = []
153
+ for (a = 2; a--; i=x)
154
+ i.map(function(b){
155
+ h[b] = h[b] || n.push(b)
156
+ })
157
+ return n
158
+ }
159
+
160
+ /**
161
+ * check if local storage is usable.
162
+ */
163
+ function cf7msm_hasLs() {
164
+ var test = 'test';
165
+ try {
166
+ localStorage.setItem(test, test);
167
+ localStorage.removeItem(test);
168
+ return true;
169
+ } catch(e) {
170
+ return false;
171
+ }
172
+ }
173
+ Storage.prototype.setObject = function(key, value) {
174
+ this.setItem(key, JSON.stringify(value));
175
+ }
176
+
177
+ Storage.prototype.getObject = function(key) {
178
+ var value = this.getItem(key);
179
+ return value && JSON.parse(value);
180
+ }