Version Description
- New feature: Pass specific fields from the form as URL query parameters.
- Minor dev improvements.
Download this release
Release Info
Developer | yuvalsabar |
Plugin | Contact Form 7 Redirection |
Version | 1.2.8 |
Comparing to | |
See all releases |
Code changes from version 1.2.2 to 1.2.8
- admin/wpcf7-redirect-admin-script.js +33 -2
- admin/wpcf7-redirect-admin-style.css +11 -1
- js/wpcf7-redirect-script.js +47 -27
- readme.txt +26 -6
- wpcf7-redirect.php +99 -31
admin/wpcf7-redirect-admin-script.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
jQuery(document).ready(function($) {
|
|
|
2 |
jQuery( '#wpcf7-redirect-open-in-new-tab' ).change(function() {
|
3 |
if ( jQuery( this ).is( ":checked" ) ) {
|
4 |
jQuery( '.field-notice-alert' ).removeClass( 'field-notice-hidden' );
|
@@ -7,15 +8,45 @@ jQuery(document).ready(function($) {
|
|
7 |
}
|
8 |
});
|
9 |
|
10 |
-
if ( jQuery( '
|
11 |
jQuery( '.field-notice-alert' ).removeClass( 'field-notice-hidden' );
|
12 |
}
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
jQuery( '#wpcf7-redirect-after-sent-script' ).keyup(function(event) {
|
15 |
-
if (
|
16 |
jQuery( '.field-warning-alert' ).removeClass( 'field-notice-hidden' );
|
17 |
} else {
|
18 |
jQuery( '.field-warning-alert' ).addClass( 'field-notice-hidden' );
|
19 |
}
|
20 |
});
|
|
|
|
|
|
|
|
|
21 |
});
|
1 |
jQuery(document).ready(function($) {
|
2 |
+
// field - open in a new tab
|
3 |
jQuery( '#wpcf7-redirect-open-in-new-tab' ).change(function() {
|
4 |
if ( jQuery( this ).is( ":checked" ) ) {
|
5 |
jQuery( '.field-notice-alert' ).removeClass( 'field-notice-hidden' );
|
8 |
}
|
9 |
});
|
10 |
|
11 |
+
if ( jQuery( '#wpcf7-redirect-open-in-new-tab' ).is( ":checked" ) ) {
|
12 |
jQuery( '.field-notice-alert' ).removeClass( 'field-notice-hidden' );
|
13 |
}
|
14 |
|
15 |
+
// fields - http build query
|
16 |
+
jQuery( '#wpcf7-redirect-http-build-query-selectively' ).change(function() {
|
17 |
+
if ( jQuery( this ).is( ":checked" ) ) {
|
18 |
+
jQuery( '#wpcf7-redirect-http-build-query-selectively-fields' ).removeClass( 'field-hidden' );
|
19 |
+
}
|
20 |
+
});
|
21 |
+
|
22 |
+
jQuery( '#wpcf7-redirect-http-build-query' ).change(function() {
|
23 |
+
if ( jQuery( this ).is( ":checked" ) ) {
|
24 |
+
jQuery( '#wpcf7-redirect-http-build-query-selectively-fields' ).addClass( 'field-hidden' );
|
25 |
+
}
|
26 |
+
});
|
27 |
+
|
28 |
+
if ( jQuery( '#wpcf7-redirect-http-build-query-selectively' ).is( ":checked" ) ) {
|
29 |
+
jQuery( '#wpcf7-redirect-http-build-query-selectively-fields' ).removeClass( 'field-hidden' );
|
30 |
+
}
|
31 |
+
|
32 |
+
jQuery('.checkbox-radio-1').change(function() {
|
33 |
+
var checked = jQuery(this).is(':checked');
|
34 |
+
jQuery('.checkbox-radio-1').prop('checked', false);
|
35 |
+
if ( checked ) {
|
36 |
+
jQuery(this).prop('checked',true);
|
37 |
+
}
|
38 |
+
});
|
39 |
+
|
40 |
+
// field - after sent script
|
41 |
jQuery( '#wpcf7-redirect-after-sent-script' ).keyup(function(event) {
|
42 |
+
if ( jQuery(this).val().length != 0 ) {
|
43 |
jQuery( '.field-warning-alert' ).removeClass( 'field-notice-hidden' );
|
44 |
} else {
|
45 |
jQuery( '.field-warning-alert' ).addClass( 'field-notice-hidden' );
|
46 |
}
|
47 |
});
|
48 |
+
|
49 |
+
if ( jQuery( '#wpcf7-redirect-after-sent-script' ).val() ) {
|
50 |
+
jQuery( '.field-warning-alert' ).removeClass( 'field-notice-hidden' );
|
51 |
+
}
|
52 |
});
|
admin/wpcf7-redirect-admin-style.css
CHANGED
@@ -5,9 +5,13 @@
|
|
5 |
#redirect-panel .field-wrap [type='select'] {
|
6 |
height: 28px;
|
7 |
}
|
8 |
-
#redirect-panel .field-wrap [type='url']
|
|
|
9 |
width: 100%;
|
10 |
}
|
|
|
|
|
|
|
11 |
#redirect-panel .field-wrap textarea {
|
12 |
direction: ltr;
|
13 |
width: 100%;
|
@@ -15,8 +19,13 @@
|
|
15 |
#redirect-panel .field-wrap-after-sent-script {
|
16 |
margin-top: 10px;
|
17 |
}
|
|
|
18 |
#redirect-panel .field-wrap-after-sent-script label {
|
19 |
display: block;
|
|
|
|
|
|
|
|
|
20 |
}
|
21 |
#redirect-panel .field-wrap-after-sent-script .field-message {
|
22 |
margin-bottom: 10px;
|
@@ -34,6 +43,7 @@
|
|
34 |
border: 1px solid #faebcc;
|
35 |
background-color: #fcf8e3;
|
36 |
}
|
|
|
37 |
#redirect-panel .field-notice-hidden {
|
38 |
display: none;
|
39 |
}
|
5 |
#redirect-panel .field-wrap [type='select'] {
|
6 |
height: 28px;
|
7 |
}
|
8 |
+
#redirect-panel .field-wrap [type='url'],
|
9 |
+
#redirect-panel .field-wrap [type='text'] {
|
10 |
width: 100%;
|
11 |
}
|
12 |
+
#redirect-panel .field-wrap [type='checkbox'] {
|
13 |
+
margin-top: 1px;
|
14 |
+
}
|
15 |
#redirect-panel .field-wrap textarea {
|
16 |
direction: ltr;
|
17 |
width: 100%;
|
19 |
#redirect-panel .field-wrap-after-sent-script {
|
20 |
margin-top: 10px;
|
21 |
}
|
22 |
+
#redirect-panel .field-wrap-page-id label,
|
23 |
#redirect-panel .field-wrap-after-sent-script label {
|
24 |
display: block;
|
25 |
+
margin-bottom: 5px;
|
26 |
+
}
|
27 |
+
#redirect-panel .field-wrap-http-build-query-selectively [type='text'] {
|
28 |
+
margin-top: 10px;
|
29 |
}
|
30 |
#redirect-panel .field-wrap-after-sent-script .field-message {
|
31 |
margin-bottom: 10px;
|
43 |
border: 1px solid #faebcc;
|
44 |
background-color: #fcf8e3;
|
45 |
}
|
46 |
+
#redirect-panel .field-hidden,
|
47 |
#redirect-panel .field-notice-hidden {
|
48 |
display: none;
|
49 |
}
|
js/wpcf7-redirect-script.js
CHANGED
@@ -5,46 +5,66 @@ jQuery(document).ready(function() {
|
|
5 |
function wpcf7_redirect_mailsent_handler() {
|
6 |
document.addEventListener( 'wpcf7mailsent', function( event ) {
|
7 |
form = wpcf7_redirect_forms [ event.detail.contactFormId ];
|
8 |
-
|
9 |
// Script to run after sent.
|
10 |
if ( form.after_sent_script ) {
|
|
|
11 |
eval( form.after_sent_script );
|
12 |
}
|
13 |
-
|
14 |
|
15 |
-
//
|
16 |
if ( form.use_external_url && form.external_url ) {
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
if ( ! form.open_in_new_tab ) {
|
24 |
// Open in current tab
|
25 |
-
location.href =
|
26 |
} else {
|
27 |
// Open in external tab
|
28 |
-
window.open(
|
29 |
}
|
30 |
}
|
31 |
-
|
32 |
-
// Redirect to a page in this site.
|
33 |
-
else if ( form.thankyou_page_url ) {
|
34 |
-
if ( form.http_build_query ) {
|
35 |
-
// Build http query
|
36 |
-
http_query = jQuery.param( event.detail.inputs, true );
|
37 |
-
form.thankyou_page_url = form.thankyou_page_url + '?' + http_query;
|
38 |
-
}
|
39 |
-
|
40 |
-
if ( ! form.open_in_new_tab ) {
|
41 |
-
// Open in current tab
|
42 |
-
location.href = form.thankyou_page_url;
|
43 |
-
} else {
|
44 |
-
// Open in new tab
|
45 |
-
window.open( form.thankyou_page_url );
|
46 |
-
}
|
47 |
-
}
|
48 |
|
49 |
}, false );
|
50 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
function wpcf7_redirect_mailsent_handler() {
|
6 |
document.addEventListener( 'wpcf7mailsent', function( event ) {
|
7 |
form = wpcf7_redirect_forms [ event.detail.contactFormId ];
|
8 |
+
|
9 |
// Script to run after sent.
|
10 |
if ( form.after_sent_script ) {
|
11 |
+
form.after_sent_script = htmlspecialchars_decode( form.after_sent_script );
|
12 |
eval( form.after_sent_script );
|
13 |
}
|
|
|
14 |
|
15 |
+
// Set redirect URL
|
16 |
if ( form.use_external_url && form.external_url ) {
|
17 |
+
redirect_url = form.external_url;
|
18 |
+
} else {
|
19 |
+
redirect_url = form.thankyou_page_url;
|
20 |
+
}
|
21 |
+
|
22 |
+
// Build http query
|
23 |
+
if ( form.http_build_query ) {
|
24 |
+
http_query = jQuery.param( event.detail.inputs, true );
|
25 |
+
redirect_url = redirect_url + '?' + http_query;
|
26 |
+
} else if ( form.http_build_query_selectively ) {
|
27 |
+
http_query = '?';
|
28 |
+
selective_fields = form.http_build_query_selectively_fields.replace(' ', '').split(',');
|
29 |
+
event.detail.inputs.forEach( function(element, index) {
|
30 |
+
if ( selective_fields.indexOf( element.name ) != -1 ) {
|
31 |
+
http_query += element.name + '=' + element.value + '&';
|
32 |
+
}
|
33 |
+
});
|
34 |
|
35 |
+
http_query = http_query.slice(0, -1);
|
36 |
+
redirect_url = redirect_url + http_query;
|
37 |
+
}
|
38 |
+
|
39 |
+
// Redirect
|
40 |
+
if ( redirect_url ) {
|
41 |
if ( ! form.open_in_new_tab ) {
|
42 |
// Open in current tab
|
43 |
+
location.href = redirect_url;
|
44 |
} else {
|
45 |
// Open in external tab
|
46 |
+
window.open( redirect_url );
|
47 |
}
|
48 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
}, false );
|
51 |
}
|
52 |
+
|
53 |
+
function htmlspecialchars_decode( string ) {
|
54 |
+
var map = {
|
55 |
+
'&': '&',
|
56 |
+
'&': "&",
|
57 |
+
'<': '<',
|
58 |
+
'>': '>',
|
59 |
+
'"': '"',
|
60 |
+
''': "'",
|
61 |
+
'’': "’",
|
62 |
+
'‘': "‘",
|
63 |
+
'–': "–",
|
64 |
+
'—': "—",
|
65 |
+
'…': "…",
|
66 |
+
'”': '”'
|
67 |
+
};
|
68 |
+
|
69 |
+
return string.replace(/\&[\w\d\#]{2,5}\;/g, function(m) { return map[m]; });
|
70 |
+
}
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== Contact Form 7 Redirection ===
|
2 |
Tags: contact form 7 redirect, contact form 7 thank you page, redirect cf7, redirect contact form 7, contact form 7 success page, cf7 redirect
|
3 |
Contributors: yuvalsabar
|
4 |
-
Requires at least: 4.
|
5 |
-
Tested up to: 4.9.
|
6 |
-
Stable tag: 1.
|
7 |
License: GPLv3 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
@@ -12,7 +12,7 @@ A simple add-on for Contact Form 7 that adds a redirect option after form sent s
|
|
12 |
== Description ==
|
13 |
|
14 |
A straightforward add-on plugin for Contact Form 7 - adds the option to redirect to any page you choose after mail sent successfully, with DOM Events and without AJAX being disabled.
|
15 |
-
NOTE: This plugin requires Contact Form 7 version 4.
|
16 |
|
17 |
== Usage ==
|
18 |
|
@@ -43,8 +43,28 @@ No. One of the reasons we developed this plugin, is because on_send_ok is now de
|
|
43 |
|
44 |
== Changelog ==
|
45 |
|
46 |
-
= 1.2.
|
47 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
= 1.2 =
|
50 |
* Added option to add script after the form has been sent successfully.
|
1 |
=== Contact Form 7 Redirection ===
|
2 |
Tags: contact form 7 redirect, contact form 7 thank you page, redirect cf7, redirect contact form 7, contact form 7 success page, cf7 redirect
|
3 |
Contributors: yuvalsabar
|
4 |
+
Requires at least: 4.7.0
|
5 |
+
Tested up to: 4.9.8
|
6 |
+
Stable tag: 1.2.8
|
7 |
License: GPLv3 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
12 |
== Description ==
|
13 |
|
14 |
A straightforward add-on plugin for Contact Form 7 - adds the option to redirect to any page you choose after mail sent successfully, with DOM Events and without AJAX being disabled.
|
15 |
+
NOTE: This plugin requires Contact Form 7 version 4.8 or later.
|
16 |
|
17 |
== Usage ==
|
18 |
|
43 |
|
44 |
== Changelog ==
|
45 |
|
46 |
+
= 1.2.8 =
|
47 |
+
* New feature: Pass specific fields from the form as URL query parameters.
|
48 |
+
* Minor dev improvements.
|
49 |
+
|
50 |
+
= 1.2.7 =
|
51 |
+
* Script field now accepts special characters, such as < and >.
|
52 |
+
|
53 |
+
= 1.2.6 =
|
54 |
+
* Added support for browsers that don't support AJAX.
|
55 |
+
* Minor CSS changes.
|
56 |
+
|
57 |
+
= 1.2.5 =
|
58 |
+
* Added error message if Contact Form 7 version is earlier than 4.8.
|
59 |
+
|
60 |
+
= 1.2.4 =
|
61 |
+
* Fixed a bug regarding sanitizing URL, causing & to change to #038;
|
62 |
+
* Unnecessary variables removed.
|
63 |
+
|
64 |
+
= 1.2.2 =
|
65 |
+
* New feature: Pass all fields from the form as URL query parameters.
|
66 |
+
* Minor CSS changes.
|
67 |
+
* Dev improvements.
|
68 |
|
69 |
= 1.2 =
|
70 |
* Added option to add script after the form has been sent successfully.
|
wpcf7-redirect.php
CHANGED
@@ -3,14 +3,14 @@
|
|
3 |
* Plugin Name: Contact Form 7 Redirection
|
4 |
* Plugin URI: http://querysol.com/blog/product/contact-form-7-redirection/
|
5 |
* Description: Contact Form 7 Add-on - Redirect after mail sent.
|
6 |
-
* Version: 1.2.
|
7 |
* Author: Query Solutions
|
8 |
* Author URI: http://querysol.com
|
9 |
* Contributors: querysolutions, yuvalsabar
|
10 |
-
* Requires at least: 4.0
|
11 |
*
|
12 |
* Text Domain: wpcf7-redirect
|
13 |
-
* Domain Path: /
|
14 |
*
|
15 |
* @package Contact Form 7 Redirection
|
16 |
* @category Contact Form 7 Addon
|
@@ -31,7 +31,7 @@ class WPCF7_Redirect {
|
|
31 |
public function __construct() {
|
32 |
$this->plugin_url = plugin_dir_url( __FILE__ );
|
33 |
$this->plugin_path = plugin_dir_path( __FILE__ );
|
34 |
-
$this->version = '1.2.
|
35 |
$this->add_actions();
|
36 |
}
|
37 |
|
@@ -45,6 +45,7 @@ class WPCF7_Redirect {
|
|
45 |
add_action( 'wpcf7_editor_panels', array( $this, 'add_panel' ) );
|
46 |
add_action( 'wpcf7_after_save', array( $this, 'store_meta' ) );
|
47 |
add_action( 'wpcf7_after_create', array( $this, 'duplicate_form_support' ) );
|
|
|
48 |
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
|
49 |
}
|
50 |
|
@@ -69,6 +70,10 @@ class WPCF7_Redirect {
|
|
69 |
public function enqueue_frontend() {
|
70 |
wp_enqueue_script( 'wpcf7-redirect-script', $this->plugin_url . 'js/wpcf7-redirect-script.js', array(), null, true );
|
71 |
wp_localize_script( 'wpcf7-redirect-script', 'wpcf7_redirect_forms', $this->get_forms() );
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
|
74 |
/**
|
@@ -103,14 +108,22 @@ class WPCF7_Redirect {
|
|
103 |
'name' => 'use_external_url',
|
104 |
'type' => 'checkbox',
|
105 |
),
|
|
|
|
|
|
|
|
|
106 |
array(
|
107 |
'name' => 'http_build_query',
|
108 |
'type' => 'checkbox',
|
109 |
),
|
110 |
array(
|
111 |
-
'name' => '
|
112 |
'type' => 'checkbox',
|
113 |
),
|
|
|
|
|
|
|
|
|
114 |
array(
|
115 |
'name' => 'after_sent_script',
|
116 |
'type' => 'textarea',
|
@@ -163,7 +176,7 @@ class WPCF7_Redirect {
|
|
163 |
break;
|
164 |
|
165 |
case 'textarea':
|
166 |
-
$value =
|
167 |
break;
|
168 |
|
169 |
case 'number':
|
@@ -171,7 +184,7 @@ class WPCF7_Redirect {
|
|
171 |
break;
|
172 |
|
173 |
case 'url':
|
174 |
-
$value =
|
175 |
break;
|
176 |
}
|
177 |
|
@@ -181,15 +194,19 @@ class WPCF7_Redirect {
|
|
181 |
}
|
182 |
|
183 |
/**
|
184 |
-
*
|
|
|
185 |
*/
|
186 |
public function get_forms() {
|
187 |
$args = array(
|
188 |
'post_type' => 'wpcf7_contact_form',
|
189 |
'posts_per_page' => -1,
|
|
|
190 |
);
|
191 |
$query = new WP_Query( $args );
|
192 |
|
|
|
|
|
193 |
if ( $query->have_posts() ) :
|
194 |
|
195 |
$fields = $this->get_plugin_fields();
|
@@ -202,16 +219,14 @@ class WPCF7_Redirect {
|
|
202 |
$forms[ $post_id ][ $field['name'] ] = get_post_meta( $post_id, '_wpcf7_redirect_' . $field['name'], true );
|
203 |
|
204 |
if ( $field['type'] == 'textarea' ) {
|
205 |
-
$forms[ $post_id ][ $field['name'] ] =
|
206 |
}
|
207 |
}
|
208 |
|
209 |
// Thank you page URL is a little bit different...
|
210 |
$forms[ $post_id ]['thankyou_page_url'] = $forms[ $post_id ]['page_id'] ? get_permalink( $forms[ $post_id ]['page_id'] ) : '';
|
211 |
-
|
212 |
endwhile;
|
213 |
wp_reset_postdata();
|
214 |
-
|
215 |
endif;
|
216 |
|
217 |
return $forms;
|
@@ -244,13 +259,16 @@ class WPCF7_Redirect {
|
|
244 |
$wpcf7_path = plugin_dir_path( dirname( __FILE__ ) ) . 'contact-form-7/wp-contact-form-7.php';
|
245 |
$wpcf7_data = get_plugin_data( $wpcf7_path, false, false );
|
246 |
|
247 |
-
// If CF7 version is < 4.
|
248 |
-
if ( $wpcf7_data['Version'] < 4.
|
249 |
?>
|
250 |
|
251 |
-
<div class="error notice">
|
|
|
|
|
|
|
252 |
<p>
|
253 |
-
<?php esc_html_e( 'Error: Please update Contact Form 7.', 'wpcf7-redirect' );?>
|
254 |
</p>
|
255 |
</div>
|
256 |
|
@@ -258,11 +276,11 @@ class WPCF7_Redirect {
|
|
258 |
}
|
259 |
} else {
|
260 |
// If CF7 isn't installed and activated, throw an error.
|
261 |
-
$wpcf7_path = plugin_dir_path( dirname( __FILE__ ) ) . 'contact-form-7/wp-contact-form-7.php';
|
262 |
-
$wpcf7_data = get_plugin_data( $wpcf7_path, false, false );
|
263 |
?>
|
264 |
-
|
265 |
-
|
|
|
|
|
266 |
<p>
|
267 |
<?php esc_html_e( 'Error: Please install and activate Contact Form 7.', 'wpcf7-redirect' );?>
|
268 |
</p>
|
@@ -272,6 +290,48 @@ class WPCF7_Redirect {
|
|
272 |
}
|
273 |
}
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
/**
|
276 |
* Create the panel inputs
|
277 |
*
|
@@ -288,11 +348,10 @@ class WPCF7_Redirect {
|
|
288 |
</h2>
|
289 |
|
290 |
<fieldset>
|
291 |
-
<legend>
|
292 |
-
<?php esc_html_e( 'Select a page to redirect to on successful form submission.', 'wpcf7-redirect' );?>
|
293 |
-
</legend>
|
294 |
-
|
295 |
<div class="field-wrap field-wrap-page-id">
|
|
|
|
|
|
|
296 |
<?php
|
297 |
echo wp_dropdown_pages( array(
|
298 |
'echo' => 0,
|
@@ -300,7 +359,7 @@ class WPCF7_Redirect {
|
|
300 |
'show_option_none' => __( 'Choose Page', 'wpcf7-redirect' ),
|
301 |
'option_none_value' => '0',
|
302 |
'selected' => $fields['page_id'],
|
303 |
-
'id' => '
|
304 |
)
|
305 |
);
|
306 |
?>
|
@@ -317,12 +376,6 @@ class WPCF7_Redirect {
|
|
317 |
</label>
|
318 |
</div>
|
319 |
|
320 |
-
<div class="field-wrap field-wrap-http-build-query">
|
321 |
-
<input type="checkbox" id="wpcf7-redirect-http-build-query" name="wpcf7-redirect[http_build_query]" <?php checked( $fields['http_build_query'], 'on', true ); ?>/>
|
322 |
-
<label for="wpcf7-redirect-http-build-query">
|
323 |
-
<?php esc_html_e( 'Pass fields from the form as URL query parameters', 'wpcf7-redirect' );?>
|
324 |
-
</label>
|
325 |
-
</div>
|
326 |
|
327 |
<div class="field-wrap field-wrap-open-in-new-tab">
|
328 |
<input type="checkbox" id="wpcf7-redirect-open-in-new-tab" name="wpcf7-redirect[open_in_new_tab]" <?php checked( $fields['open_in_new_tab'], 'on', true ); ?>/>
|
@@ -335,6 +388,21 @@ class WPCF7_Redirect {
|
|
335 |
</div>
|
336 |
</div>
|
337 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
<hr />
|
339 |
|
340 |
<div class="field-wrap field-wrap-after-sent-script">
|
@@ -358,4 +426,4 @@ class WPCF7_Redirect {
|
|
358 |
}
|
359 |
}
|
360 |
|
361 |
-
$cf7_redirect = new WPCF7_Redirect();
|
3 |
* Plugin Name: Contact Form 7 Redirection
|
4 |
* Plugin URI: http://querysol.com/blog/product/contact-form-7-redirection/
|
5 |
* Description: Contact Form 7 Add-on - Redirect after mail sent.
|
6 |
+
* Version: 1.2.8
|
7 |
* Author: Query Solutions
|
8 |
* Author URI: http://querysol.com
|
9 |
* Contributors: querysolutions, yuvalsabar
|
10 |
+
* Requires at least: 4.7.0
|
11 |
*
|
12 |
* Text Domain: wpcf7-redirect
|
13 |
+
* Domain Path: /lang
|
14 |
*
|
15 |
* @package Contact Form 7 Redirection
|
16 |
* @category Contact Form 7 Addon
|
31 |
public function __construct() {
|
32 |
$this->plugin_url = plugin_dir_url( __FILE__ );
|
33 |
$this->plugin_path = plugin_dir_path( __FILE__ );
|
34 |
+
$this->version = '1.2.8';
|
35 |
$this->add_actions();
|
36 |
}
|
37 |
|
45 |
add_action( 'wpcf7_editor_panels', array( $this, 'add_panel' ) );
|
46 |
add_action( 'wpcf7_after_save', array( $this, 'store_meta' ) );
|
47 |
add_action( 'wpcf7_after_create', array( $this, 'duplicate_form_support' ) );
|
48 |
+
add_action( 'wpcf7_submit', array( $this, 'non_ajax_redirection' ) );
|
49 |
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
|
50 |
}
|
51 |
|
70 |
public function enqueue_frontend() {
|
71 |
wp_enqueue_script( 'wpcf7-redirect-script', $this->plugin_url . 'js/wpcf7-redirect-script.js', array(), null, true );
|
72 |
wp_localize_script( 'wpcf7-redirect-script', 'wpcf7_redirect_forms', $this->get_forms() );
|
73 |
+
|
74 |
+
if ( isset( $this->enqueue_new_tab_script ) && $this->enqueue_new_tab_script ){
|
75 |
+
wp_add_inline_script( 'wpcf7-redirect-script', 'window.open("'. $this->redirect_url .'");' );
|
76 |
+
}
|
77 |
}
|
78 |
|
79 |
/**
|
108 |
'name' => 'use_external_url',
|
109 |
'type' => 'checkbox',
|
110 |
),
|
111 |
+
array(
|
112 |
+
'name' => 'open_in_new_tab',
|
113 |
+
'type' => 'checkbox',
|
114 |
+
),
|
115 |
array(
|
116 |
'name' => 'http_build_query',
|
117 |
'type' => 'checkbox',
|
118 |
),
|
119 |
array(
|
120 |
+
'name' => 'http_build_query_selectively',
|
121 |
'type' => 'checkbox',
|
122 |
),
|
123 |
+
array(
|
124 |
+
'name' => 'http_build_query_selectively_fields',
|
125 |
+
'type' => 'text',
|
126 |
+
),
|
127 |
array(
|
128 |
'name' => 'after_sent_script',
|
129 |
'type' => 'textarea',
|
176 |
break;
|
177 |
|
178 |
case 'textarea':
|
179 |
+
$value = htmlspecialchars( $value );
|
180 |
break;
|
181 |
|
182 |
case 'number':
|
184 |
break;
|
185 |
|
186 |
case 'url':
|
187 |
+
$value = esc_url_raw( $value );
|
188 |
break;
|
189 |
}
|
190 |
|
194 |
}
|
195 |
|
196 |
/**
|
197 |
+
* Push all forms redirect settings data into an array.
|
198 |
+
* @return array Form redirect settings data
|
199 |
*/
|
200 |
public function get_forms() {
|
201 |
$args = array(
|
202 |
'post_type' => 'wpcf7_contact_form',
|
203 |
'posts_per_page' => -1,
|
204 |
+
'suppress_filters' => true
|
205 |
);
|
206 |
$query = new WP_Query( $args );
|
207 |
|
208 |
+
$forms = array();
|
209 |
+
|
210 |
if ( $query->have_posts() ) :
|
211 |
|
212 |
$fields = $this->get_plugin_fields();
|
219 |
$forms[ $post_id ][ $field['name'] ] = get_post_meta( $post_id, '_wpcf7_redirect_' . $field['name'], true );
|
220 |
|
221 |
if ( $field['type'] == 'textarea' ) {
|
222 |
+
$forms[ $post_id ][ $field['name'] ] = $forms[ $post_id ][ $field['name'] ];
|
223 |
}
|
224 |
}
|
225 |
|
226 |
// Thank you page URL is a little bit different...
|
227 |
$forms[ $post_id ]['thankyou_page_url'] = $forms[ $post_id ]['page_id'] ? get_permalink( $forms[ $post_id ]['page_id'] ) : '';
|
|
|
228 |
endwhile;
|
229 |
wp_reset_postdata();
|
|
|
230 |
endif;
|
231 |
|
232 |
return $forms;
|
259 |
$wpcf7_path = plugin_dir_path( dirname( __FILE__ ) ) . 'contact-form-7/wp-contact-form-7.php';
|
260 |
$wpcf7_data = get_plugin_data( $wpcf7_path, false, false );
|
261 |
|
262 |
+
// If CF7 version is < 4.8.
|
263 |
+
if ( $wpcf7_data['Version'] < 4.8 ) {
|
264 |
?>
|
265 |
|
266 |
+
<div class="wpcf7-redirect-error error notice">
|
267 |
+
<h3>
|
268 |
+
<?php esc_html_e( 'Contact Form Redirection', 'wpcf7-redirect' );?>
|
269 |
+
</h3>
|
270 |
<p>
|
271 |
+
<?php esc_html_e( 'Error: Contact Form 7 version is too old. Contact Form Redirection is compatible from version 4.8 and above. Please update Contact Form 7.', 'wpcf7-redirect' );?>
|
272 |
</p>
|
273 |
</div>
|
274 |
|
276 |
}
|
277 |
} else {
|
278 |
// If CF7 isn't installed and activated, throw an error.
|
|
|
|
|
279 |
?>
|
280 |
+
<div class="wpcf7-redirect-error error notice">
|
281 |
+
<h3>
|
282 |
+
<?php esc_html_e( 'Contact Form Redirection', 'wpcf7-redirect' );?>
|
283 |
+
</h3>
|
284 |
<p>
|
285 |
<?php esc_html_e( 'Error: Please install and activate Contact Form 7.', 'wpcf7-redirect' );?>
|
286 |
</p>
|
290 |
}
|
291 |
}
|
292 |
|
293 |
+
/**
|
294 |
+
* Add plugin support to browsers that don't support ajax
|
295 |
+
*/
|
296 |
+
public function non_ajax_redirection( $contact_form ) {
|
297 |
+
$this->fields = $this->get_fields_values( $contact_form->id() );
|
298 |
+
|
299 |
+
if ( isset( $this->fields ) && ! WPCF7_Submission::is_restful() ) {
|
300 |
+
$submission = WPCF7_Submission::get_instance();
|
301 |
+
|
302 |
+
if ( $submission->get_status() == 'mail_sent' ) {
|
303 |
+
|
304 |
+
// Use extrnal url
|
305 |
+
if ( $this->fields['external_url'] && $this->fields['use_external_url'] == 'on' ) {
|
306 |
+
$this->redirect_url = $this->fields['external_url'];
|
307 |
+
} else {
|
308 |
+
$this->redirect_url = get_permalink( $this->fields['page_id'] );
|
309 |
+
}
|
310 |
+
|
311 |
+
// Pass all fields from the form as URL query parameters
|
312 |
+
if ( isset( $this->redirect_url ) && $this->redirect_url ) {
|
313 |
+
if ( $this->fields['http_build_query'] == 'on' ) {
|
314 |
+
$posted_data = $submission->get_posted_data();
|
315 |
+
// Remove WPCF7 keys from posted data
|
316 |
+
$remove_keys = array( '_wpcf7', '_wpcf7_version', '_wpcf7_locale', '_wpcf7_unit_tag', '_wpcf7_container_post' );
|
317 |
+
$posted_data = array_diff_key( $posted_data, array_flip( $remove_keys ) );
|
318 |
+
$this->redirect_url = add_query_arg( $posted_data, $this->redirect_url );
|
319 |
+
}
|
320 |
+
}
|
321 |
+
|
322 |
+
// Open link in a new tab
|
323 |
+
if ( isset( $this->redirect_url ) && $this->redirect_url ) {
|
324 |
+
if ( $this->fields['open_in_new_tab'] == 'on' ) {
|
325 |
+
$this->enqueue_new_tab_script = true;
|
326 |
+
} else {
|
327 |
+
wp_redirect( $this->redirect_url );
|
328 |
+
exit;
|
329 |
+
}
|
330 |
+
}
|
331 |
+
}
|
332 |
+
}
|
333 |
+
}
|
334 |
+
|
335 |
/**
|
336 |
* Create the panel inputs
|
337 |
*
|
348 |
</h2>
|
349 |
|
350 |
<fieldset>
|
|
|
|
|
|
|
|
|
351 |
<div class="field-wrap field-wrap-page-id">
|
352 |
+
<label for="wpcf7-redirect-page-id">
|
353 |
+
<?php esc_html_e( 'Select a page to redirect to on successful form submission.', 'wpcf7-redirect' );?>
|
354 |
+
</label>
|
355 |
<?php
|
356 |
echo wp_dropdown_pages( array(
|
357 |
'echo' => 0,
|
359 |
'show_option_none' => __( 'Choose Page', 'wpcf7-redirect' ),
|
360 |
'option_none_value' => '0',
|
361 |
'selected' => $fields['page_id'],
|
362 |
+
'id' => 'wpcf7-redirect-page-id',
|
363 |
)
|
364 |
);
|
365 |
?>
|
376 |
</label>
|
377 |
</div>
|
378 |
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
|
380 |
<div class="field-wrap field-wrap-open-in-new-tab">
|
381 |
<input type="checkbox" id="wpcf7-redirect-open-in-new-tab" name="wpcf7-redirect[open_in_new_tab]" <?php checked( $fields['open_in_new_tab'], 'on', true ); ?>/>
|
388 |
</div>
|
389 |
</div>
|
390 |
|
391 |
+
<div class="field-wrap field-wrap-http-build-query">
|
392 |
+
<input type="checkbox" id="wpcf7-redirect-http-build-query" class="checkbox-radio-1" name="wpcf7-redirect[http_build_query]" <?php checked( $fields['http_build_query'], 'on', true ); ?>/>
|
393 |
+
<label for="wpcf7-redirect-http-build-query">
|
394 |
+
<?php esc_html_e( 'Pass all the fields from the form as URL query parameters', 'wpcf7-redirect' );?>
|
395 |
+
</label>
|
396 |
+
</div>
|
397 |
+
|
398 |
+
<div class="field-wrap field-wrap-http-build-query-selectively">
|
399 |
+
<input type="checkbox" id="wpcf7-redirect-http-build-query-selectively" class="checkbox-radio-1" name="wpcf7-redirect[http_build_query_selectively]" <?php checked( $fields['http_build_query_selectively'], 'on', true ); ?>/>
|
400 |
+
<label for="wpcf7-redirect-http-build-query-selectively">
|
401 |
+
<?php esc_html_e( 'Pass specific fields from the form as URL query parameters', 'wpcf7-redirect' );?>
|
402 |
+
</label>
|
403 |
+
<input type="text" id="wpcf7-redirect-http-build-query-selectively-fields" class="field-hidden" placeholder="<?php esc_html_e( 'Fields to pass, separated by commas', 'wpcf7-redirect' );?>" name="wpcf7-redirect[http_build_query_selectively_fields]" value="<?php echo $fields['http_build_query_selectively_fields'];?>">
|
404 |
+
</div>
|
405 |
+
|
406 |
<hr />
|
407 |
|
408 |
<div class="field-wrap field-wrap-after-sent-script">
|
426 |
}
|
427 |
}
|
428 |
|
429 |
+
$cf7_redirect = new WPCF7_Redirect();
|