Version Description
First release
Download this release
Release Info
Developer | Jules Colle |
Plugin | Conditional Fields for Contact Form 7 |
Version | 0.1 |
Comparing to | |
See all releases |
Version 0.1
- admin-style.css +4 -0
- admin.php +164 -0
- contact-form-7-conditional-fields.php +191 -0
- js/scripts.js +58 -0
- js/scripts_admin.js +31 -0
- readme.txt +38 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- style.css +0 -0
admin-style.css
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
#wpcf7cf-add-button, .delete-button { text-decoration: none; display: inline-block; vertical-align: baseline; color:#4ed521; }
|
2 |
+
.delete-button { color: #d54e21 !important; }
|
3 |
+
#wpcf7cf-new-entry { display: inline-block; display:none; }
|
4 |
+
#wpcf7cf-delete-button { display: none; }
|
admin.php
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
add_action( 'admin_enqueue_scripts', 'wpcf7cf_admin_enqueue_scripts', 11 ); // set priority so scripts and styles get loaded later.
|
4 |
+
|
5 |
+
function wpcf7cf_admin_enqueue_scripts( $hook_suffix ) {
|
6 |
+
wp_enqueue_style( 'contact-form-7-cf-admin', wpcf7cf_plugin_url( 'admin-style.css' ), array(), WPCF7CF_VERSION, 'all' );
|
7 |
+
wp_enqueue_script('cf7cf-scripts-admin', wpcf7cf_plugin_url( 'js/scripts_admin.js' ),array(), WPCF7CF_VERSION,true);
|
8 |
+
}
|
9 |
+
|
10 |
+
add_filter('wpcf7_editor_panels', 'add_conditional_panel');
|
11 |
+
|
12 |
+
function add_conditional_panel($panels) {
|
13 |
+
$panels['contitional-panel'] = array(
|
14 |
+
'title' => __( 'Conditional fields', 'wpcf7cf' ),
|
15 |
+
'callback' => 'wpcf7cf_editor_panel_conditional'
|
16 |
+
);
|
17 |
+
return $panels;
|
18 |
+
}
|
19 |
+
|
20 |
+
function all_field_options($post, $selected = '') {
|
21 |
+
$all_fields = $post->form_scan_shortcode();
|
22 |
+
?>
|
23 |
+
<option value="-1">-- Select field --</option>
|
24 |
+
<?php
|
25 |
+
foreach ($all_fields as $tag) {
|
26 |
+
if ($tag['type'] == 'group' || $tag['name'] == '') continue;
|
27 |
+
?>
|
28 |
+
<option value="<?php echo $tag['name']; ?>" <?php echo $selected == $tag['name']?'selected':'' ?>><?php echo $tag['name']; ?></option>
|
29 |
+
<?php
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
function all_group_options($post, $selected = '') {
|
34 |
+
$all_groups = $post->form_scan_shortcode(array('type'=>'group'));
|
35 |
+
|
36 |
+
?>
|
37 |
+
<option value="-1">-- Select group --</option>
|
38 |
+
<?php
|
39 |
+
foreach ($all_groups as $tag) {
|
40 |
+
?>
|
41 |
+
<option value="<?php echo $tag['name']; ?>" <?php echo $selected == $tag['name']?'selected':'' ?>><?php echo $tag['name']; ?></option>
|
42 |
+
<?php
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
function all_operator_options($selected = 'equals') {
|
47 |
+
$all_options = array('equals', 'not equals');
|
48 |
+
foreach($all_options as $option) {
|
49 |
+
?>
|
50 |
+
<option value="<?php echo $option ?>" <?php echo $selected == $option?'selected':'' ?>><?php echo $option ?></option>
|
51 |
+
<?php
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
function all_display_options($selected = 'show') {
|
56 |
+
$all_options = array('show', 'hide');
|
57 |
+
foreach($all_options as $option) {
|
58 |
+
?>
|
59 |
+
<option value="<?php echo $option ?>" <?php echo $selected == $option?'selected':'' ?>><?php echo $option ?></option>
|
60 |
+
<?php
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
function wpcf7cf_editor_panel_conditional($form) {
|
65 |
+
|
66 |
+
$form_id = $_GET['post'];
|
67 |
+
$wpcf7cf_entries = get_post_meta($form_id,'wpcf7cf_options',true);
|
68 |
+
|
69 |
+
?>
|
70 |
+
<h3><?php echo esc_html( __( 'Conditional fields', 'wpcf7cf' ) ); ?></h3>
|
71 |
+
|
72 |
+
|
73 |
+
<div id="wpcf7cf-new-entry">
|
74 |
+
if
|
75 |
+
<select name="wpcf7cf_options[{id}][if_field]" class="if-field-select"><?php all_field_options($form); ?></select>
|
76 |
+
<select name="wpcf7cf_options[{id}][operator]"><?php all_operator_options(); ?></select>
|
77 |
+
<input name="wpcf7cf_options[{id}][if_value]" type="text" placeholder="value">
|
78 |
+
then
|
79 |
+
<select name="wpcf7cf_options[{id}][then_visibility]"><?php all_display_options() ?></select>
|
80 |
+
<select name="wpcf7cf_options[{id}][then_field]" class="then-field-select"><?php all_group_options($form); ?></select>
|
81 |
+
</div>
|
82 |
+
<a id="wpcf7cf-delete-button" class="delete-button" title="delete rule" href="#"><span class="dashicons dashicons-dismiss"></span> Remove rule</a>
|
83 |
+
<a id="wpcf7cf-add-button" title="add new rule" href="#"><span class="dashicons dashicons-plus-alt"></span> add new conditional rule</a>
|
84 |
+
|
85 |
+
<div id="wpcf7cf-entries">
|
86 |
+
<?php
|
87 |
+
$i = 0;
|
88 |
+
foreach($wpcf7cf_entries as $id => $entry) {
|
89 |
+
?>
|
90 |
+
<div class="entry" id="entry-<?php echo $i ?>">
|
91 |
+
if
|
92 |
+
<select name="wpcf7cf_options[<?php echo $i ?>][if_field]" class="if-field-select"><?php all_field_options($form, $entry['if_field']); ?></select>
|
93 |
+
<select name="wpcf7cf_options[<?php echo $i ?>][operator]"><?php all_operator_options($entry['operator']) ?></select>
|
94 |
+
<input name="wpcf7cf_options[<?php echo $i ?>][if_value]" type="text" placeholder="value" value="<?php echo $entry['if_value'] ?>">
|
95 |
+
then
|
96 |
+
<select name="wpcf7cf_options[<?php echo $i ?>][then_visibility]"><?php all_display_options($entry['then_visibility']) ?></select>
|
97 |
+
<select name="wpcf7cf_options[<?php echo $i ?>][then_field]" class="then-field-select"><?php all_group_options($form, $entry['then_field']); ?></select>
|
98 |
+
<a style="display: inline-block;" href="#" title="delete rule" class="delete-button"><span class="dashicons dashicons-dismiss"></span> Remove rule</a>
|
99 |
+
</div>
|
100 |
+
<?php
|
101 |
+
$i++;
|
102 |
+
}
|
103 |
+
?>
|
104 |
+
</div>
|
105 |
+
|
106 |
+
<script>
|
107 |
+
(function($) {
|
108 |
+
var index = $('#wpcf7cf-entries .entry').length;
|
109 |
+
|
110 |
+
$('.delete-button').click(function(){
|
111 |
+
|
112 |
+
//if (confirm('You sure?')===false) return false;
|
113 |
+
$(this).parent().remove();
|
114 |
+
return false;
|
115 |
+
|
116 |
+
});
|
117 |
+
|
118 |
+
$('#wpcf7cf-add-button').click(function(){
|
119 |
+
|
120 |
+
// if ($('#wpcf7cf-new-entry .if-field-select').val() == '-1' || $('#wpcf7cf-new-entry .then-field-select').val() == '-1') {
|
121 |
+
// alert('Please select 2 fields');
|
122 |
+
// $(this).parent().remove();
|
123 |
+
// return false;
|
124 |
+
// } else if($('#wpcf7cf-new-entry .if-field-select').val() == $('#wpcf7cf-new-entry .then-field-select').val()) {
|
125 |
+
// alert('The fields cannot be the same');
|
126 |
+
// $(this).parent().remove();
|
127 |
+
// return false;
|
128 |
+
// }
|
129 |
+
|
130 |
+
var $delete_button = $('#wpcf7cf-delete-button').clone().removeAttr('id');
|
131 |
+
$('<div class="entry" id="entry-'+index+'">'+($('#wpcf7cf-new-entry').html().replace(/{id}/g, index))+'</div>').prependTo('#wpcf7cf-entries').append($delete_button);
|
132 |
+
$delete_button.click(function(){
|
133 |
+
|
134 |
+
//if (confirm('You sure?')===false) return false;
|
135 |
+
$(this).parent().remove();
|
136 |
+
return false;
|
137 |
+
|
138 |
+
});
|
139 |
+
index++;
|
140 |
+
return false;
|
141 |
+
|
142 |
+
});
|
143 |
+
})( jQuery );
|
144 |
+
</script>
|
145 |
+
<?php
|
146 |
+
}
|
147 |
+
|
148 |
+
// define the wpcf7_save_contact_form callback
|
149 |
+
function wpcf7cf_save_contact_form( $contact_form )
|
150 |
+
{
|
151 |
+
if ( ! isset( $_POST ) || empty( $_POST ) || ! isset( $_POST['wpcf7cf_options'] ) || ! is_array( $_POST['wpcf7cf_options'] ) )
|
152 |
+
return;
|
153 |
+
$post_id = $contact_form->id();
|
154 |
+
if ( ! $post_id )
|
155 |
+
return;
|
156 |
+
|
157 |
+
unset($_POST['wpcf7cf_options']['{id}']); // remove the dummy entry
|
158 |
+
|
159 |
+
update_post_meta( $post_id, 'wpcf7cf_options', $_POST['wpcf7cf_options'] );
|
160 |
+
|
161 |
+
};
|
162 |
+
|
163 |
+
// add the action
|
164 |
+
add_action( 'wpcf7_save_contact_form', 'wpcf7cf_save_contact_form', 10, 1 );
|
contact-form-7-conditional-fields.php
ADDED
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
Plugin Name: Contact Form 7 Conditional Fields
|
4 |
+
Plugin URI: http://bdwm.be/
|
5 |
+
Description: Adds support for conditional fields to Contact Form 7. This plugin depends on Contact Form 7.
|
6 |
+
Author: Jules Colle
|
7 |
+
Version: 0.1
|
8 |
+
Author URI: http://bdwm.be/
|
9 |
+
*/
|
10 |
+
|
11 |
+
/**
|
12 |
+
* This program is free software; you can redistribute it and/or modify
|
13 |
+
* it under the terms of the GNU General Public License as published by
|
14 |
+
* the Free Software Foundation; either version 2 of the License, or
|
15 |
+
* (at your option) any later version.
|
16 |
+
*
|
17 |
+
* This program is distributed in the hope that it will be useful,
|
18 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
+
* GNU General Public License for more details.
|
21 |
+
*
|
22 |
+
* You should have received a copy of the GNU General Public License
|
23 |
+
* along with this program; if not, write to the Free Software
|
24 |
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php
|
28 |
+
|
29 |
+
define( 'WPCF7CF_VERSION', '0.1' );
|
30 |
+
define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
|
31 |
+
define( 'WPCF7CF_PLUGIN', __FILE__ );
|
32 |
+
define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
|
33 |
+
define( 'WPCF7CF_PLUGIN_NAME', trim( dirname( WPCF7CF_PLUGIN_BASENAME ), '/' ) );
|
34 |
+
define( 'WPCF7CF_PLUGIN_DIR', untrailingslashit( dirname( WPCF7CF_PLUGIN ) ) );
|
35 |
+
|
36 |
+
function wpcf7cf_plugin_path( $path = '' ) {
|
37 |
+
return path_join( WPCF7CF_PLUGIN_DIR, trim( $path, '/' ) );
|
38 |
+
}
|
39 |
+
|
40 |
+
function wpcf7cf_plugin_url( $path = '' ) {
|
41 |
+
$url = plugins_url( $path, WPCF7CF_PLUGIN );
|
42 |
+
if ( is_ssl() && 'http:' == substr( $url, 0, 5 ) ) {
|
43 |
+
$url = 'https:' . substr( $url, 5 );
|
44 |
+
}
|
45 |
+
return $url;
|
46 |
+
}
|
47 |
+
|
48 |
+
class ContactForm7ConditionalFields {
|
49 |
+
|
50 |
+
function __construct() {
|
51 |
+
|
52 |
+
add_action('wpcf7_enqueue_scripts', array(__CLASS__, 'enqueue_js'));
|
53 |
+
add_action('wpcf7_enqueue_styles', array(__CLASS__, 'enqueue_css'));
|
54 |
+
|
55 |
+
// Register shortcodes
|
56 |
+
add_action('wpcf7_init', array(__CLASS__, 'add_shortcodes'));
|
57 |
+
|
58 |
+
// Tag generator
|
59 |
+
add_action('load-contact_page_wpcf7-new', array(__CLASS__, 'tag_generator'));
|
60 |
+
add_action('load-toplevel_page_wpcf7', array(__CLASS__, 'tag_generator'));
|
61 |
+
|
62 |
+
register_activation_hook(__FILE__, array($this, 'activate'));
|
63 |
+
|
64 |
+
if (is_admin()) {
|
65 |
+
require_once dirname(__FILE__) . '/admin.php';
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
function activate() {
|
70 |
+
//add options with add_option and stuff
|
71 |
+
}
|
72 |
+
|
73 |
+
public static function enqueue_js() {
|
74 |
+
wp_enqueue_script('cf7cf-scripts', plugins_url('js/scripts.js', __FILE__), array('jquery'), '', true);
|
75 |
+
}
|
76 |
+
|
77 |
+
public static function enqueue_css() {
|
78 |
+
|
79 |
+
wp_enqueue_style('cf7cf-style', plugins_url('style.css', __FILE__));
|
80 |
+
}
|
81 |
+
|
82 |
+
public static function add_shortcodes() {
|
83 |
+
wpcf7_add_shortcode('group', array(__CLASS__, 'shortcode_handler'), true);
|
84 |
+
//add_shortcode( 'group', array(__CLASS__, 'group_shortcode_handler') );
|
85 |
+
}
|
86 |
+
|
87 |
+
function group_shortcode_handler( $atts, $content = "" ) {
|
88 |
+
return $content;
|
89 |
+
}
|
90 |
+
|
91 |
+
function shortcode_handler($tag) {
|
92 |
+
$tag = new WPCF7_Shortcode($tag);
|
93 |
+
//ob_start();
|
94 |
+
//print_r($tag);
|
95 |
+
//return print_r($tag, true);
|
96 |
+
return $tag->content;
|
97 |
+
}
|
98 |
+
|
99 |
+
|
100 |
+
public static function tag_generator() {
|
101 |
+
if (! function_exists( 'wpcf7_add_tag_generator'))
|
102 |
+
return;
|
103 |
+
|
104 |
+
wpcf7_add_tag_generator('group',
|
105 |
+
__('Conditional fields Group', 'wpcf7cf'),
|
106 |
+
'wpcf7-tg-pane-group',
|
107 |
+
array(__CLASS__, 'tg_pane')
|
108 |
+
);
|
109 |
+
}
|
110 |
+
|
111 |
+
function tg_pane( $contact_form, $args = '' ) {
|
112 |
+
$args = wp_parse_args( $args, array() );
|
113 |
+
$type = 'group';
|
114 |
+
|
115 |
+
$description = __( "Generate a group tag to group form elements that can be shown conditionally. For more details, see %s.", 'cf7cf' );
|
116 |
+
|
117 |
+
$desc_link = wpcf7_link( __( 'http://bdwm.be/cf7cf', 'cf7cf' ), __( 'Group', 'cf7cf' ) );
|
118 |
+
|
119 |
+
?>
|
120 |
+
<div class="control-box">
|
121 |
+
<fieldset>
|
122 |
+
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
123 |
+
|
124 |
+
<table class="form-table">
|
125 |
+
<tbody>
|
126 |
+
|
127 |
+
<tr>
|
128 |
+
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
129 |
+
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
130 |
+
</tr>
|
131 |
+
|
132 |
+
<tr>
|
133 |
+
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-style' ); ?>"><?php echo esc_html( __( 'Style', 'cf7cf' ) ); ?></label></th>
|
134 |
+
<td>
|
135 |
+
<fieldset>
|
136 |
+
<legend class="screen-reader-text"><?php echo esc_html( __( 'Style', 'cf7cf' ) ); ?></legend>
|
137 |
+
<select class="stylevalue oneline option" id="<?php echo esc_attr( $args['content'] . '-style' ); ?>">
|
138 |
+
<option value="" selected="selected"><?php echo esc_html( __( 'None', 'cf7cf' ) ); ?></option>
|
139 |
+
<option value="fieldset"><?php echo esc_html( __( 'Fieldset', 'cf7cf' ) ); ?></option>
|
140 |
+
</select>
|
141 |
+
</fieldset>
|
142 |
+
<input type="hidden" name="style" id="<?php echo esc_attr( $args['content'] . '-style-hidden' ); ?>" class="stylevalue oneline option">
|
143 |
+
</td>
|
144 |
+
</tr>
|
145 |
+
|
146 |
+
<tr>
|
147 |
+
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
148 |
+
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
149 |
+
</tr>
|
150 |
+
|
151 |
+
<tr>
|
152 |
+
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
153 |
+
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
154 |
+
</tr>
|
155 |
+
</tbody>
|
156 |
+
</table>
|
157 |
+
</fieldset>
|
158 |
+
</div>
|
159 |
+
|
160 |
+
<div class="insert-box">
|
161 |
+
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
162 |
+
|
163 |
+
<div class="submitbox">
|
164 |
+
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
165 |
+
</div>
|
166 |
+
|
167 |
+
<br class="clear" />
|
168 |
+
</div>
|
169 |
+
<?php
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
new ContactForm7ConditionalFields;
|
174 |
+
|
175 |
+
add_filter( 'wpcf7_contact_form_properties', 'wpcf7cf_properties', 10, 2 );
|
176 |
+
|
177 |
+
function wpcf7cf_properties($properties, $wpcf7form) {
|
178 |
+
if (!is_admin()) { // TODO: kind of hacky. maybe find a better solution. Needed because otherwise the group tags will be replaced in the editor aswell.
|
179 |
+
$form = $properties['form'];
|
180 |
+
$form = preg_replace( '/\[group (.*?)\]/s', '<div id="$1" class="wpcf7cf_group">', $form );
|
181 |
+
$form = preg_replace( '/\[\/group\]/s', '</div>', $form );
|
182 |
+
|
183 |
+
$properties['form'] = $form;
|
184 |
+
}
|
185 |
+
return $properties;
|
186 |
+
}
|
187 |
+
|
188 |
+
add_action('wpcf7_contact_form', 'wpcf7cf_enqueue_scripts', 10, 1);
|
189 |
+
function wpcf7cf_enqueue_scripts($cf7form) {
|
190 |
+
wp_localize_script('cf7cf-scripts', 'wpcf7cf_options', get_post_meta($cf7form->id,'wpcf7cf_options',true));
|
191 |
+
}
|
js/scripts.js
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function($) {
|
2 |
+
//if (wpcf7cf_options == null) var wpcf7cf_options = [];
|
3 |
+
console.log(wpcf7cf_options);
|
4 |
+
|
5 |
+
$(document).ready(function() {
|
6 |
+
function display_fields() {
|
7 |
+
console.log('display fields');
|
8 |
+
$('.wpcf7cf_group').hide();
|
9 |
+
for (var i=0; i < wpcf7cf_options.length; i++) {
|
10 |
+
|
11 |
+
var condition = wpcf7cf_options[i];
|
12 |
+
console.log(condition);
|
13 |
+
if (condition.then_visibility == 'hide') continue;
|
14 |
+
|
15 |
+
if ($('[name='+condition.if_field+']').length) {
|
16 |
+
|
17 |
+
// single field
|
18 |
+
|
19 |
+
$field = $('[name='+condition.if_field+']');
|
20 |
+
if (condition.operator == 'equals' && $field.val() == condition.if_value || condition.operator == 'not equals' && $field.val() != condition.if_value) {
|
21 |
+
$('#'+condition.then_field).show();
|
22 |
+
}
|
23 |
+
|
24 |
+
} else if ($('[name='+condition.if_field+'\\[\\]]').length) {
|
25 |
+
|
26 |
+
// multiple fields (checkboxes)
|
27 |
+
|
28 |
+
$fields = $('[name='+condition.if_field+'\\[\\]]');
|
29 |
+
|
30 |
+
var all_values = [];
|
31 |
+
var checked_values = [];
|
32 |
+
$fields.each(function() {
|
33 |
+
all_values.push($(this).val());
|
34 |
+
if($(this).is(':checked')) {
|
35 |
+
checked_values.push($(this).val());
|
36 |
+
}
|
37 |
+
});
|
38 |
+
|
39 |
+
console.log(all_values);
|
40 |
+
console.log(checked_values);
|
41 |
+
console.log(condition.operator);
|
42 |
+
console.log(condition.if_value);
|
43 |
+
console.log(condition.then_field);
|
44 |
+
|
45 |
+
if (condition.operator == 'equals' && $.inArray(condition.if_value, checked_values) != -1) {
|
46 |
+
$('#'+condition.then_field).show();
|
47 |
+
} else if (condition.operator == 'not equals' && $.inArray(condition.if_value, all_values) != -1 && $.inArray(condition.if_value, checked_values) == -1) {
|
48 |
+
$('#'+condition.then_field).show();
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
}
|
53 |
+
}
|
54 |
+
display_fields();
|
55 |
+
$('input, select, textarea').change(display_fields);
|
56 |
+
});
|
57 |
+
|
58 |
+
})( jQuery );
|
js/scripts_admin.js
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Created by jules on 7/17/2015.
|
3 |
+
*/
|
4 |
+
|
5 |
+
console.log('loading scripts_admin.js');
|
6 |
+
var old_compose = _wpcf7.taggen.compose;
|
7 |
+
|
8 |
+
(function($) {
|
9 |
+
console.log(_wpcf7.taggen.compose);
|
10 |
+
|
11 |
+
// ...before overwriting the jQuery extension point
|
12 |
+
_wpcf7.taggen.compose = function(tagType, $form)
|
13 |
+
{
|
14 |
+
|
15 |
+
$('#tag-generator-panel-group-style-hidden').val($('#tag-generator-panel-group-style').val());
|
16 |
+
|
17 |
+
// original behavior - use function.apply to preserve context
|
18 |
+
var ret = old_compose.apply(this, arguments);
|
19 |
+
//tagType = arguments[0];
|
20 |
+
//$form = arguments[1];
|
21 |
+
|
22 |
+
// START: code here will be executed after the _wpcf7.taggen.update function
|
23 |
+
if (tagType== 'group') ret += "[/group]";
|
24 |
+
// END
|
25 |
+
|
26 |
+
return ret;
|
27 |
+
};
|
28 |
+
|
29 |
+
console.log(_wpcf7.taggen.compose);
|
30 |
+
|
31 |
+
})( jQuery );
|
readme.txt
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Conditional Fields for Contact Form 7 ===
|
2 |
+
Contributors: Jules Colle
|
3 |
+
Author: Jules Colle
|
4 |
+
Website: http://bdwm.be
|
5 |
+
Tags: wordpress, contact form 7, forms, conditional fields
|
6 |
+
Requires at least: 3.6.1
|
7 |
+
Tested up to: 4.5.2
|
8 |
+
Stable tag: 0.1
|
9 |
+
License: GPLv2 or later
|
10 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
+
|
12 |
+
Adds support for conditional fields to Contact Form 7.
|
13 |
+
This plugin depends on Contact Form 7.
|
14 |
+
|
15 |
+
== Description ==
|
16 |
+
|
17 |
+
Adds conditional fields support to [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
|
18 |
+
|
19 |
+
== Installation ==
|
20 |
+
|
21 |
+
Please follow the [standard installation procedure for WordPress plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins).
|
22 |
+
|
23 |
+
== Frequently Asked Questions ==
|
24 |
+
|
25 |
+
= Why are there not more Frequently asked questions? =
|
26 |
+
|
27 |
+
Because no questions have been asked frequently about this plugin.
|
28 |
+
|
29 |
+
== Screenshots ==
|
30 |
+
|
31 |
+
1. Back End
|
32 |
+
2. Front End
|
33 |
+
|
34 |
+
== Changelog ==
|
35 |
+
|
36 |
+
= 0.1 =
|
37 |
+
|
38 |
+
First release
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|
style.css
ADDED
File without changes
|