Contact Form 7 Multi-Step Forms - Version 1.4

Version Description

Updated to be compatible with Contact Form 7 version 3.9.

Download this release

Release Info

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

Code changes from version 1.3.6 to 1.4

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.3.6
9
  */
10
  /* Copyright 2012 Webhead LLC (email: info at webheadcoder.com)
11
 
@@ -63,6 +63,20 @@ function cf7msm_init_sessions() {
63
  }
64
  add_action('init', 'cf7msm_init_sessions');
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  /**
68
  * Add scripts to be able to go back to a previous step.
@@ -137,14 +151,27 @@ function cf7msm_remove($var_name) {
137
  * If it's not the first step, make sure it's the next form in the steps.
138
  */
139
  function cf7msm_step_2($cf7) {
140
- $formstring = $cf7->form;
 
 
 
 
 
 
141
  //check if form has a step field
142
  if (!is_admin() && preg_match('/\[hidden step "(\d+)-(\d+)"\]/', $formstring, $matches)) {
143
  $step = cf7msm_get('step');
144
  if ( !isset($matches[1])
145
  || ($matches[1] != 1 && empty($step) )
146
  || ($matches[1] != 1 && ((int) $step) + 1 < $matches[1]) ) {
147
- $cf7->form = apply_filters('wh_hide_cf7_step_message', "Please fill out the form on the previous page");
 
 
 
 
 
 
 
148
  }
149
  if (count($matches) == 3 && $matches[1] != $matches[2]) {
150
  add_filter('wpcf7_ajax_json_echo', 'cf7msm_clear_success_message', 10, 2);
@@ -155,8 +182,66 @@ function cf7msm_step_2($cf7) {
155
  add_action('wpcf7_contact_form', 'cf7msm_step_2');
156
 
157
  /**
158
- * Handle a multi-step cf7 form.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  */
 
160
  function cf7msm_store_data_steps(&$cf7) {
161
  if (isset($cf7->posted_data['step'])) {
162
  if (preg_match('/(\d+)-(\d+)/', $cf7->posted_data['step'], $matches)) {
@@ -207,8 +292,7 @@ function cf7msm_store_data_steps(&$cf7) {
207
  }
208
  }
209
  }
210
-
211
- add_action( 'wpcf7_before_send_mail', 'cf7msm_store_data_steps', 9 );
212
 
213
  /**
214
  * Hide success message if form is redirecting to another page.
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.4
9
  */
10
  /* Copyright 2012 Webhead LLC (email: info at webheadcoder.com)
11
 
63
  }
64
  add_action('init', 'cf7msm_init_sessions');
65
 
66
+ /**
67
+ * Add the right hooks for the right version of cf7.
68
+ */
69
+ function cf7msm_init() {
70
+ /*
71
+ if ( class_exists( 'WPCF7_Submission' ) ) {
72
+ add_filter( 'wpcf7_posted_data', 'cf7msm_store_data_steps_filter', 9 );
73
+ }
74
+ else {
75
+ add_action( 'wpcf7_before_send_mail', 'cf7msm_store_data_steps', 9 );
76
+ }
77
+ */
78
+ }
79
+ add_action( 'init', 'cf7msm_init' );
80
 
81
  /**
82
  * Add scripts to be able to go back to a previous step.
151
  * If it's not the first step, make sure it's the next form in the steps.
152
  */
153
  function cf7msm_step_2($cf7) {
154
+ $has_wpcf7_class = class_exists( 'WPCF7_ContactForm' ) && method_exists($cf7, 'prop');
155
+ if ( $has_wpcf7_class ) {
156
+ $formstring = $cf7->prop('form');
157
+ }
158
+ else {
159
+ $formstring = $cf7->form;
160
+ }
161
  //check if form has a step field
162
  if (!is_admin() && preg_match('/\[hidden step "(\d+)-(\d+)"\]/', $formstring, $matches)) {
163
  $step = cf7msm_get('step');
164
  if ( !isset($matches[1])
165
  || ($matches[1] != 1 && empty($step) )
166
  || ($matches[1] != 1 && ((int) $step) + 1 < $matches[1]) ) {
167
+ if ( $has_wpcf7_class ) {
168
+ $cf7->set_properties( array(
169
+ 'form' => apply_filters('wh_hide_cf7_step_message', "Please fill out the form on the previous page")
170
+ ) );
171
+ }
172
+ else {
173
+ $cf7->form = apply_filters('wh_hide_cf7_step_message', "Please fill out the form on the previous page");
174
+ }
175
  }
176
  if (count($matches) == 3 && $matches[1] != $matches[2]) {
177
  add_filter('wpcf7_ajax_json_echo', 'cf7msm_clear_success_message', 10, 2);
182
  add_action('wpcf7_contact_form', 'cf7msm_step_2');
183
 
184
  /**
185
+ * Handle a multi-step cf7 form for cf7 3.9+
186
+ */
187
+ function cf7msm_store_data_steps_filter( $cf7_posted_data ) {
188
+ if (isset($cf7_posted_data['step'])) {
189
+ if (preg_match('/(\d+)-(\d+)/', $cf7_posted_data['step'], $matches)) {
190
+ $curr_step = $matches[1];
191
+ $last_step = $matches[2];
192
+ }
193
+
194
+ //for back button
195
+ $prev_urls = cf7msm_get('cf7msm_prev_urls');
196
+ if ( empty($prev_urls) ) {
197
+ $prev_urls = array();
198
+ }
199
+ //example:
200
+ // on step 1,
201
+ // prev url {"2-3":"page-2"} will be set.
202
+ // back button is pressed, key "1-3" is looked up and returns undefined
203
+ // on step 2,
204
+ // prev url {"3-3":"page-2"} will be set.
205
+ // back button is pressed, key "2-3" is looked up and returns "page-1"
206
+ // on step 3,
207
+ // prev url {"4-3":"page-3"} will be set. - not used
208
+ // back button is pressed, key "3-3" is looked up and returns "page-2"
209
+ // step
210
+ $prev_urls[ ($curr_step+1) . '-' . $last_step] = cf7msm_current_url();
211
+ cf7msm_set('cf7msm_prev_urls', $prev_urls);
212
+
213
+ $prev_data = cf7msm_get('cf7msm_posted_data', '' );
214
+ if (!is_array($prev_data)) {
215
+ $prev_data = array();
216
+ }
217
+ //remove empty [form] tags from posted_data so $prev_data can be stored.
218
+ $fes = wpcf7_scan_shortcode();
219
+ foreach ( $fes as $fe ) {
220
+ if ( empty( $fe['name'] ) || $fe['type'] != 'form' )
221
+ continue;
222
+ unset($cf7_posted_data[$fe['name']]);
223
+ }
224
+ if ($curr_step != $last_step) {
225
+ $wpcf7 = WPCF7_ContactForm::get_current();
226
+ $wpcf7->skip_mail = true;
227
+ cf7msm_set('step', $curr_step);
228
+ $posted_data = array_merge($prev_data, $cf7_posted_data);
229
+ cf7msm_set('cf7msm_posted_data', $posted_data );
230
+ }
231
+ else {
232
+ $cf7_posted_data = array_merge($prev_data, $cf7_posted_data);
233
+ cf7msm_remove('step');
234
+ cf7msm_remove('cf7msm_posted_data');
235
+ }
236
+ }
237
+ return $cf7_posted_data;
238
+ }
239
+ add_filter( 'wpcf7_posted_data', 'cf7msm_store_data_steps_filter', 9 );
240
+
241
+ /**
242
+ * Handle a multi-step cf7 form for cf7 < 3.9
243
  */
244
+ /*
245
  function cf7msm_store_data_steps(&$cf7) {
246
  if (isset($cf7->posted_data['step'])) {
247
  if (preg_match('/(\d+)-(\d+)/', $cf7->posted_data['step'], $matches)) {
292
  }
293
  }
294
  }
295
+ */
 
296
 
297
  /**
298
  * Hide success message if form is redirecting to another page.
module-back.php CHANGED
@@ -53,7 +53,7 @@ function cf7msm_add_tag_generator_back() {
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="">
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="">
readme.txt CHANGED
@@ -2,8 +2,8 @@
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: 3.9
6
- Stable tag: 1.3.6
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -11,6 +11,8 @@ Enables the Contact Form 7 plugin to create multi-page, multi-step forms.
11
 
12
  == Description ==
13
 
 
 
14
  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.
15
 
16
  Sample of this working is at [http://webheadcoder.com/contact-form-7-multi-step-form/](http://webheadcoder.com/contact-form-7-multi-step-form/)
@@ -30,7 +32,7 @@ Instructions:
30
  1. Add a hidden tag named "step" with the value being <current_step>-<total-steps>. For example, if you have a 5-step form and you are creating the first step, the form would need: `[hidden step "1-5"]`. The last form in this example would need: `[hidden step "5-5"]`
31
 
32
  1. In the "Additional Settings" textarea at the bottom of the form editing page, add in the location of the next form.
33
- If the next form is located on My2ndPage on example.com you would add the following to "Additional Settings" (note the following should all be on one line) `on_sent_ok: "location.replace('http://example.com/My2ndPage/');"`
34
 
35
  1. Repeat steps 1 - 3. On the form that will actually send a email, do not do step 3 unless you want the form to redirect
36
  the user to another page.
@@ -49,13 +51,27 @@ This plugin only works when the forms are on separate pages. Many have asked to
49
 
50
  == Frequently Asked Questions ==
51
 
52
- = Why did you do this? =
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
- I have used countless free plugins and have saved countless hours. I could not find any plugin that does multi page forms, but have seen a few requests for it. I decided to give some hours back.
55
 
56
 
57
  == Changelog ==
58
 
 
 
 
59
  = 1.3.6 =
60
  Updated readme to be more readable.
61
  Fixed issue for servers with magic quotes turned off. Fixes "Please fill out the form on the previous page" error.
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: 3.9.2
6
+ Stable tag: 1.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
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/)
32
  1. Add a hidden tag named "step" with the value being <current_step>-<total-steps>. For example, if you have a 5-step form and you are creating the first step, the form would need: `[hidden step "1-5"]`. The last form in this example would need: `[hidden step "5-5"]`
33
 
34
  1. In the "Additional Settings" textarea at the bottom of the form editing page, add in the location of the next form.
35
+ If the next form is located on my-second-page on example.com you would add the following all on one line to "Additional Settings": `on_sent_ok: "location.replace('http://example.com/my-second-page/');"`
36
 
37
  1. Repeat steps 1 - 3. On the form that will actually send a email, do not do step 3 unless you want the form to redirect
38
  the user to another page.
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.4 =
73
+ Updated to be compatible with Contact Form 7 version 3.9.
74
+
75
  = 1.3.6 =
76
  Updated readme to be more readable.
77
  Fixed issue for servers with magic quotes turned off. Fixes "Please fill out the form on the previous page" error.