Bootstrap for Contact Form 7 - Version 1.2.0

Version Description

  • Added: new CF7 count shortcode is now supported
  • Enhanced: form properties can now be modified without any code (i.e. without a filter); the properties can be defined in the new "Additional Settings" tab of Contact Form 7
  • Enhanced: textual inputs now support Bootstrap's input group feature
  • Enhanced: checkbox and radio types can now show an actual label; it is only used as the checkbox label if no option is provided
  • Tweaked: plugin now adheres to WordPress Coding Standards
  • Fixed: improved display method for captcha images
  • Fixed: textarea row attribute now honored
  • Fixed: free_text attribute on checkbox and radio types now honored
  • Fixed: form attribute 'group_type' now honored
  • Fixed: additional CF7 styles are now outputted in the head
  • Fixed: check if CF7 functions are available before calling them
Download this release

Release Info

Developer flixos90
Plugin Icon 128x128 Bootstrap for Contact Form 7
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.1 to 1.2.0

.editorconfig ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # WordPress Coding Standards
2
+ # http://make.wordpress.org/core/handbook/coding-standards/
3
+
4
+ root = true
5
+
6
+ [*]
7
+ charset = utf-8
8
+ end_of_line = lf
9
+ indent_size = 4
10
+ tab_width = 4
11
+ indent_style = tab
12
+ insert_final_newline = true
13
+ trim_trailing_whitespace = true
14
+
15
+ [*.md]
16
+ trim_trailing_whitespace = false
17
+ indent_style = space
18
+ indent_size = 2
19
+
20
+ [*.txt]
21
+ trim_trailing_whitespace = false
22
+
23
+ [*.json]
24
+ insert_final_newline = false
25
+ indent_style = space
26
+ indent_size = 2
27
+
28
+ [.*rc]
29
+ insert_final_newline = false
30
+ indent_style = space
31
+ indent_size = 2
32
+
33
+ [*.yml]
34
+ insert_final_newline = false
35
+ indent_style = space
36
+ indent_size = 2
assets/.jshintrc CHANGED
@@ -12,4 +12,4 @@
12
  "strict" : true,
13
  "undef" : true,
14
  "unused" : true
15
- }
12
  "strict" : true,
13
  "undef" : true,
14
  "unused" : true
15
+ }
assets/scripts.js CHANGED
@@ -1,64 +1,64 @@
1
- +function ($) {
2
- 'use strict';
3
 
4
- // add Bootstrap Alert classes to response output
5
- $(function() {
6
- $('div.wpcf7').on('invalid.wpcf7', function() {
7
- $(this).find('div.wpcf7-response-output').addClass('alert-warning');
8
- });
9
- $('div.wpcf7').on('spam.wpcf7', function() {
10
- $(this).find('div.wpcf7-response-output').addClass('alert-warning');
11
- });
12
- $('div.wpcf7').on('mailsent.wpcf7', function() {
13
- $(this).find('div.wpcf7-response-output').addClass('alert-success');
14
- });
15
- $('div.wpcf7').on('mailfailed.wpcf7', function() {
16
- $(this).find('div.wpcf7-response-output').addClass('alert-danger');
17
- });
18
- });
19
-
20
- // WPCF7 Function Override: Adjusted for Bootstrap Help Block Output and Status Class
21
- $.fn.wpcf7NotValidTip = function(message) {
22
- return this.each(function() {
23
- var $into = $(this);
24
- $into.addClass('has-error');
25
- $into.find('span.wpcf7-not-valid-tip').remove();
26
- $into.append('<span class="help-block wpcf7-not-valid-tip">' + message + '</span>');
27
- $into.slideDown('fast');
28
 
29
- if ($into.is('.use-floating-validation-tip *')) {
30
- $('.wpcf7-not-valid-tip', $into).mouseover(function() {
31
- $(this).wpcf7FadeOut();
32
- });
 
 
 
 
33
 
34
- $(':input', $into).focus(function() {
35
- $('.wpcf7-not-valid-tip', $into).not(':hidden').wpcf7FadeOut();
36
- });
37
- }
38
- });
39
- };
40
 
41
- // WPCF7 Function Override: Different DOM Element is required
42
- $.fn.wpcf7RefillQuiz = function(quiz) {
43
- return this.each(function() {
44
- var form = $(this);
 
 
45
 
46
- $.each(quiz, function(i, n) {
47
- form.find(':input[name="' + i + '"]').clearFields();
48
- form.find(':input[name="' + i + '"]').siblings('p.wpcf7-quiz-label').text(n[0]);
49
- form.find('input:hidden[name="_wpcf7_quiz_answer_' + i + '"]').attr('value', n[1]);
50
- });
51
- });
52
- };
53
 
54
- // WPCF7 Function Override: Adjusted for Bootstrap Alert classes and Status Class
55
- $.fn.wpcf7ClearResponseOutput = function() {
56
- return this.each(function() {
57
- $(this).find('div.wpcf7-response-output').hide().empty().removeClass('wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked alert-warning alert-success alert-danger').removeAttr('role');
58
- $(this).find('div.form-group').removeClass('has-error');
59
- $(this).find('span.wpcf7-not-valid-tip').remove();
60
- $(this).find('img.ajax-loader').css({ visibility: 'hidden' });
61
- });
62
- };
 
 
 
 
 
 
 
 
63
 
64
  }(jQuery);
1
+ +function ( $ ) {
2
+ 'use strict';
3
 
4
+ // add Bootstrap Alert classes to response output
5
+ $( function() {
6
+ $( 'div.wpcf7' ).on( 'invalid.wpcf7', function() {
7
+ $( this ).find( 'div.wpcf7-response-output' ).addClass( 'alert-warning' );
8
+ });
9
+ $( 'div.wpcf7' ).on( 'spam.wpcf7', function() {
10
+ $( this ).find( 'div.wpcf7-response-output' ).addClass( 'alert-warning' );
11
+ });
12
+ $( 'div.wpcf7' ).on( 'mailsent.wpcf7', function() {
13
+ $( this ).find( 'div.wpcf7-response-output' ).addClass( 'alert-success' );
14
+ });
15
+ $( 'div.wpcf7' ).on( 'mailfailed.wpcf7', function() {
16
+ $( this ).find( 'div.wpcf7-response-output' ).addClass( 'alert-danger' );
17
+ });
18
+ });
 
 
 
 
 
 
 
 
 
19
 
20
+ // WPCF7 Function Override: Adjusted for Bootstrap Help Block Output and Status Class
21
+ $.fn.wpcf7NotValidTip = function( message ) {
22
+ return this.each( function() {
23
+ var $into = $( this );
24
+ $into.addClass( 'has-error' );
25
+ $into.find( 'span.wpcf7-not-valid-tip' ).remove();
26
+ $into.append( '<span class="help-block wpcf7-not-valid-tip">' + message + '</span>' );
27
+ $into.slideDown( 'fast' );
28
 
29
+ if ( $into.is( '.use-floating-validation-tip *' ) ) {
30
+ $( '.wpcf7-not-valid-tip', $into ).mouseover( function() {
31
+ $( this ).wpcf7FadeOut();
32
+ });
 
 
33
 
34
+ $( ':input', $into ).focus( function() {
35
+ $( '.wpcf7-not-valid-tip', $into ).not( ':hidden' ).wpcf7FadeOut();
36
+ });
37
+ }
38
+ });
39
+ };
40
 
41
+ // WPCF7 Function Override: Different DOM Element is required
42
+ $.fn.wpcf7RefillQuiz = function( quiz ) {
43
+ return this.each( function() {
44
+ var form = $( this );
 
 
 
45
 
46
+ $.each( quiz, function( i, n ) {
47
+ form.find( ':input[name="' + i + '"]' ).clearFields();
48
+ form.find( ':input[name="' + i + '"]' ).siblings( 'p.wpcf7-quiz-label' ).text( n[0] );
49
+ form.find( 'input:hidden[name="_wpcf7_quiz_answer_' + i + '"]' ).attr( 'value', n[1] );
50
+ });
51
+ });
52
+ };
53
+
54
+ // WPCF7 Function Override: Adjusted for Bootstrap Alert classes and Status Class
55
+ $.fn.wpcf7ClearResponseOutput = function() {
56
+ return this.each(function() {
57
+ $( this ).find( 'div.wpcf7-response-output' ).hide().empty().removeClass( 'wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked alert-warning alert-success alert-danger' ).removeAttr( 'role' );
58
+ $( this ).find( 'div.form-group' ).removeClass( 'has-error' );
59
+ $( this ).find( 'span.wpcf7-not-valid-tip' ).remove();
60
+ $( this ).find( 'img.ajax-loader' ).css({ visibility: 'hidden' });
61
+ });
62
+ };
63
 
64
  }(jQuery);
assets/scripts.min.js CHANGED
@@ -1,5 +1,5 @@
1
  /*!
2
- * Bootstrap for Contact Form 7 Scripts - Version 1.1.1
3
  *
4
  * Modifications and Additions to WPCF7 Scripts to work with CF7BS
5
  * Felix Arntz <felix-arntz@leaves-and-love.net>
1
  /*!
2
+ * Bootstrap for Contact Form 7 Scripts - Version 1.2.0
3
  *
4
  * Modifications and Additions to WPCF7 Scripts to work with CF7BS
5
  * Felix Arntz <felix-arntz@leaves-and-love.net>
bootstrap-for-contact-form-7.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Bootstrap for Contact Form 7
4
  Plugin URI: http://wordpress.org/plugins/bootstrap-for-contact-form-7/
5
  Description: This plugin modifies the output of the popular Contact Form 7 plugin to be styled in compliance with themes using the Bootstrap CSS framework.
6
- Version: 1.1.1
7
  Author: Felix Arntz
8
  Author URI: http://leaves-and-love.net
9
  License: GNU General Public License v2
@@ -11,140 +11,131 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  */
12
  /**
13
  * @package CF7BS
14
- * @version 1.1.1
15
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
16
  */
17
 
18
- define( 'CF7BS_VERSION', '1.1.1' );
19
  define( 'CF7BS_MAINFILE', __FILE__ );
20
  define( 'CF7BS_PATH', untrailingslashit( plugin_dir_path( CF7BS_MAINFILE ) ) );
21
  define( 'CF7BS_URL', untrailingslashit( plugin_dir_url( CF7BS_MAINFILE ) ) );
22
  define( 'CF7BS_BASENAME', plugin_basename( CF7BS_MAINFILE ) );
23
 
24
- if( !defined( 'WPCF7_AUTOP' ) )
25
- {
26
- define( 'WPCF7_AUTOP', false );
27
  }
28
 
29
- function cf7bs_maybe_init()
30
- {
31
- if( defined( 'WPCF7_VERSION' ) && apply_filters( 'cf7bs_using_bootstrap', true ) )
32
- {
33
- include_once CF7BS_PATH . '/modifications.php';
34
- include_once CF7BS_PATH . '/classes/CF7BS_Component.php';
35
- include_once CF7BS_PATH . '/classes/CF7BS_Button.php';
36
- include_once CF7BS_PATH . '/classes/CF7BS_Button_Group.php';
37
- include_once CF7BS_PATH . '/classes/CF7BS_Alert.php';
38
- include_once CF7BS_PATH . '/classes/CF7BS_Form_Field.php';
39
 
40
- $modules = array(
41
- 'acceptance',
42
- 'submit',
43
- 'captcha',
44
- 'number',
45
- 'text',
46
- 'checkbox',
47
- 'quiz',
48
- 'textarea',
49
- 'date',
50
- 'file',
51
- 'select',
52
- );
53
- foreach( $modules as $module )
54
- {
55
- $file = CF7BS_PATH . '/modules/' . $module . '.php';
56
- if( file_exists( $file ) )
57
- {
58
- include_once $file;
59
- }
60
- }
61
- }
62
  }
63
  add_action( 'plugins_loaded', 'cf7bs_maybe_init', 50 );
64
 
65
  $current_form_id = 0;
66
  $current_form_properties = array();
67
 
68
- function cf7bs_get_form_property( $property, $form_id = 0 )
69
- {
70
- global $current_form_id, $current_form_properties;
71
 
72
- if( $form_id == 0 )
73
- {
74
- $current_form = WPCF7_ContactForm::get_current();
75
- if ( $current_form !== null ) {
76
- $form_id = $current_form->id();
77
- }
78
- }
 
79
 
80
- if ( $form_id == 0 ) {
81
- return false;
82
- }
83
-
84
- if( $current_form_id != $form_id )
85
- {
86
- $current_form_id = $form_id;
87
 
88
- $properties = cf7bs_get_default_form_properties();
89
- $current_form_properties = apply_filters( 'cf7bs_form_' . $form_id . '_properties', $properties );
90
- }
91
-
92
- if( isset( $current_form_properties[ $property ] ) )
93
- {
94
- return $current_form_properties[ $property ];
95
- }
96
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
 
99
- function cf7bs_get_default_form_properties()
100
- {
101
- $properties = array(
102
- 'layout' => 'default', // default, inline, horizontal
103
- 'label_width' => 3, // integer between 1 and 11
104
- 'breakpoint' => 'sm', // xs, sm, md, lg
105
- 'size' => 'default', // default, small, large
106
- 'required_html' => '<span class="required">*</span>',
107
- 'group_layout' => 'default', // default, inline, buttons
108
- 'group_type' => 'default', // default, primary, success, info, warning, danger (only if group_layout=buttons)
109
- 'submit_type' => 'primary', // default, primary, success, info, warning, danger
110
- );
111
- return apply_filters( 'cf7bs_default_form_properties', $properties );
112
  }
113
 
114
- function cf7bs_add_get_parameter()
115
- {
116
- $args = func_get_args();
117
- if( is_array( $args[0] ) )
118
- {
119
- if( count( $args ) < 2 || $args[1] === false )
120
- {
121
- $uri = $_SERVER['REQUEST_URI'];
122
- }
123
- else
124
- {
125
- $uri = $args[1];
126
- }
127
- foreach( $args[0] as $key => &$value )
128
- {
129
- $value = cf7bs_parameter_encode( $value );
130
- }
131
- return add_query_arg( $args[0], $uri );
132
- }
133
- else
134
- {
135
- if( count( $args ) < 3 || $args[2] === false )
136
- {
137
- $uri = $_SERVER['REQUEST_URI'];
138
- }
139
- else
140
- {
141
- $uri = $args[2];
142
- }
143
- if( count( $args ) < 2 )
144
- {
145
- return $uri;
146
- }
147
- return add_query_arg( $args[0], cf7bs_parameter_encode( $args[1] ), $uri );
148
- }
149
- return '';
150
  }
3
  Plugin Name: Bootstrap for Contact Form 7
4
  Plugin URI: http://wordpress.org/plugins/bootstrap-for-contact-form-7/
5
  Description: This plugin modifies the output of the popular Contact Form 7 plugin to be styled in compliance with themes using the Bootstrap CSS framework.
6
+ Version: 1.2.0
7
  Author: Felix Arntz
8
  Author URI: http://leaves-and-love.net
9
  License: GNU General Public License v2
11
  */
12
  /**
13
  * @package CF7BS
14
+ * @version 1.2.0
15
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
16
  */
17
 
18
+ define( 'CF7BS_VERSION', '1.2.0' );
19
  define( 'CF7BS_MAINFILE', __FILE__ );
20
  define( 'CF7BS_PATH', untrailingslashit( plugin_dir_path( CF7BS_MAINFILE ) ) );
21
  define( 'CF7BS_URL', untrailingslashit( plugin_dir_url( CF7BS_MAINFILE ) ) );
22
  define( 'CF7BS_BASENAME', plugin_basename( CF7BS_MAINFILE ) );
23
 
24
+ if ( ! defined( 'WPCF7_AUTOP' ) ) {
25
+ define( 'WPCF7_AUTOP', false );
 
26
  }
27
 
28
+ function cf7bs_maybe_init() {
29
+ if ( defined( 'WPCF7_VERSION' ) && apply_filters( 'cf7bs_using_bootstrap', true ) ) {
30
+ include_once CF7BS_PATH . '/modifications.php';
31
+ include_once CF7BS_PATH . '/classes/CF7BS_Component.php';
32
+ include_once CF7BS_PATH . '/classes/CF7BS_Button.php';
33
+ include_once CF7BS_PATH . '/classes/CF7BS_Button_Group.php';
34
+ include_once CF7BS_PATH . '/classes/CF7BS_Alert.php';
35
+ include_once CF7BS_PATH . '/classes/CF7BS_Form_Field.php';
 
 
36
 
37
+ $modules = array(
38
+ 'acceptance',
39
+ 'submit',
40
+ 'captcha',
41
+ 'count',
42
+ 'number',
43
+ 'text',
44
+ 'checkbox',
45
+ 'quiz',
46
+ 'textarea',
47
+ 'date',
48
+ 'file',
49
+ 'select',
50
+ );
51
+ foreach ( $modules as $module ) {
52
+ $file = CF7BS_PATH . '/modules/' . $module . '.php';
53
+ if ( file_exists( $file ) ) {
54
+ include_once $file;
55
+ }
56
+ }
57
+ }
 
58
  }
59
  add_action( 'plugins_loaded', 'cf7bs_maybe_init', 50 );
60
 
61
  $current_form_id = 0;
62
  $current_form_properties = array();
63
 
64
+ function cf7bs_get_form_property( $property, $form_id = 0 ) {
65
+ global $current_form_id, $current_form_properties;
 
66
 
67
+ if ( $form_id == 0 ) {
68
+ if ( is_callable( array( 'WPCF7_ContactForm', 'get_current' ) ) ) {
69
+ $current_form = WPCF7_ContactForm::get_current();
70
+ if ( is_a( $current_form, 'WPCF7_ContactForm' ) && is_callable( array( $current_form, 'id' ) ) ) {
71
+ $form_id = $current_form->id();
72
+ }
73
+ }
74
+ }
75
 
76
+ if ( $form_id == 0 ) {
77
+ return false;
78
+ }
 
 
 
 
79
 
80
+ if ( $current_form_id != $form_id ) {
81
+ $current_form_id = $form_id;
82
+
83
+ $properties = cf7bs_get_default_form_properties();
84
+ if ( is_a( $current_form, 'WPCF7_ContactForm' ) && is_callable( array( $current_form, 'additional_setting' ) ) ) {
85
+ foreach ( $properties as $key => &$value ) {
86
+ $setting = $current_form->additional_setting( $key );
87
+ if ( isset( $setting[0] ) ) {
88
+ $value = $setting[0];
89
+ }
90
+ }
91
+ unset( $key );
92
+ unset( $value );
93
+ }
94
+ $current_form_properties = apply_filters( 'cf7bs_form_' . $form_id . '_properties', $properties );
95
+ }
96
+
97
+ if ( isset( $current_form_properties[ $property ] ) ) {
98
+ return $current_form_properties[ $property ];
99
+ }
100
+ return false;
101
  }
102
 
103
+ function cf7bs_get_default_form_properties() {
104
+ $properties = array(
105
+ 'layout' => 'default', // default, inline, horizontal
106
+ 'label_width' => 3, // integer between 1 and 11
107
+ 'breakpoint' => 'sm', // xs, sm, md, lg
108
+ 'size' => 'default', // default, small, large
109
+ 'required_html' => '<span class="required">*</span>',
110
+ 'group_layout' => 'default', // default, inline, buttons
111
+ 'group_type' => 'default', // default, primary, success, info, warning, danger (only if group_layout=buttons)
112
+ 'submit_type' => 'primary', // default, primary, success, info, warning, danger
113
+ );
114
+ return apply_filters( 'cf7bs_default_form_properties', $properties );
 
115
  }
116
 
117
+ function cf7bs_add_get_parameter() {
118
+ $args = func_get_args();
119
+ if ( is_array( $args[0] ) ) {
120
+ if ( count( $args ) < 2 || $args[1] === false ) {
121
+ $uri = $_SERVER['REQUEST_URI'];
122
+ } else {
123
+ $uri = $args[1];
124
+ }
125
+ foreach ( $args[0] as $key => &$value ) {
126
+ $value = cf7bs_parameter_encode( $value );
127
+ }
128
+ return add_query_arg( $args[0], $uri );
129
+ } else {
130
+ if ( count( $args ) < 3 || $args[2] === false ) {
131
+ $uri = $_SERVER['REQUEST_URI'];
132
+ } else {
133
+ $uri = $args[2];
134
+ }
135
+ if ( count( $args ) < 2 ) {
136
+ return $uri;
137
+ }
138
+ return add_query_arg( $args[0], cf7bs_parameter_encode( $args[1] ), $uri );
139
+ }
140
+ return '';
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
changelog.txt CHANGED
@@ -1,5 +1,18 @@
1
  == Changelog ==
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  = 1.1.1 =
4
  * Fixed: exclusive option for checkbox now working
5
  * Fixed: default option for radio/checkbox now working
1
  == Changelog ==
2
 
3
+ = 1.2.0 =
4
+ * Added: new CF7 count shortcode is now supported
5
+ * Enhanced: form properties can now be modified without any code (i.e. without a filter); the properties can be defined in the new "Additional Settings" tab of Contact Form 7
6
+ * Enhanced: textual inputs now support Bootstrap's input group feature
7
+ * Enhanced: checkbox and radio types can now show an actual label; it is only used as the checkbox label if no option is provided
8
+ * Tweaked: plugin now adheres to WordPress Coding Standards
9
+ * Fixed: improved display method for captcha images
10
+ * Fixed: textarea row attribute now honored
11
+ * Fixed: free_text attribute on checkbox and radio types now honored
12
+ * Fixed: form attribute 'group_type' now honored
13
+ * Fixed: additional CF7 styles are now outputted in the head
14
+ * Fixed: check if CF7 functions are available before calling them
15
+
16
  = 1.1.1 =
17
  * Fixed: exclusive option for checkbox now working
18
  * Fixed: default option for radio/checkbox now working
classes/CF7BS_Alert.php CHANGED
@@ -1,99 +1,84 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- class CF7BS_Alert extends CF7BS_Component
9
- {
10
- public function open( $echo = true )
11
- {
12
- $output = apply_filters( 'cf7bs_bootstrap_alert_open', '', $this->args );
13
-
14
- if( empty( $output ) )
15
- {
16
- $output = '';
17
-
18
- extract( $this->args );
19
-
20
- $type = $this->validate_type( $type );
21
-
22
- if( !empty( $class ) )
23
- {
24
- $class .= ' ';
25
- }
26
- $class .= 'alert';
27
- if( !empty( $type ) )
28
- {
29
- $class .= ' alert-' . $type;
30
- }
31
- if( $dismissable )
32
- {
33
- $class .= ' alert-dismissable';
34
- }
35
-
36
- $output .= '<div class="' . esc_attr( $class ) . '"' . ( $hide ? ' style="display:none;"' : '' ) . '>';
37
- if( $dismissable )
38
- {
39
- $output .= '<button class="close" data-dismiss="alert" type="button">&times;</button>';
40
- }
41
- }
42
-
43
- if( $echo )
44
- {
45
- echo $output;
46
- }
47
- return $output;
48
- }
49
-
50
- public function close( $echo = true )
51
- {
52
- $output = apply_filters( 'cf7bs_bootstrap_alert_close', '', $this->args );
53
-
54
- if( empty( $output ) )
55
- {
56
- $output .= '</div>';
57
- }
58
-
59
- if( $echo )
60
- {
61
- echo $output;
62
- }
63
- return $output;
64
- }
65
-
66
- protected function validate_args( $args, $exclude = array() )
67
- {
68
- $args = parent::validate_args( $args, $exclude );
69
-
70
- return $args;
71
- }
72
-
73
- protected function get_defaults()
74
- {
75
- $defaults = array(
76
- 'type' => 'default',
77
- 'class' => '',
78
- 'dismissable' => false,
79
- 'hide' => false,
80
- );
81
- return apply_filters( 'cf7bs_bootstrap_alert_defaults', $defaults );
82
- }
83
-
84
- private function validate_type( $type )
85
- {
86
- $whitelist = array(
87
- 'success',
88
- 'info',
89
- 'warning',
90
- 'danger'
91
- );
92
-
93
- if( !in_array( $type, $whitelist ) )
94
- {
95
- $type = '';
96
- }
97
- return $type;
98
- }
99
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
+ class CF7BS_Alert extends CF7BS_Component {
9
+ public function open( $echo = true ) {
10
+ $output = apply_filters( 'cf7bs_bootstrap_alert_open', '', $this->args );
11
+
12
+ if ( empty( $output ) ) {
13
+ $output = '';
14
+
15
+ extract( $this->args );
16
+
17
+ $type = $this->validate_type( $type );
18
+
19
+ if ( ! empty( $class ) ) {
20
+ $class .= ' ';
21
+ }
22
+ $class .= 'alert';
23
+ if ( ! empty( $type ) ) {
24
+ $class .= ' alert-' . $type;
25
+ }
26
+ if ( $dismissable ) {
27
+ $class .= ' alert-dismissable';
28
+ }
29
+
30
+ $output .= '<div class="' . esc_attr( $class ) . '"' . ( $hide ? ' style="display:none;"' : '' ) . '>';
31
+ if ( $dismissable ) {
32
+ $output .= '<button class="close" data-dismiss="alert" type="button">&times;</button>';
33
+ }
34
+ }
35
+
36
+ if ( $echo ) {
37
+ echo $output;
38
+ }
39
+ return $output;
40
+ }
41
+
42
+ public function close( $echo = true ) {
43
+ $output = apply_filters( 'cf7bs_bootstrap_alert_close', '', $this->args );
44
+
45
+ if ( empty( $output ) ) {
46
+ $output .= '</div>';
47
+ }
48
+
49
+ if ( $echo ) {
50
+ echo $output;
51
+ }
52
+ return $output;
53
+ }
54
+
55
+ protected function validate_args( $args, $exclude = array() ) {
56
+ $args = parent::validate_args( $args, $exclude );
57
+
58
+ return $args;
59
+ }
60
+
61
+ protected function get_defaults() {
62
+ $defaults = array(
63
+ 'type' => 'default',
64
+ 'class' => '',
65
+ 'dismissable' => false,
66
+ 'hide' => false,
67
+ );
68
+ return apply_filters( 'cf7bs_bootstrap_alert_defaults', $defaults );
69
+ }
70
+
71
+ private function validate_type( $type ) {
72
+ $whitelist = array(
73
+ 'success',
74
+ 'info',
75
+ 'warning',
76
+ 'danger'
77
+ );
78
+
79
+ if ( ! in_array( $type, $whitelist ) ) {
80
+ $type = '';
81
+ }
82
+ return $type;
83
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
classes/CF7BS_Button.php CHANGED
@@ -1,173 +1,151 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- class CF7BS_Button extends CF7BS_Component
9
- {
10
- public function display( $echo = true )
11
- {
12
- $output = apply_filters( 'cf7bs_bootstrap_button_display', '', $this->args );
13
-
14
- if( empty( $output ) )
15
- {
16
- $output = '';
17
-
18
- extract( $this->args );
19
-
20
- $type = $this->validate_type( $type );
21
-
22
- if( !empty( $class ) )
23
- {
24
- $class .= ' ';
25
- }
26
-
27
- $class .= 'btn btn-' . $type;
28
-
29
- $sizes = array(
30
- 'mini' => 'xs',
31
- 'small' => 'sm',
32
- 'large' => 'lg',
33
- );
34
- if( isset( $sizes[ $size ] ) )
35
- {
36
- $class .= ' btn-' . $sizes[ $size ];
37
- }
38
-
39
- if( !empty( $id ) )
40
- {
41
- $id = ' id="' . esc_attr( $id ) . '"';
42
- }
43
-
44
- if( !empty( $name ) )
45
- {
46
- $name = ' name="' . esc_attr( $name ) . '"';
47
- }
48
-
49
- if( $mode == 'checkbox' )
50
- {
51
- $output .= '<label class="' . esc_attr( $class ) . '"><input' . $id . $name . ' type="checkbox" value="' . esc_attr( $value ) . '"' . $append . '>' . esc_html( $title ) . '</label>';
52
- }
53
- elseif( $mode == 'radio' )
54
- {
55
- $output .= '<label class="' . esc_attr( $class ) . '"><input' . $id . $name . ' type="radio" value="' . esc_attr( $value ) . '"' . $append . '>' . esc_html( $title ) . '</label>';
56
- }
57
- else
58
- {
59
- $wrapper_class = array();
60
-
61
- if( $align && $form_layout != 'inline' )
62
- {
63
- $wrapper_class[] = 'text-' . $align;
64
- }
65
-
66
- if( $form_layout == 'horizontal' )
67
- {
68
- $wrapper_class[] = $this->get_column_class( $form_label_width, $form_breakpoint );
69
- }
70
-
71
- $wrapper_class = implode( ' ', $wrapper_class );
72
-
73
- if( !empty( $wrapper_class ) )
74
- {
75
- $wrapper_class = ' class="' . $wrapper_class . '"';
76
- }
77
-
78
- if( is_int( $tabindex ) )
79
- {
80
- $tabindex = ' tabindex="' . $tabindex . '"';
81
- }
82
- else
83
- {
84
- $tabindex = '';
85
- }
86
- $output .= '<div class="form-group"><div' . $wrapper_class . '>';
87
- $output .= '<input class="' . esc_attr( $class ) . '"' . $id . $name . ' type="submit" value="' . esc_attr( $title ) . '"' . $tabindex . '>';
88
- $output .= '</div></div>';
89
- }
90
- }
91
-
92
- if( $echo )
93
- {
94
- echo $output;
95
- }
96
- return $output;
97
- }
98
-
99
- protected function validate_args( $args, $exclude = array() )
100
- {
101
- $exclude[] = 'tabindex';
102
- $exclude[] = 'align';
103
- $args = parent::validate_args( $args, $exclude );
104
-
105
- if( is_string( $args['align'] ) )
106
- {
107
- $args['align'] = strtolower( $args['align'] );
108
- }
109
-
110
- if( !in_array( $args['align'], array( 'left', 'center', 'right' ) ) )
111
- {
112
- $args['align'] = false;
113
- }
114
-
115
- // type whitelist check is made later in the display() function to allow different types to use in a filter
116
-
117
- return $args;
118
- }
119
-
120
- protected function get_defaults()
121
- {
122
- $defaults = array(
123
- 'type' => 'default',
124
- 'size' => 'default', // default, large, small, mini
125
- 'mode' => 'submit', // checkbox, radio, submit
126
- 'id' => '',
127
- 'class' => '',
128
- 'title' => 'Button Title',
129
- 'name' => '',
130
- 'append' => '', // for checkbox/radio only
131
- 'value' => '', // for checkbox/radio only
132
- 'tabindex' => false,
133
- 'align' => false,
134
- 'form_layout' => 'default', // default, inline, horizontal
135
- 'form_label_width' => 2,
136
- 'form_breakpoint' => 'sm',
137
- );
138
- return apply_filters( 'cf7bs_bootstrap_button_defaults', $defaults );
139
- }
140
-
141
- private function validate_type( $type )
142
- {
143
- $whitelist = array(
144
- 'default',
145
- 'primary',
146
- 'info',
147
- 'success',
148
- 'warning',
149
- 'danger',
150
- 'link'
151
- );
152
-
153
- $type = strtolower( $type );
154
- if( !in_array( $type, $whitelist ) )
155
- {
156
- $type = 'default';
157
- }
158
- return $type;
159
- }
160
-
161
- private function get_column_class( $label_column_width = 2, $breakpoint = 'sm' )
162
- {
163
- if( $label_column_width > 11 || $label_column_width < 1 )
164
- {
165
- $label_column_width = 2;
166
- }
167
- if( !in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) )
168
- {
169
- $breakpoint = 'sm';
170
- }
171
- return 'col-' . $breakpoint . '-' . ( 12 - $label_column_width ) . ' col-' . $breakpoint . '-offset-' . $label_column_width;
172
- }
173
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
+ class CF7BS_Button extends CF7BS_Component {
9
+ public function display( $echo = true ) {
10
+ $output = apply_filters( 'cf7bs_bootstrap_button_display', '', $this->args );
11
+
12
+ if ( empty( $output ) ) {
13
+ $output = '';
14
+
15
+ extract( $this->args );
16
+
17
+ $type = $this->validate_type( $type );
18
+
19
+ if ( ! empty( $class ) ) {
20
+ $class .= ' ';
21
+ }
22
+
23
+ $class .= 'btn btn-' . $type;
24
+
25
+ $sizes = array(
26
+ 'mini' => 'xs',
27
+ 'small' => 'sm',
28
+ 'large' => 'lg',
29
+ );
30
+ if ( isset( $sizes[ $size ] ) ) {
31
+ $class .= ' btn-' . $sizes[ $size ];
32
+ }
33
+
34
+ if ( ! empty( $id ) ) {
35
+ $id = ' id="' . esc_attr( $id ) . '"';
36
+ }
37
+
38
+ if ( ! empty( $name ) ) {
39
+ $name = ' name="' . esc_attr( $name ) . '"';
40
+ }
41
+
42
+ if ( 'checkbox' == $mode ) {
43
+ if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
44
+ $title = esc_html( $title );
45
+ }
46
+ $output .= '<label class="' . esc_attr( $class ) . '"><input' . $id . $name . ' type="checkbox" value="' . esc_attr( $value ) . '"' . $append . '>' . $title . '</label>';
47
+ } elseif ( 'radio' == $mode ) {
48
+ if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
49
+ $title = esc_html( $title );
50
+ }
51
+ $output .= '<label class="' . esc_attr( $class ) . '"><input' . $id . $name . ' type="radio" value="' . esc_attr( $value ) . '"' . $append . '>' . $title . '</label>';
52
+ } else {
53
+ $wrapper_class = array();
54
+
55
+ if ( $align && 'inline' != $form_layout ) {
56
+ $wrapper_class[] = 'text-' . $align;
57
+ }
58
+
59
+ if ( 'horizontal' == $form_layout ) {
60
+ $wrapper_class[] = $this->get_column_class( $form_label_width, $form_breakpoint );
61
+ }
62
+
63
+ $wrapper_class = implode( ' ', $wrapper_class );
64
+
65
+ if ( ! empty( $wrapper_class ) ) {
66
+ $wrapper_class = ' class="' . $wrapper_class . '"';
67
+ }
68
+
69
+ if ( is_int( $tabindex ) ) {
70
+ $tabindex = ' tabindex="' . $tabindex . '"';
71
+ } else {
72
+ $tabindex = '';
73
+ }
74
+ $output .= '<div class="form-group"><div' . $wrapper_class . '>';
75
+ $output .= '<input class="' . esc_attr( $class ) . '"' . $id . $name . ' type="submit" value="' . esc_attr( $title ) . '"' . $tabindex . '>';
76
+ $output .= '</div></div>';
77
+ }
78
+ }
79
+
80
+ if ( $echo ) {
81
+ echo $output;
82
+ }
83
+ return $output;
84
+ }
85
+
86
+ protected function validate_args( $args, $exclude = array() ) {
87
+ $exclude[] = 'tabindex';
88
+ $exclude[] = 'align';
89
+ $args = parent::validate_args( $args, $exclude );
90
+
91
+ if ( is_string( $args['align'] ) ) {
92
+ $args['align'] = strtolower( $args['align'] );
93
+ }
94
+
95
+ if ( ! in_array( $args['align'], array( 'left', 'center', 'right' ) ) ) {
96
+ $args['align'] = false;
97
+ }
98
+
99
+ // type whitelist check is made later in the display() function to allow different types to use in a filter
100
+
101
+ return $args;
102
+ }
103
+
104
+ protected function get_defaults() {
105
+ $defaults = array(
106
+ 'type' => 'default',
107
+ 'size' => 'default', // default, large, small, mini
108
+ 'mode' => 'submit', // checkbox, radio, submit
109
+ 'id' => '',
110
+ 'class' => '',
111
+ 'title' => 'Button Title',
112
+ 'name' => '',
113
+ 'append' => '', // for checkbox/radio only
114
+ 'value' => '', // for checkbox/radio only
115
+ 'tabindex' => false,
116
+ 'align' => false,
117
+ 'form_layout' => 'default', // default, inline, horizontal
118
+ 'form_label_width' => 2,
119
+ 'form_breakpoint' => 'sm',
120
+ );
121
+ return apply_filters( 'cf7bs_bootstrap_button_defaults', $defaults );
122
+ }
123
+
124
+ private function validate_type( $type ) {
125
+ $whitelist = array(
126
+ 'default',
127
+ 'primary',
128
+ 'info',
129
+ 'success',
130
+ 'warning',
131
+ 'danger',
132
+ 'link',
133
+ );
134
+
135
+ $type = strtolower( $type );
136
+ if ( ! in_array( $type, $whitelist ) ) {
137
+ $type = 'default';
138
+ }
139
+ return $type;
140
+ }
141
+
142
+ private function get_column_class( $label_column_width = 2, $breakpoint = 'sm' ) {
143
+ if ( $label_column_width > 11 || $label_column_width < 1 ) {
144
+ $label_column_width = 2;
145
+ }
146
+ if ( ! in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) ) {
147
+ $breakpoint = 'sm';
148
+ }
149
+ return 'col-' . $breakpoint . '-' . ( 12 - $label_column_width ) . ' col-' . $breakpoint . '-offset-' . $label_column_width;
150
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  }
classes/CF7BS_Button_Group.php CHANGED
@@ -1,115 +1,97 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- class CF7BS_Button_Group extends CF7BS_Component
9
- {
10
- private $buttons = array();
11
-
12
- public function open( $echo = true )
13
- {
14
- $output = apply_filters( 'cf7bs_bootstrap_button_group_open', '', $this->args );
15
-
16
- if( empty( $output ) )
17
- {
18
- $output = '';
19
-
20
- extract( $this->args );
21
-
22
- $class = 'btn-group';
23
-
24
- if( $layout == 'vertical' )
25
- {
26
- $class .= '-vertical';
27
- }
28
- elseif( $layout == 'justified' )
29
- {
30
- $class .= ' btn-group-justified';
31
- }
32
-
33
- $sizes = array(
34
- 'mini' => 'xs',
35
- 'small' => 'sm',
36
- 'large' => 'lg',
37
- );
38
- if( isset( $sizes[ $size ] ) )
39
- {
40
- $class .= ' btn-group-' . $sizes[ $size ];
41
- }
42
-
43
- if( !empty( $id ) )
44
- {
45
- $id = ' id="' . $id . '"';
46
- }
47
-
48
- $toggle = '';
49
- if( in_array( $mode, array( 'checkbox', 'radio' ) ) )
50
- {
51
- $toggle = ' data-toggle="buttons"';
52
- }
53
-
54
- $output .= '<div class="' . $class . '"' . $id . $toggle . '>';
55
- }
56
-
57
- if( $echo )
58
- {
59
- echo $output;
60
- }
61
- return $output;
62
- }
63
-
64
- public function close( $echo = true )
65
- {
66
- $output = apply_filters( 'cf7bs_bootstrap_button_group_close', '', $this->args );
67
-
68
- if( empty( $output ) )
69
- {
70
- $output = '</div>';
71
- }
72
-
73
- if( $echo )
74
- {
75
- echo $output;
76
- }
77
- return $output;
78
- }
79
-
80
- public function insert_button( $args = array(), $echo = true, $shortcode_tag = '' )
81
- {
82
- $args = (array) $args;
83
- $args['size'] = 'default'; // size is defined in button group, so set it to 'default' on button
84
- if( in_array( $this->args['mode'], array( 'checkbox', 'radio' ) ) )
85
- {
86
- $args['mode'] = $this->args['mode'];
87
- }
88
- $temp = new CF7BS_Button( $args, $shortcode_tag );
89
- $this->buttons[] = $temp;
90
- return $temp->display( $echo );
91
- }
92
-
93
- protected function validate_args( $args, $exclude = array() )
94
- {
95
- $args = parent::validate_args( $args, $exclude );
96
-
97
- return $args;
98
- }
99
-
100
- protected function get_defaults()
101
- {
102
- $defaults = array(
103
- 'mode' => 'default', // default, checkbox, radio
104
- 'size' => 'default', // default, large, small, mini
105
- 'layout' => 'default', // default, vertical, justified
106
- 'id' => '',
107
- );
108
- return apply_filters( 'cf7bs_bootstrap_button_group_defaults', $defaults );
109
- }
110
-
111
- public function get_contents()
112
- {
113
- return $this->buttons;
114
- }
115
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
+ class CF7BS_Button_Group extends CF7BS_Component {
9
+ private $buttons = array();
10
+
11
+ public function open( $echo = true ) {
12
+ $output = apply_filters( 'cf7bs_bootstrap_button_group_open', '', $this->args );
13
+
14
+ if ( empty( $output ) ) {
15
+ $output = '';
16
+
17
+ extract( $this->args );
18
+
19
+ $class = 'btn-group';
20
+
21
+ if ( 'vertical' == $layout ) {
22
+ $class .= '-vertical';
23
+ } elseif( 'justified' == $layout ) {
24
+ $class .= ' btn-group-justified';
25
+ }
26
+
27
+ $sizes = array(
28
+ 'mini' => 'xs',
29
+ 'small' => 'sm',
30
+ 'large' => 'lg',
31
+ );
32
+ if ( isset( $sizes[ $size ] ) ) {
33
+ $class .= ' btn-group-' . $sizes[ $size ];
34
+ }
35
+
36
+ if ( ! empty( $id ) ) {
37
+ $id = ' id="' . $id . '"';
38
+ }
39
+
40
+ $toggle = '';
41
+ if ( in_array( $mode, array( 'checkbox', 'radio' ) ) ) {
42
+ $toggle = ' data-toggle="buttons"';
43
+ }
44
+
45
+ $output .= '<div class="' . $class . '"' . $id . $toggle . '>';
46
+ }
47
+
48
+ if ( $echo ) {
49
+ echo $output;
50
+ }
51
+ return $output;
52
+ }
53
+
54
+ public function close( $echo = true ) {
55
+ $output = apply_filters( 'cf7bs_bootstrap_button_group_close', '', $this->args );
56
+
57
+ if ( empty( $output ) ) {
58
+ $output = '</div>';
59
+ }
60
+
61
+ if ( $echo ) {
62
+ echo $output;
63
+ }
64
+ return $output;
65
+ }
66
+
67
+ public function insert_button( $args = array(), $echo = true, $shortcode_tag = '' ) {
68
+ $args = (array) $args;
69
+ $args['size'] = 'default'; // size is defined in button group, so set it to 'default' on button
70
+ if ( in_array( $this->args['mode'], array( 'checkbox', 'radio' ) ) ) {
71
+ $args['mode'] = $this->args['mode'];
72
+ }
73
+ $temp = new CF7BS_Button( $args, $shortcode_tag );
74
+ $this->buttons[] = $temp;
75
+ return $temp->display( $echo );
76
+ }
77
+
78
+ protected function validate_args( $args, $exclude = array() ) {
79
+ $args = parent::validate_args( $args, $exclude );
80
+
81
+ return $args;
82
+ }
83
+
84
+ protected function get_defaults() {
85
+ $defaults = array(
86
+ 'mode' => 'default', // default, checkbox, radio
87
+ 'size' => 'default', // default, large, small, mini
88
+ 'layout' => 'default', // default, vertical, justified
89
+ 'id' => '',
90
+ );
91
+ return apply_filters( 'cf7bs_bootstrap_button_group_defaults', $defaults );
92
+ }
93
+
94
+ public function get_contents() {
95
+ return $this->buttons;
96
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
classes/CF7BS_Component.php CHANGED
@@ -1,61 +1,45 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- abstract class CF7BS_Component
9
- {
10
- protected $args = array();
11
-
12
- public function __construct( $args = array() )
13
- {
14
- $this->args = $this->validate_args( $args );
15
- }
16
-
17
- protected function validate_args( $args, $exclude = array() )
18
- {
19
- $defaults = $this->get_defaults();
20
- $args = wp_parse_args( $args, $defaults );
21
- foreach( $defaults as $key => $value )
22
- {
23
- if( !in_array( $key, $exclude ) )
24
- {
25
- if( is_string( $value ) )
26
- {
27
- $args[ $key ] = (string) $args[ $key ];
28
- }
29
- elseif( is_int( $value ) )
30
- {
31
- $args[ $key ] = intval( $args[ $key ] );
32
- }
33
- elseif( is_float( $value ) )
34
- {
35
- $args[ $key ] = floatval( $args[ $key ] );
36
- }
37
- elseif( is_bool( $value ) )
38
- {
39
- $args[ $key ] = (bool) $args[ $key ];
40
- }
41
- elseif( is_array( $value ) )
42
- {
43
- $args[ $key ] = (array) $args[ $key ];
44
- }
45
- elseif( is_object( $value ) )
46
- {
47
- $args[ $key ] = (object) $args[ $key ];
48
- }
49
- }
50
- }
51
-
52
- return $args;
53
- }
54
-
55
- protected abstract function get_defaults();
56
-
57
- public function get_args()
58
- {
59
- return $this->args;
60
- }
61
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
+ abstract class CF7BS_Component {
9
+ protected $args = array();
10
+
11
+ public function __construct( $args = array() ) {
12
+ $this->args = $this->validate_args( $args );
13
+ }
14
+
15
+ protected function validate_args( $args, $exclude = array() ) {
16
+ $defaults = $this->get_defaults();
17
+ $args = wp_parse_args( $args, $defaults );
18
+ foreach ( $defaults as $key => $value ) {
19
+ if ( ! in_array( $key, $exclude ) ) {
20
+ if ( is_string( $value ) ) {
21
+ $args[ $key ] = (string) $args[ $key ];
22
+ } elseif ( is_int( $value ) ) {
23
+ $args[ $key ] = intval( $args[ $key ] );
24
+ } elseif ( is_float( $value ) ) {
25
+ $args[ $key ] = floatval( $args[ $key ] );
26
+ } elseif ( is_bool( $value ) ) {
27
+ $args[ $key ] = (bool) $args[ $key ];
28
+ } elseif ( is_array( $value ) ) {
29
+ $args[ $key ] = (array) $args[ $key ];
30
+ } elseif ( is_object( $value ) ) {
31
+ $args[ $key ] = (object) $args[ $key ];
32
+ }
33
+ }
34
+ }
35
+
36
+ return $args;
37
+ }
38
+
39
+ protected abstract function get_defaults();
40
+
41
+ public function get_args()
42
+ {
43
+ return $this->args;
44
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  }
classes/CF7BS_Form_Field.php CHANGED
@@ -1,582 +1,481 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- class CF7BS_Form_Field extends CF7BS_Component
9
- {
10
- public function display( $echo = true )
11
- {
12
- $output = apply_filters( 'cf7bs_bootstrap_form_field_display', '', $this->args );
13
-
14
- if( empty( $output ) )
15
- {
16
- $output = '';
17
-
18
- extract( $this->args );
19
-
20
- $type = $this->validate_type( $type );
21
-
22
- $value = $this->validate_value( $value, $type, $options );
23
-
24
- if( $type != 'hidden' )
25
- {
26
- $label_class = 'control-label';
27
- $input_div_class = '';
28
- $input_class = $class;
29
- if( $form_layout == 'horizontal' )
30
- {
31
- $classes = $this->get_column_width_classes( $form_label_width, $form_breakpoint );
32
- $label_class .= ' ' . $classes['label'];
33
- $input_div_class = $classes['input'];
34
- if( empty( $label ) || in_array( $type, array( 'radio', 'checkbox' ) ) && count( $options ) <= 1 )
35
- {
36
- $input_div_class .= ' ' . $this->get_column_offset_class( $form_label_width, $form_breakpoint );
37
- }
38
- }
39
- elseif( $form_layout == 'inline' )
40
- {
41
- if( empty( $placeholder ) )
42
- {
43
- $placeholder = $label;
44
- }
45
- }
46
-
47
- if( !empty( $wrapper_class ) )
48
- {
49
- $wrapper_class = ' ' . esc_attr( $wrapper_class );
50
- }
51
-
52
- if( !in_array( $type, array( 'radio', 'checkbox' ) ) )
53
- {
54
- if( !empty( $input_class ) )
55
- {
56
- $input_class .= ' ';
57
- }
58
- if( !in_array( $type, array( 'file', 'range' ) ) )
59
- {
60
- $input_class .= 'form-control';
61
- }
62
-
63
- if( $type != 'textarea' )
64
- {
65
- if( $size == 'large' )
66
- {
67
- $input_class .= ' input-lg';
68
- }
69
- elseif( $size == 'small' || $size == 'mini' )
70
- {
71
- $input_class .= ' input-sm';
72
- }
73
- }
74
-
75
- if( is_int( $tabindex ) )
76
- {
77
- $tabindex = ' tabindex="' . $tabindex . '"';
78
- }
79
- else
80
- {
81
- $tabindex = '';
82
- }
83
- }
84
-
85
- if( !empty( $input_class ) )
86
- {
87
- $input_class = ' class="' . esc_attr( $input_class ) . '"';
88
- }
89
- if( !empty( $placeholder ) )
90
- {
91
- $placeholder = ' placeholder="' . esc_attr( $placeholder ) . '"';
92
- }
93
-
94
- if( $readonly )
95
- {
96
- $readonly = ' readonly';
97
- }
98
- else
99
- {
100
- $readonly = '';
101
- }
102
- if( $maxlength > -1 && !empty( $maxlength ) )
103
- {
104
- $maxlength = ' maxlength="' . absint( $maxlength ) . '"';
105
- }
106
- else
107
- {
108
- $maxlength = '';
109
- }
110
-
111
- $append = '';
112
- if( $mode == 'required' )
113
- {
114
- $append = ' required';
115
- }
116
- elseif( $mode == 'disabled' )
117
- {
118
- $append = ' disabled';
119
- }
120
-
121
- $label_required = '';
122
- if( $mode == 'required' )
123
- {
124
- $label_required = ' ' . cf7bs_get_form_property( 'required_html' );
125
- }
126
-
127
- if( in_array( $status, array( 'success', 'warning', 'error' ) ) )
128
- {
129
- $status = ' has-' . $status;
130
- }
131
- else
132
- {
133
- $status = '';
134
- }
135
-
136
- if( $form_layout == 'horizontal' )
137
- {
138
- $output .= '<div class="form-group' . $wrapper_class . $status . '">';
139
- if( !empty( $label ) && ( !in_array( $type, array( 'radio', 'checkbox' ) ) || count( $options ) > 1 ) )
140
- {
141
- $output .= '<label class="' . esc_attr( $label_class ) . '" for="' . esc_attr( $id ) . '">' . esc_html( $label ) . $label_required . '</label>';
142
- }
143
- $output .= '<div class="' . esc_attr( $input_div_class ) . '">';
144
- }
145
- elseif( $form_layout == 'inline' )
146
- {
147
- if( !in_array( $type, array( 'radio', 'checkbox' ) ) || count( $options ) > 1 )
148
- {
149
- $output .= '<div class="form-group' . $wrapper_class . $status . '">';
150
- if( !empty( $label ) )
151
- {
152
- $output .= '<label class="sr-only" for="' . esc_attr( $id ) . '">' . esc_html( $label ) . $label_required . '</label>';
153
- }
154
- }
155
- }
156
- else
157
- {
158
- if( !in_array( $type, array( 'radio', 'checkbox' ) ) || count( $options ) > 1 )
159
- {
160
- $output .= '<div class="form-group' . $wrapper_class . $status . '">';
161
- if( !empty( $label ) )
162
- {
163
- $rc_group_style = '';
164
- if( in_array( $type, array( 'radio', 'checkbox' ) ) )
165
- {
166
- $rc_group_style = ' style="display:block;"';
167
- }
168
- $output .= '<label for="' . esc_attr( $id ) . '"' . $rc_group_style . '>' . esc_html( $label ) . $label_required . '</label>';
169
- }
170
- }
171
- }
172
- }
173
-
174
- switch( $type )
175
- {
176
- case 'checkbox':
177
- if( count( $options ) <= 1 )
178
- {
179
- if( count( $options ) < 1 )
180
- {
181
- $curval = 'true';
182
- $title = $label;
183
- }
184
- else
185
- {
186
- reset( $options );
187
- $curval = key( $options );
188
- $title = $options[ $curval ];
189
- }
190
- $output .= '<div class="checkbox' . $wrapper_class . '">';
191
- $output .= '<label>';
192
- $output .= '<input' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="checkbox" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . $tabindex . '"' : '' ) . $append . '>';
193
- $output .= esc_html( $title );
194
- $output .= '</label>';
195
- $output .= '</div>';
196
- }
197
- else
198
- {
199
- if( $group_layout == 'buttons' )
200
- {
201
- $button_group = new CF7BS_Button_Group( array(
202
- 'mode' => 'checkbox',
203
- 'size' => $size,
204
- ) );
205
- $output .= $button_group->open( false );
206
- $counter = 0;
207
- foreach( $options as $curval => $title )
208
- {
209
- $is_checked = cf7bs_multiple_checked( $value, $curval, false );
210
- $output .= $button_group->insert_button( array(
211
- 'type' => $group_type,
212
- 'id' => $id . ( $counter + 1 ),
213
- 'name' => $name . '[]',
214
- 'class' => $class,
215
- 'value' => $curval,
216
- 'title' => $title,
217
- 'append' => ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $is_checked . $append,
218
- ), false );
219
- $counter++;
220
- }
221
- $output .= $button_group->close( false );
222
- }
223
- elseif( $group_layout == 'inline' && $form_layout != 'inline' )
224
- {
225
- $counter = 0;
226
- foreach( $options as $curval => $title )
227
- {
228
- $output .= '<label class="checkbox-inline">';
229
- $output .= '<input' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name . '[]' ) . '" type="checkbox" value="' . esc_attr( $curval ) . '"' . cf7bs_multiple_checked( $value, $curval, false ) . ( $tabindex >= 0 ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
230
- $output .= esc_html( $title );
231
- $output .= '</label>';
232
- $counter++;
233
- }
234
- }
235
- else
236
- {
237
- $counter = 0;
238
- foreach( $options as $curval => $title )
239
- {
240
- $output .= '<div class="checkbox">';
241
- $output .= '<label>';
242
- $output .= '<input' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name . '[]' ) . '" type="checkbox" value="' . esc_attr( $curval ) . '"' . cf7bs_multiple_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
243
- $output .= esc_html( $title );
244
- $output .= '</label>';
245
- $output .= '</div>';
246
- $counter++;
247
- }
248
- }
249
- }
250
- break;
251
- case 'select':
252
- $output .= '<select' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '"' . $tabindex . $append . '>';
253
- foreach( $options as $curval => $title )
254
- {
255
- $output .= '<option value="' . esc_attr( $curval ) . '"' . cf7bs_selected( $value, $curval, false ) . '>' . esc_html( $title ) . '</option>';
256
- }
257
- $output .= '</select>';
258
- break;
259
- case 'multiselect':
260
- $output .= '<select' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name . '[]' ) . '" multiple' . $tabindex . $append . '>';
261
- foreach( $options as $curval => $title )
262
- {
263
- $output .= '<option value="' . esc_attr( $curval ) . '"' . cf7bs_multiple_selected( $value, $curval, false ) . '>' . esc_html( $title ) . '</option>';
264
- }
265
- $output .= '</select>';
266
- break;
267
- case 'radio':
268
- if( count( $options ) <= 1 )
269
- {
270
- if( count( $options ) < 1 )
271
- {
272
- $curval = 'true';
273
- $title = $label;
274
- }
275
- else
276
- {
277
- reset( $options );
278
- $curval = key( $options );
279
- $title = $options[ $curval ];
280
- }
281
- $output .= '<div class="radio' . $wrapper_class . '">';
282
- $output .= '<label>';
283
- $output .= '<input' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="radio" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . $tabindex . '"' : '' ) . $append . '>';
284
- $output .= esc_html( $title );
285
- $output .= '</label>';
286
- $output .= '</div>';
287
- }
288
- else
289
- {
290
- if( $group_layout == 'buttons' )
291
- {
292
- $button_group = new CF7BS_Button_Group( array(
293
- 'mode' => 'radio',
294
- 'size' => $size,
295
- ) );
296
- $output .= $button_group->open( false );
297
- $counter = 0;
298
- foreach( $options as $curval => $title )
299
- {
300
- $is_checked = cf7bs_checked( $value, $curval, false );
301
- $output .= $button_group->insert_button( array(
302
- 'type' => $group_type,
303
- 'id' => $id . ( $counter + 1 ),
304
- 'name' => $name,
305
- 'class' => $class,
306
- 'value' => $curval,
307
- 'title' => $title,
308
- 'append' => ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $is_checked . $append,
309
- ), false );
310
- $counter++;
311
- }
312
- $output .= $button_group->close( false );
313
- }
314
- elseif( $group_layout == 'inline' && $form_layout != 'inline' )
315
- {
316
- $counter = 0;
317
- foreach( $options as $curval => $title )
318
- {
319
- $output .= '<label class="radio-inline">';
320
- $output .= '<input' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="radio" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( $tabindex >= 0 ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
321
- $output .= esc_html( $title );
322
- $output .= '</label>';
323
- $counter++;
324
- }
325
- }
326
- else
327
- {
328
- $counter = 0;
329
- foreach( $options as $curval => $title )
330
- {
331
- $output .= '<div class="radio">';
332
- $output .= '<label>';
333
- $output .= '<input' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="radio" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
334
- $output .= esc_html( $title );
335
- $output .= '</label>';
336
- $output .= '</div>';
337
- $counter++;
338
- }
339
- }
340
- }
341
- break;
342
- case 'textarea':
343
- $output .= '<textarea' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" rows="' . absint( $rows ) . '"' . $placeholder . $readonly . $tabindex . $append . '>';
344
- $output .= esc_textarea( $value );
345
- $output .= '</textarea>';
346
- break;
347
- case 'file':
348
- $output .= '<input' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="file"' . $tabindex . $append . '>';
349
- break;
350
- case 'hidden':
351
- $output .= '<input' . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="hidden" value="' . esc_attr( $value ) . '">';
352
- break;
353
- case 'number':
354
- case 'range':
355
- case 'date':
356
- case 'datetime':
357
- case 'datetime-local':
358
- case 'month':
359
- case 'time':
360
- case 'week':
361
- $min = '';
362
- if( isset( $options['min'] ) )
363
- {
364
- $min = ' min="' . esc_attr( $options['min'] ) . '"';
365
- }
366
- $max = '';
367
- if( isset( $options['max'] ) )
368
- {
369
- $max = ' max="' . esc_attr( $options['max'] ) . '"';
370
- }
371
- $step = '';
372
- if( isset( $options['step'] ) )
373
- {
374
- $step = ' step="' . esc_attr( $options['step'] ) . '"';
375
- }
376
- $output .= '<input' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="' . esc_attr( $type ) . '" value="' . esc_attr( $value ) . '"' . $placeholder . $min . $max . $step . $readonly . $tabindex . $append . '>';
377
- break;
378
- default:
379
- if( $mode == 'static' )
380
- {
381
- $output .= '<p class="form-control-static">' . esc_html( $value ) . '</p>';
382
- }
383
- else
384
- {
385
- if( !empty( $input_before ) || !empty( $input_after ) )
386
- {
387
- $input_group_class = 'input-group';
388
- if( strpos( $input_class, ' input-lg') !== false )
389
- {
390
- $input_class = str_replace( ' input-lg', '', $input_class );
391
- $input_group_class .= ' input-group-lg';
392
- }
393
- elseif( strpos( $input_class, ' input-sm') !== false )
394
- {
395
- $input_class = str_replace( ' input-sm', '', $input_class );
396
- $input_group_class .= ' input-group-sm';
397
- }
398
- $output .= '<div class="' . $input_group_class . '">';
399
- if( !empty( $input_before ) )
400
- {
401
- $output .= '<span class="' . esc_attr( $input_before_class ) . '">';
402
- $output .= $input_before;
403
- $output .= '</span>';
404
- }
405
- }
406
-
407
- $output .= '<input' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="' . esc_attr( $type ) . '" value="' . esc_attr( $value ) . '"' . $placeholder . $readonly . $maxlength . $tabindex . $append . '>';
408
-
409
- if( !empty( $input_before ) || !empty( $input_after ) )
410
- {
411
- if( !empty( $input_after ) )
412
- {
413
- $output .= '<span class="' . esc_attr( $input_after_class ) . '">';
414
- $output .= $input_after;
415
- $output .= '</span>';
416
- }
417
- $output .= '</div>';
418
- }
419
- }
420
- break;
421
- }
422
-
423
- if( $type != 'hidden' )
424
- {
425
- if( !empty( $help_text ) && $form_layout != 'inline' )
426
- {
427
- $output .= '<span class="help-block">' . $help_text . '</span>';
428
- }
429
-
430
- if( $form_layout == 'horizontal' )
431
- {
432
- $output .= '</div>';
433
- $output .= '</div>';
434
- }
435
- else
436
- {
437
- if( !in_array( $type, array( 'radio', 'checkbox' ) ) || count( $options ) > 1 )
438
- {
439
- $output .= '</div>';
440
- }
441
- }
442
- }
443
- }
444
-
445
- if( $echo )
446
- {
447
- echo $output;
448
- }
449
- return $output;
450
- }
451
-
452
- protected function validate_args( $args, $exclude = array() )
453
- {
454
- $exclude[] = 'value';
455
- $exclude[] = 'maxlength';
456
- $exclude[] = 'tabindex';
457
- $args = parent::validate_args( $args, $exclude );
458
-
459
- // type whitelist check is made later in the display() function to allow different types to use in a filter
460
-
461
- return $args;
462
- }
463
-
464
- protected function get_defaults()
465
- {
466
- $defaults = array(
467
- 'name' => '',
468
- 'id' => '',
469
- 'class' => '',
470
- 'type' => 'text',
471
- 'value' => '', // for multiselect and multiple checkbox an array, for singular checkboxes and all others a string
472
- 'placeholder' => '',
473
- 'label' => '',
474
- 'options' => array(), // for select, multiselect, checkbox and radio: value => title; for number, range and all datetime-related fields: min, max, step
475
- 'rows' => 4,
476
- 'help_text' => '',
477
- 'size' => 'default', // default, large, small, mini
478
- 'form_layout' => 'default', // default, inline, horizontal
479
- 'form_label_width' => 2,
480
- 'form_breakpoint' => 'sm',
481
- 'mode' => 'default', // default, required, static, disabled
482
- 'status' => 'default', // default, success, warning, error
483
- 'readonly' => false,
484
- 'maxlength' => false,
485
- 'tabindex' => false,
486
- 'group_layout' => 'default', // default, inline, buttons
487
- 'group_type' => 'default', // only if group_layout==buttons
488
- 'wrapper_class' => '',
489
- 'input_before' => '',
490
- 'input_after' => '',
491
- 'input_before_class' => 'input-group-addon',
492
- 'input_after_class' => 'input-group-addon',
493
- );
494
- return apply_filters( 'cf7bs_bootstrap_form_field_defaults', $defaults );
495
- }
496
-
497
- private function validate_type( $type )
498
- {
499
- $whitelist = array(
500
- 'text',
501
- 'password',
502
- 'datetime',
503
- 'datetime-local',
504
- 'date',
505
- 'month',
506
- 'time',
507
- 'week',
508
- 'number',
509
- 'range',
510
- 'email',
511
- 'url',
512
- 'search',
513
- 'tel',
514
- 'color',
515
- 'textarea',
516
- 'file',
517
- 'hidden',
518
- 'select',
519
- 'multiselect',
520
- 'checkbox',
521
- 'radio',
522
- );
523
-
524
- $type = strtolower( $type );
525
- if( !in_array( $type, $whitelist ) )
526
- {
527
- $type = 'text';
528
- }
529
- return $type;
530
- }
531
-
532
- private function validate_value( $value, $type, $options = array() )
533
- {
534
- if( $type == 'multiselect' || $type == 'checkbox' && is_array( $options ) && count( $options ) > 1 )
535
- {
536
- $value = (array) $value;
537
- }
538
- else
539
- {
540
- if( is_array( $value ) )
541
- {
542
- if ( count( $value ) > 0 ) {
543
- reset( $value );
544
- $value = $value[ key( $value ) ];
545
- } else {
546
- $value = '';
547
- }
548
- }
549
- $value = (string) $value;
550
- }
551
- return $value;
552
- }
553
-
554
- private function get_column_width_classes( $label_column_width = 2, $breakpoint = 'sm' )
555
- {
556
- if( $label_column_width > 11 || $label_column_width < 1 )
557
- {
558
- $label_column_width = 2;
559
- }
560
- if( !in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) )
561
- {
562
- $breakpoint = 'sm';
563
- }
564
- return array(
565
- 'label' => 'col-' . $breakpoint . '-' . $label_column_width,
566
- 'input' => 'col-' . $breakpoint . '-' . ( 12 - $label_column_width ),
567
- );
568
- }
569
-
570
- private function get_column_offset_class( $label_column_width = 2, $breakpoint = 'sm' )
571
- {
572
- if( $label_column_width > 11 || $label_column_width < 1 )
573
- {
574
- $label_column_width = 2;
575
- }
576
- if( !in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) )
577
- {
578
- $breakpoint = 'sm';
579
- }
580
- return 'col-' . $breakpoint . '-offset-' . $label_column_width;
581
- }
582
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
+ class CF7BS_Form_Field extends CF7BS_Component {
9
+ public function display( $echo = true ) {
10
+ $output = apply_filters( 'cf7bs_bootstrap_form_field_display', '', $this->args );
11
+
12
+ if ( empty( $output ) ) {
13
+ $output = '';
14
+
15
+ extract( $this->args );
16
+
17
+ $type = $this->validate_type( $type );
18
+
19
+ $value = $this->validate_value( $value, $type, $options );
20
+
21
+ if ( 'hidden' != $type ) {
22
+ $label_class = 'control-label';
23
+ $input_div_class = '';
24
+ $input_class = $class;
25
+ if ( 'horizontal' == $form_layout ) {
26
+ $classes = $this->get_column_width_classes( $form_label_width, $form_breakpoint );
27
+ $label_class .= ' ' . $classes['label'];
28
+ $input_div_class = $classes['input'];
29
+ if ( empty( $label ) ) {
30
+ $input_div_class .= ' ' . $this->get_column_offset_class( $form_label_width, $form_breakpoint );
31
+ }
32
+ } elseif( 'inline' == $form_layout ) {
33
+ if ( empty( $placeholder ) ) {
34
+ $placeholder = $label;
35
+ }
36
+ }
37
+
38
+ if ( ! empty( $wrapper_class ) ) {
39
+ $wrapper_class = ' ' . esc_attr( $wrapper_class );
40
+ }
41
+
42
+ if ( ! in_array( $type, array( 'radio', 'checkbox' ) ) ) {
43
+ if ( ! empty( $input_class ) ) {
44
+ $input_class .= ' ';
45
+ }
46
+ if ( ! in_array( $type, array( 'file', 'range' ) ) ) {
47
+ $input_class .= 'form-control';
48
+ }
49
+
50
+ if ( 'textarea' != $type ) {
51
+ if ( 'large' == $size ) {
52
+ $input_class .= ' input-lg';
53
+ } elseif ( in_array( $size, array( 'small', 'mini' ) ) ) {
54
+ $input_class .= ' input-sm';
55
+ }
56
+ }
57
+
58
+ if ( is_int( $tabindex ) ) {
59
+ $tabindex = ' tabindex="' . $tabindex . '"';
60
+ } else {
61
+ $tabindex = '';
62
+ }
63
+ }
64
+
65
+ if ( ! empty( $input_class ) ) {
66
+ $input_class = ' class="' . esc_attr( $input_class ) . '"';
67
+ }
68
+ if ( ! empty( $placeholder ) ) {
69
+ $placeholder = ' placeholder="' . esc_attr( $placeholder ) . '"';
70
+ }
71
+
72
+ if ( $readonly ) {
73
+ $readonly = ' readonly';
74
+ } else {
75
+ $readonly = '';
76
+ }
77
+
78
+ if ( $maxlength > -1 && !empty( $maxlength ) ) {
79
+ $maxlength = ' maxlength="' . absint( $maxlength ) . '"';
80
+ } else {
81
+ $maxlength = '';
82
+ }
83
+
84
+ $append = '';
85
+
86
+ if ( in_array( $status, array( 'success', 'warning', 'error' ) ) ) {
87
+ $status = ' has-' . $status;
88
+ } else {
89
+ $status = '';
90
+ }
91
+
92
+ if ( 'has-error' == $status ) {
93
+ $append .= ' aria-invalid="true"';
94
+ } else {
95
+ $append .= ' aria-invalid="false"';
96
+ }
97
+
98
+ $label_required = '';
99
+ if ( 'required' == $mode ) {
100
+ $append .= ' aria-required="true" required';
101
+ $label_required = ' ' . cf7bs_get_form_property( 'required_html' );
102
+ } elseif( 'disabled' == $mode ) {
103
+ $append .= ' disabled';
104
+ }
105
+
106
+ if ( 'horizontal' == $form_layout ) {
107
+ $output .= '<div class="form-group' . $wrapper_class . $status . '">';
108
+ if ( ! empty( $label ) ) {
109
+ $output .= '<label class="' . esc_attr( $label_class ) . '" for="' . esc_attr( $id ) . '">' . esc_html( $label ) . $label_required . '</label>';
110
+ }
111
+ $output .= '<div class="' . esc_attr( $input_div_class ) . '">';
112
+ } elseif( 'inline' == $form_layout ) {
113
+ $output .= '<div class="form-group' . $wrapper_class . $status . '">';
114
+ if ( ! empty( $label ) ) {
115
+ $output .= '<label class="sr-only" for="' . esc_attr( $id ) . '">' . esc_html( $label ) . $label_required . '</label>';
116
+ }
117
+ } else {
118
+ $output .= '<div class="form-group' . $wrapper_class . $status . '">';
119
+ if ( ! empty( $label ) ) {
120
+ $rc_group_style = '';
121
+ if ( in_array( $type, array( 'radio', 'checkbox' ) ) ) {
122
+ $rc_group_style = ' style="display:block;"';
123
+ }
124
+ $output .= '<label for="' . esc_attr( $id ) . '"' . $rc_group_style . '>' . esc_html( $label ) . $label_required . '</label>';
125
+ }
126
+ }
127
+ }
128
+
129
+ switch ( $type ) {
130
+ case 'checkbox':
131
+ if ( count( $options ) <= 1 ) {
132
+ $curval = key( $options );
133
+ $title = $options[ $curval ];
134
+ if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
135
+ $title = esc_html( $title );
136
+ }
137
+ $output .= '<div class="checkbox' . $wrapper_class . '">';
138
+ $output .= '<label>';
139
+ $output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="checkbox" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . $tabindex . '"' : '' ) . $append . '>';
140
+ $output .= $title;
141
+ $output .= '</label>';
142
+ $output .= '</div>';
143
+ } else {
144
+ if ( 'buttons' == $group_layout ) {
145
+ $button_group = new CF7BS_Button_Group( array(
146
+ 'mode' => 'checkbox',
147
+ 'size' => $size,
148
+ ) );
149
+ $output .= $button_group->open( false );
150
+ $counter = 0;
151
+ foreach ( $options as $curval => $title ) {
152
+ $is_checked = cf7bs_multiple_checked( $value, $curval, false );
153
+ $output .= $button_group->insert_button( array(
154
+ 'type' => $group_type,
155
+ 'id' => $id . ( $counter + 1 ),
156
+ 'name' => $name . '[]',
157
+ 'class' => $class,
158
+ 'value' => $curval,
159
+ 'title' => $title,
160
+ 'append' => ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $is_checked . $append,
161
+ ), false );
162
+ $counter++;
163
+ }
164
+ $output .= $button_group->close( false );
165
+ } elseif ( 'inline' == $group_layout && 'inline' != $form_layout ) {
166
+ $counter = 0;
167
+ foreach ( $options as $curval => $title ) {
168
+ if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
169
+ $title = esc_html( $title );
170
+ }
171
+ $output .= '<label class="checkbox-inline">';
172
+ $output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name . '[]' ) . '" type="checkbox" value="' . esc_attr( $curval ) . '"' . cf7bs_multiple_checked( $value, $curval, false ) . ( $tabindex >= 0 ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
173
+ $output .= $title;
174
+ $output .= '</label>';
175
+ $counter++;
176
+ }
177
+ } else {
178
+ $counter = 0;
179
+ foreach ( $options as $curval => $title ) {
180
+ if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
181
+ $title = esc_html( $title );
182
+ }
183
+ $output .= '<div class="checkbox">';
184
+ $output .= '<label>';
185
+ $output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name . '[]' ) . '" type="checkbox" value="' . esc_attr( $curval ) . '"' . cf7bs_multiple_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
186
+ $output .= $title;
187
+ $output .= '</label>';
188
+ $output .= '</div>';
189
+ $counter++;
190
+ }
191
+ }
192
+ }
193
+ break;
194
+ case 'select':
195
+ $output .= '<select' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '"' . $tabindex . $append . '>';
196
+ foreach ( $options as $curval => $title ) {
197
+ $output .= '<option value="' . esc_attr( $curval ) . '"' . cf7bs_selected( $value, $curval, false ) . '>' . esc_html( $title ) . '</option>';
198
+ }
199
+ $output .= '</select>';
200
+ break;
201
+ case 'multiselect':
202
+ $output .= '<select' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name . '[]' ) . '" multiple' . $tabindex . $append . '>';
203
+ foreach ( $options as $curval => $title ) {
204
+ $output .= '<option value="' . esc_attr( $curval ) . '"' . cf7bs_multiple_selected( $value, $curval, false ) . '>' . esc_html( $title ) . '</option>';
205
+ }
206
+ $output .= '</select>';
207
+ break;
208
+ case 'radio':
209
+ if ( count( $options ) <= 1 ) {
210
+ $curval = key( $options );
211
+ $title = $options[ $curval ];
212
+ if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
213
+ $title = esc_html( $title );
214
+ }
215
+ $output .= '<div class="radio' . $wrapper_class . '">';
216
+ $output .= '<label>';
217
+ $output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="radio" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . $tabindex . '"' : '' ) . $append . '>';
218
+ $output .= $title;
219
+ $output .= '</label>';
220
+ $output .= '</div>';
221
+ } else {
222
+ if ( 'buttons' == $group_layout ) {
223
+ $button_group = new CF7BS_Button_Group( array(
224
+ 'mode' => 'radio',
225
+ 'size' => $size,
226
+ ) );
227
+ $output .= $button_group->open( false );
228
+ $counter = 0;
229
+ foreach ( $options as $curval => $title ) {
230
+ $is_checked = cf7bs_checked( $value, $curval, false );
231
+ $output .= $button_group->insert_button( array(
232
+ 'type' => $group_type,
233
+ 'id' => $id . ( $counter + 1 ),
234
+ 'name' => $name,
235
+ 'class' => $class,
236
+ 'value' => $curval,
237
+ 'title' => $title,
238
+ 'append' => ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $is_checked . $append,
239
+ ), false );
240
+ $counter++;
241
+ }
242
+ $output .= $button_group->close( false );
243
+ } elseif( 'inline' == $group_layout && 'inline' != $form_layout ) {
244
+ $counter = 0;
245
+ foreach ( $options as $curval => $title ) {
246
+ if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
247
+ $title = esc_html( $title );
248
+ }
249
+ $output .= '<label class="radio-inline">';
250
+ $output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="radio" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( $tabindex >= 0 ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
251
+ $output .= $title;
252
+ $output .= '</label>';
253
+ $counter++;
254
+ }
255
+ } else {
256
+ $counter = 0;
257
+ foreach ( $options as $curval => $title ) {
258
+ if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
259
+ $title = esc_html( $title );
260
+ }
261
+ $output .= '<div class="radio">';
262
+ $output .= '<label>';
263
+ $output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="radio" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
264
+ $output .= $title;
265
+ $output .= '</label>';
266
+ $output .= '</div>';
267
+ $counter++;
268
+ }
269
+ }
270
+ }
271
+ break;
272
+ case 'textarea':
273
+ $output .= '<textarea' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" rows="' . absint( $rows ) . '"' . $placeholder . $readonly . $tabindex . $append . '>';
274
+ $output .= esc_textarea( $value );
275
+ $output .= '</textarea>';
276
+ break;
277
+ case 'file':
278
+ $output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="file"' . $tabindex . $append . '>';
279
+ break;
280
+ case 'hidden':
281
+ $output .= '<input' . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="hidden" value="' . esc_attr( $value ) . '">';
282
+ break;
283
+ case 'number':
284
+ case 'range':
285
+ case 'date':
286
+ case 'datetime':
287
+ case 'datetime-local':
288
+ case 'month':
289
+ case 'time':
290
+ case 'week':
291
+ $min = '';
292
+ if ( isset( $options['min'] ) ) {
293
+ $min = ' min="' . esc_attr( $options['min'] ) . '"';
294
+ }
295
+ $max = '';
296
+ if ( isset( $options['max'] ) ) {
297
+ $max = ' max="' . esc_attr( $options['max'] ) . '"';
298
+ }
299
+ $step = '';
300
+ if ( isset( $options['step'] ) ) {
301
+ $step = ' step="' . esc_attr( $options['step'] ) . '"';
302
+ }
303
+ $output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="' . esc_attr( $type ) . '" value="' . esc_attr( $value ) . '"' . $placeholder . $min . $max . $step . $readonly . $tabindex . $append . '>';
304
+ break;
305
+ case 'custom':
306
+ if ( ! empty( $name ) ) {
307
+ $output .= $name;
308
+ }
309
+ break;
310
+ default:
311
+ if ( 'static' == $mode ) {
312
+ $output .= '<p class="form-control-static">' . esc_html( $value ) . '</p>';
313
+ } else {
314
+ if ( ! empty( $input_before ) || ! empty( $input_after ) ) {
315
+ $input_group_class = 'input-group';
316
+ if ( false !== strpos( $input_class, ' input-lg') ) {
317
+ $input_class = str_replace( ' input-lg', '', $input_class );
318
+ $input_group_class .= ' input-group-lg';
319
+ } elseif ( false !== strpos( $input_class, ' input-sm') ) {
320
+ $input_class = str_replace( ' input-sm', '', $input_class );
321
+ $input_group_class .= ' input-group-sm';
322
+ }
323
+ $output .= '<div class="' . $input_group_class . '">';
324
+ if ( ! empty( $input_before ) ) {
325
+ $output .= '<span class="' . esc_attr( $input_before_class ) . '">';
326
+ $output .= $input_before;
327
+ $output .= '</span>';
328
+ }
329
+ }
330
+
331
+ $output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="' . esc_attr( $type ) . '" value="' . esc_attr( $value ) . '"' . $placeholder . $readonly . $maxlength . $tabindex . $append . '>';
332
+
333
+ if ( ! empty( $input_before ) || ! empty( $input_after ) ) {
334
+ if ( ! empty( $input_after ) ) {
335
+ $output .= '<span class="' . esc_attr( $input_after_class ) . '">';
336
+ $output .= $input_after;
337
+ $output .= '</span>';
338
+ }
339
+ $output .= '</div>';
340
+ }
341
+ }
342
+ break;
343
+ }
344
+
345
+ if ( 'hidden' != $type ) {
346
+ if ( ! empty( $help_text ) && 'inline' != $form_layout ) {
347
+ $output .= '<span class="help-block">' . $help_text . '</span>';
348
+ }
349
+
350
+ if ( 'horizontal' == $form_layout ) {
351
+ $output .= '</div>';
352
+ $output .= '</div>';
353
+ } else {
354
+ $output .= '</div>';
355
+ }
356
+ }
357
+ }
358
+
359
+ if ( $echo ) {
360
+ echo $output;
361
+ }
362
+ return $output;
363
+ }
364
+
365
+ protected function validate_args( $args, $exclude = array() ) {
366
+ $exclude[] = 'value';
367
+ $exclude[] = 'maxlength';
368
+ $exclude[] = 'tabindex';
369
+ $args = parent::validate_args( $args, $exclude );
370
+
371
+ // type whitelist check is made later in the display() function to allow different types to use in a filter
372
+
373
+ return $args;
374
+ }
375
+
376
+ protected function get_defaults() {
377
+ $defaults = array(
378
+ 'name' => '',
379
+ 'id' => '',
380
+ 'class' => '',
381
+ 'type' => 'text',
382
+ 'value' => '', // for multiselect and multiple checkbox an array, for singular checkboxes and all others a string
383
+ 'placeholder' => '',
384
+ 'label' => '',
385
+ 'options' => array(), // for select, multiselect, checkbox and radio: value => title; for number, range and all datetime-related fields: min, max, step
386
+ 'rows' => 4,
387
+ 'help_text' => '',
388
+ 'size' => 'default', // default, large, small, mini
389
+ 'form_layout' => 'default', // default, inline, horizontal
390
+ 'form_label_width' => 2,
391
+ 'form_breakpoint' => 'sm',
392
+ 'mode' => 'default', // default, required, static, disabled
393
+ 'status' => 'default', // default, success, warning, error
394
+ 'readonly' => false,
395
+ 'maxlength' => false,
396
+ 'tabindex' => false,
397
+ 'group_layout' => 'default', // default, inline, buttons
398
+ 'group_type' => 'default', // only if group_layout==buttons
399
+ 'wrapper_class' => '',
400
+ 'input_before' => '',
401
+ 'input_after' => '',
402
+ 'input_before_class' => 'input-group-addon',
403
+ 'input_after_class' => 'input-group-addon',
404
+ );
405
+ return apply_filters( 'cf7bs_bootstrap_form_field_defaults', $defaults );
406
+ }
407
+
408
+ private function validate_type( $type ) {
409
+ $whitelist = array(
410
+ 'text',
411
+ 'password',
412
+ 'datetime',
413
+ 'datetime-local',
414
+ 'date',
415
+ 'month',
416
+ 'time',
417
+ 'week',
418
+ 'number',
419
+ 'range',
420
+ 'email',
421
+ 'url',
422
+ 'search',
423
+ 'tel',
424
+ 'color',
425
+ 'textarea',
426
+ 'file',
427
+ 'hidden',
428
+ 'select',
429
+ 'multiselect',
430
+ 'checkbox',
431
+ 'radio',
432
+ 'custom',
433
+ );
434
+
435
+ $type = strtolower( $type );
436
+ if ( ! in_array( $type, $whitelist ) ) {
437
+ $type = 'text';
438
+ }
439
+ return $type;
440
+ }
441
+
442
+ private function validate_value( $value, $type, $options = array() ) {
443
+ if ( 'multiselect' == $type || 'checkbox' == $type && is_array( $options ) && count( $options ) > 1 ) {
444
+ $value = (array) $value;
445
+ } else {
446
+ if ( is_array( $value ) ) {
447
+ if ( count( $value ) > 0 ) {
448
+ reset( $value );
449
+ $value = $value[ key( $value ) ];
450
+ } else {
451
+ $value = '';
452
+ }
453
+ }
454
+ $value = (string) $value;
455
+ }
456
+ return $value;
457
+ }
458
+
459
+ private function get_column_width_classes( $label_column_width = 2, $breakpoint = 'sm' ) {
460
+ if ( $label_column_width > 11 || $label_column_width < 1 ) {
461
+ $label_column_width = 2;
462
+ }
463
+ if ( ! in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) ) {
464
+ $breakpoint = 'sm';
465
+ }
466
+ return array(
467
+ 'label' => 'col-' . $breakpoint . '-' . $label_column_width,
468
+ 'input' => 'col-' . $breakpoint . '-' . ( 12 - $label_column_width ),
469
+ );
470
+ }
471
+
472
+ private function get_column_offset_class( $label_column_width = 2, $breakpoint = 'sm' ) {
473
+ if ( $label_column_width > 11 || $label_column_width < 1 ) {
474
+ $label_column_width = 2;
475
+ }
476
+ if ( ! in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) ) {
477
+ $breakpoint = 'sm';
478
+ }
479
+ return 'col-' . $breakpoint . '-offset-' . $label_column_width;
480
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  }
composer.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "name": "felixarntz/bootstrap-for-contact-form-7",
3
  "description": "This plugin modifies the output of the popular Contact Form 7 plugin to be styled in compliance with themes using the Bootstrap CSS framework.",
4
- "version": "1.1.1",
5
  "license": "GPL-2.0",
6
  "type": "wordpress-plugin",
7
  "keywords": [
1
  {
2
  "name": "felixarntz/bootstrap-for-contact-form-7",
3
  "description": "This plugin modifies the output of the popular Contact Form 7 plugin to be styled in compliance with themes using the Bootstrap CSS framework.",
4
+ "version": "1.2.0",
5
  "license": "GPL-2.0",
6
  "type": "wordpress-plugin",
7
  "keywords": [
modifications.php CHANGED
@@ -1,277 +1,237 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- function cf7bs_selected( $selected, $current = true, $echo = true )
9
- {
10
- $result = '';
11
-
12
- if( $selected == $current )
13
- {
14
- $result = ' selected';
15
- if( !wpcf7_support_html5() )
16
- {
17
- $result .= '="selected"';
18
- }
19
- }
20
-
21
- if( $echo )
22
- {
23
- echo $result;
24
- }
25
-
26
- return $result;
27
  }
28
 
29
- function cf7bs_multiple_selected( $selected, $current = true, $echo = true )
30
- {
31
- $result = '';
32
-
33
- if( is_array( $selected ) )
34
- {
35
- if( in_array( $current, $selected ) )
36
- {
37
- $result = ' selected';
38
- if( !wpcf7_support_html5() )
39
- {
40
- $result .= '="selected"';
41
- }
42
- }
43
- }
44
-
45
- if( $echo )
46
- {
47
- echo $result;
48
- }
49
-
50
- return $result;
51
  }
52
 
53
- function cf7bs_checked( $checked, $current = true, $echo = true )
54
- {
55
- $result = '';
56
-
57
- if( $checked == $current )
58
- {
59
- $result = ' checked';
60
- if( !wpcf7_support_html5() )
61
- {
62
- $result .= '="checked"';
63
- }
64
- }
65
-
66
- if( $echo )
67
- {
68
- echo $result;
69
- }
70
-
71
- return $result;
72
  }
73
 
74
- function cf7bs_multiple_checked( $checked, $current = true, $echo = true )
75
- {
76
- $result = '';
77
-
78
- if( is_array( $checked ) )
79
- {
80
- if( in_array( $current, $checked ) )
81
- {
82
- $result = ' checked';
83
- if( !wpcf7_support_html5() )
84
- {
85
- $result .= '="checked"';
86
- }
87
- }
88
- }
89
-
90
- if( $echo )
91
- {
92
- echo $result;
93
- }
94
-
95
- return $result;
96
  }
97
 
98
- function cf7bs_enqueue_scripts()
99
- {
100
- $in_footer = true;
101
- if( 'header' === WPCF7_LOAD_JS )
102
- {
103
- $in_footer = false;
104
- }
105
- wp_enqueue_script( 'contact-form-7-bootstrap', CF7BS_URL . '/assets/scripts.min.js', array( 'jquery', 'jquery-form', 'contact-form-7' ), CF7BS_VERSION, $in_footer );
106
  }
107
  add_action( 'wpcf7_enqueue_scripts', 'cf7bs_enqueue_scripts' );
108
 
109
- function cf7bs_enqueue_styles()
110
- {
111
- wp_dequeue_style( 'contact-form-7' );
112
  }
113
  add_action( 'wpcf7_enqueue_styles', 'cf7bs_enqueue_styles' );
114
 
115
- function cf7bs_inline_styles()
116
- {
117
- ?>
118
- <style type="text/css">
119
- .screen-reader-response {
120
- display: none;
121
- }
122
- </style>
123
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  }
125
  add_action( 'wp_head', 'cf7bs_inline_styles' );
126
 
127
- function cf7bs_form_class_attr( $class = '' )
128
- {
129
- $layout = cf7bs_get_form_property( 'layout' );
130
- if( $layout == 'horizontal' || $layout == 'inline' )
131
- {
132
- if( !empty( $class ) )
133
- {
134
- $class .= ' ';
135
- }
136
- $class .= 'form-' . $layout;
137
- }
138
- return $class;
139
  }
140
  add_filter( 'wpcf7_form_class_attr', 'cf7bs_form_class_attr' );
141
 
142
- function cf7bs_form_novalidate( $novalidate )
143
- {
144
- if( wpcf7_support_html5() )
145
- {
146
- return ' novalidate';
147
- }
148
- return '';
149
  }
150
  add_filter( 'wpcf7_form_novalidate', 'cf7bs_form_novalidate' );
151
 
152
- function cf7bs_form_response_output( $output, $class, $content, $form_obj )
153
- {
154
- $type = 'warning';
155
- $hide = false;
156
-
157
- if( strpos( $class, 'wpcf7-display-none' ) !== false )
158
- {
159
- $hide = true;
160
- $type = '';
161
- }
162
- else
163
- {
164
- if( strpos( $class, 'wpcf7-mail-sent-ng' ) !== false )
165
- {
166
- $type = 'danger';
167
- }
168
- elseif( strpos( $class, 'wpcf7-mail-sent-ok' ) !== false )
169
- {
170
- $type = 'success';
171
- }
172
- else
173
- {
174
- $type = 'warning';
175
- }
176
- }
177
-
178
- $alert = new CF7BS_Alert( array(
179
- 'type' => $type,
180
- 'class' => $class,
181
- 'hide' => $hide,
182
- ) );
183
- return $alert->open( false ) . esc_html( $content ) . $alert->close( false );
184
  }
185
  add_filter( 'wpcf7_form_response_output', 'cf7bs_form_response_output', 10, 4 );
186
 
187
- function cf7bs_validation_error( $output, $name, $form_obj )
188
- {
189
- $alert = new CF7BS_Alert( array(
190
- 'type' => 'warning',
191
- 'class' => 'wpcf7-not-valid-tip',
192
- ) );
193
- $output = str_replace( '<span role="alert" class="wpcf7-not-valid-tip">', $alert->open( false ), $output );
194
- $output = str_replace( '</span>', $alert->close( false ), $output );
195
- return $output;
196
  }
197
  add_filter( 'wpcf7_validation_error', 'cf7bs_validation_error', 10, 3 );
198
 
199
- function cf7bs_ajax_json_echo( $items, $result )
200
- {
201
- if( isset( $items['invalids'] ) )
202
- {
203
- foreach( $items['invalids'] as &$invalid )
204
- {
205
- $invalid['into'] = str_replace( 'span.wpcf7-form-control-wrap', 'div.form-group', $invalid['into'] );
206
- }
207
- }
208
- return $items;
209
  }
210
  add_filter( 'wpcf7_ajax_json_echo', 'cf7bs_ajax_json_echo', 10, 2 );
211
 
212
- function cf7bs_default_template( $template, $prop = 'form' )
213
- {
214
- if( $prop == 'form' )
215
- {
216
- $template = cf7bs_default_form_template();
217
- }
218
- return $template;
219
  }
220
  add_filter( 'wpcf7_default_template', 'cf7bs_default_template', 10, 2 );
221
 
222
- function cf7bs_default_form_template()
223
- {
224
- $template = '[text* your-name]' . __( 'Your Name', 'contact-form-7' ) . '[/text*]' . "\n"
225
- . '[email* your-email]' . __( 'Your Email', 'contact-form-7' ) . '[/email*]' . "\n"
226
- . '[text your-subject]' . __( 'Subject', 'contact-form-7' ) . '[/text]' . "\n"
227
- . '[textarea your-message]' . __( 'Your Message', 'contact-form-7' ) . '[/textarea]' . "\n"
228
- . '[submit "' . __( 'Send', 'contact-form-7' ) . '"]';
229
-
230
- return $template;
231
- }
232
-
233
- function cf7bs_parameter_encode( $item )
234
- {
235
- $encoded = '';
236
- if( is_object( $item ) )
237
- {
238
- return '';
239
- }
240
- elseif( is_array( $item ) )
241
- {
242
- $encoded = cf7bs_array_encode( $item );
243
- }
244
- else
245
- {
246
- $encoded = $item;
247
- }
248
- return rawurlencode( $encoded );
249
- }
250
-
251
- function cf7bs_array_encode( $values )
252
- {
253
- if( !is_array( $values ) )
254
- {
255
- return '';
256
- }
257
- $encoded = '';
258
- foreach( $values as $value )
259
- {
260
- if( !empty( $encoded ) )
261
- {
262
- $encoded .= '---';
263
- }
264
- $encoded .= $value;
265
- }
266
- return $encoded;
267
- }
268
-
269
- function cf7bs_array_decode( $values )
270
- {
271
- if( !is_string( $values ) )
272
- {
273
- return array();
274
- }
275
- $decoded = explode( '---', $values );
276
- return $decoded;
277
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
+ function cf7bs_selected( $selected, $current = true, $echo = true ) {
9
+ $result = '';
10
+
11
+ if ( $selected == $current ) {
12
+ $result = ' selected';
13
+ if ( ! wpcf7_support_html5() ) {
14
+ $result .= '="selected"';
15
+ }
16
+ }
17
+
18
+ if ( $echo ) {
19
+ echo $result;
20
+ }
21
+
22
+ return $result;
 
 
 
 
23
  }
24
 
25
+ function cf7bs_multiple_selected( $selected, $current = true, $echo = true ) {
26
+ $result = '';
27
+
28
+ if ( is_array( $selected ) ) {
29
+ if ( in_array( $current, $selected ) ) {
30
+ $result = ' selected';
31
+ if ( ! wpcf7_support_html5() ) {
32
+ $result .= '="selected"';
33
+ }
34
+ }
35
+ }
36
+
37
+ if ( $echo ) {
38
+ echo $result;
39
+ }
40
+
41
+ return $result;
 
 
 
 
 
42
  }
43
 
44
+ function cf7bs_checked( $checked, $current = true, $echo = true ) {
45
+ $result = '';
46
+
47
+ if ( $checked == $current ) {
48
+ $result = ' checked';
49
+ if ( ! wpcf7_support_html5() ) {
50
+ $result .= '="checked"';
51
+ }
52
+ }
53
+
54
+ if ( $echo ) {
55
+ echo $result;
56
+ }
57
+
58
+ return $result;
 
 
 
 
59
  }
60
 
61
+ function cf7bs_multiple_checked( $checked, $current = true, $echo = true ) {
62
+ $result = '';
63
+
64
+ if ( is_array( $checked ) ) {
65
+ if ( in_array( $current, $checked ) ) {
66
+ $result = ' checked';
67
+ if ( ! wpcf7_support_html5() ) {
68
+ $result .= '="checked"';
69
+ }
70
+ }
71
+ }
72
+
73
+ if ( $echo ) {
74
+ echo $result;
75
+ }
76
+
77
+ return $result;
 
 
 
 
 
78
  }
79
 
80
+ function cf7bs_enqueue_scripts() {
81
+ $in_footer = true;
82
+ if ( 'header' === WPCF7_LOAD_JS ) {
83
+ $in_footer = false;
84
+ }
85
+ wp_enqueue_script( 'contact-form-7-bootstrap', CF7BS_URL . '/assets/scripts.min.js', array( 'jquery', 'jquery-form', 'contact-form-7' ), CF7BS_VERSION, $in_footer );
 
 
86
  }
87
  add_action( 'wpcf7_enqueue_scripts', 'cf7bs_enqueue_scripts' );
88
 
89
+ function cf7bs_enqueue_styles() {
90
+ wp_dequeue_style( 'contact-form-7' );
 
91
  }
92
  add_action( 'wpcf7_enqueue_styles', 'cf7bs_enqueue_styles' );
93
 
94
+ function cf7bs_inline_styles() {
95
+ ?>
96
+ <style type="text/css">
97
+ .screen-reader-response {
98
+ display: none;
99
+ }
100
+ div.wpcf7 img.ajax-loader {
101
+ border: none;
102
+ vertical-align: middle;
103
+ margin-left: 4px;
104
+ }
105
+ div.wpcf7 .form-inline img.ajax-loader {
106
+ display: inline;
107
+ }
108
+ div.wpcf7 div.ajax-error {
109
+ display: none;
110
+ }
111
+ .wpcf7-display-none {
112
+ display: none;
113
+ }
114
+ .form-inline .form-group {
115
+ max-width: 250px;
116
+ }
117
+ </style>
118
+ <?php
119
  }
120
  add_action( 'wp_head', 'cf7bs_inline_styles' );
121
 
122
+ function cf7bs_form_class_attr( $class = '' ) {
123
+ $layout = cf7bs_get_form_property( 'layout' );
124
+ if ( in_array( $layout, array( 'horizontal', 'inline' ) ) ) {
125
+ if ( ! empty( $class ) ) {
126
+ $class .= ' ';
127
+ }
128
+ $class .= 'form-' . $layout;
129
+ }
130
+ return $class;
 
 
 
131
  }
132
  add_filter( 'wpcf7_form_class_attr', 'cf7bs_form_class_attr' );
133
 
134
+ function cf7bs_form_novalidate( $novalidate ) {
135
+ if ( wpcf7_support_html5() ) {
136
+ return ' novalidate';
137
+ }
138
+ return '';
 
 
139
  }
140
  add_filter( 'wpcf7_form_novalidate', 'cf7bs_form_novalidate' );
141
 
142
+ function cf7bs_form_response_output( $output, $class, $content, $form_obj ) {
143
+ $type = 'warning';
144
+
145
+ if ( false !== strpos( $class, 'wpcf7-display-none' ) ) {
146
+ $type = '';
147
+ } else {
148
+ if ( false !== strpos( $class, 'wpcf7-mail-sent-ng' ) ) {
149
+ $type = 'danger';
150
+ } elseif ( false !== strpos( $class, 'wpcf7-mail-sent-ok' ) ) {
151
+ $type = 'success';
152
+ } else {
153
+ $type = 'warning';
154
+ }
155
+ }
156
+
157
+ $alert = new CF7BS_Alert( array(
158
+ 'type' => $type,
159
+ 'class' => $class,
160
+ ) );
161
+
162
+ return $alert->open( false ) . esc_html( $content ) . $alert->close( false );
 
 
 
 
 
 
 
 
 
 
 
163
  }
164
  add_filter( 'wpcf7_form_response_output', 'cf7bs_form_response_output', 10, 4 );
165
 
166
+ function cf7bs_validation_error( $output, $name, $form_obj ) {
167
+ $alert = new CF7BS_Alert( array(
168
+ 'type' => 'warning',
169
+ 'class' => 'wpcf7-not-valid-tip',
170
+ ) );
171
+ $output = str_replace( '<span role="alert" class="wpcf7-not-valid-tip">', $alert->open( false ), $output );
172
+ $output = str_replace( '</span>', $alert->close( false ), $output );
173
+ return $output;
 
174
  }
175
  add_filter( 'wpcf7_validation_error', 'cf7bs_validation_error', 10, 3 );
176
 
177
+ function cf7bs_ajax_json_echo( $items, $result ) {
178
+ if ( isset( $items['invalids'] ) ) {
179
+ foreach ( $items['invalids'] as &$invalid ) {
180
+ $invalid['into'] = str_replace( 'span.wpcf7-form-control-wrap', 'div.form-group', $invalid['into'] );
181
+ }
182
+ }
183
+ return $items;
 
 
 
184
  }
185
  add_filter( 'wpcf7_ajax_json_echo', 'cf7bs_ajax_json_echo', 10, 2 );
186
 
187
+ function cf7bs_default_template( $template, $prop = 'form' ) {
188
+ if ( 'form' == $prop ) {
189
+ $template = cf7bs_default_form_template();
190
+ }
191
+ return $template;
 
 
192
  }
193
  add_filter( 'wpcf7_default_template', 'cf7bs_default_template', 10, 2 );
194
 
195
+ function cf7bs_default_form_template() {
196
+ $template = '[text* your-name]' . __( 'Your Name', 'contact-form-7' ) . '[/text*]' . "\n"
197
+ . '[email* your-email]' . __( 'Your Email', 'contact-form-7' ) . '[/email*]' . "\n"
198
+ . '[text your-subject]' . __( 'Subject', 'contact-form-7' ) . '[/text]' . "\n"
199
+ . '[textarea your-message]' . __( 'Your Message', 'contact-form-7' ) . '[/textarea]' . "\n"
200
+ . '[submit "' . __( 'Send', 'contact-form-7' ) . '"]';
201
+
202
+ return $template;
203
+ }
204
+
205
+ function cf7bs_parameter_encode( $item ) {
206
+ $encoded = '';
207
+ if ( is_object( $item ) ) {
208
+ return '';
209
+ } elseif ( is_array( $item ) ) {
210
+ $encoded = cf7bs_array_encode( $item );
211
+ } else {
212
+ $encoded = $item;
213
+ }
214
+ return rawurlencode( $encoded );
215
+ }
216
+
217
+ function cf7bs_array_encode( $values ) {
218
+ if ( ! is_array( $values ) ) {
219
+ return '';
220
+ }
221
+ $encoded = '';
222
+ foreach ( $values as $value ) {
223
+ if ( ! empty( $encoded ) ) {
224
+ $encoded .= '---';
225
+ }
226
+ $encoded .= $value;
227
+ }
228
+ return $encoded;
229
+ }
230
+
231
+ function cf7bs_array_decode( $values ) {
232
+ if ( ! is_string( $values ) ) {
233
+ return array();
234
+ }
235
+ $decoded = explode( '---', $values );
236
+ return $decoded;
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  }
modules/acceptance.php CHANGED
@@ -1,64 +1,59 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_acceptance' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_acceptance' );
10
 
11
- function cf7bs_add_shortcode_acceptance()
12
- {
13
- wpcf7_add_shortcode( 'acceptance', 'cf7bs_acceptance_shortcode_handler', true );
14
  }
15
 
16
- function cf7bs_acceptance_shortcode_handler( $tag )
17
- {
18
- $tag = new WPCF7_Shortcode( $tag );
19
-
20
- if( empty( $tag->name ) )
21
- {
22
- return '';
23
- }
24
-
25
- $mode = $status = 'default';
26
-
27
- $validation_error = wpcf7_get_validation_error( $tag->name );
28
-
29
- $class = wpcf7_form_controls_class( $tag->type );
30
- if( $validation_error )
31
- {
32
- $class .= ' wpcf7-not-valid';
33
- $status = 'error';
34
- }
35
- if( $tag->has_option( 'invert' ) )
36
- {
37
- $class .= ' wpcf7-invert';
38
- }
39
-
40
- $field = new CF7BS_Form_Field( array(
41
- 'name' => $tag->name,
42
- 'id' => $tag->get_option( 'id', 'id', true ),
43
- 'class' => $tag->get_class_option( $class ),
44
- 'type' => 'checkbox',
45
- 'value' => $tag->has_option( 'default:on' ) ? '1' : '0',
46
- 'options' => array(
47
- '1' => $tag->content,
48
- ),
49
- 'help_text' => $validation_error,
50
- 'size' => cf7bs_get_form_property( 'size' ),
51
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
52
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
53
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
54
- 'group_layout' => cf7bs_get_form_property( 'group_layout' ),
55
- 'mode' => $mode,
56
- 'status' => $status,
57
- 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
58
- 'wrapper_class' => $tag->name,
59
- ) );
60
-
61
- $html = $field->display( false );
62
-
63
- return $html;
64
- }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_acceptance' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_acceptance' );
10
 
11
+ function cf7bs_add_shortcode_acceptance() {
12
+ wpcf7_add_shortcode( 'acceptance', 'cf7bs_acceptance_shortcode_handler', true );
 
13
  }
14
 
15
+ function cf7bs_acceptance_shortcode_handler( $tag ) {
16
+ $tag = new WPCF7_Shortcode( $tag );
17
+
18
+ if ( empty( $tag->name ) ) {
19
+ return '';
20
+ }
21
+
22
+ $mode = $status = 'default';
23
+
24
+ $validation_error = wpcf7_get_validation_error( $tag->name );
25
+
26
+ $class = wpcf7_form_controls_class( $tag->type );
27
+ if ( $validation_error ) {
28
+ $class .= ' wpcf7-not-valid';
29
+ $status = 'error';
30
+ }
31
+ if ( $tag->has_option( 'invert' ) ) {
32
+ $class .= ' wpcf7-invert';
33
+ }
34
+
35
+ $field = new CF7BS_Form_Field( array(
36
+ 'name' => $tag->name,
37
+ 'id' => $tag->get_option( 'id', 'id', true ),
38
+ 'class' => $tag->get_class_option( $class ),
39
+ 'type' => 'checkbox',
40
+ 'value' => $tag->has_option( 'default:on' ) ? '1' : '0',
41
+ 'options' => array(
42
+ '1' => $tag->content,
43
+ ),
44
+ 'help_text' => $validation_error,
45
+ 'size' => cf7bs_get_form_property( 'size' ),
46
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
47
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
48
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
49
+ 'group_layout' => cf7bs_get_form_property( 'group_layout' ),
50
+ 'mode' => $mode,
51
+ 'status' => $status,
52
+ 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
53
+ 'wrapper_class' => $tag->name,
54
+ ) );
55
+
56
+ $html = $field->display( false );
57
+
58
+ return $html;
59
+ }
 
 
 
 
modules/captcha.php CHANGED
@@ -1,110 +1,96 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_captcha' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_captcha' );
10
 
11
- function cf7bs_add_shortcode_captcha()
12
- {
13
- wpcf7_add_shortcode( array(
14
- 'captchac',
15
- 'captchar',
16
- ), 'cf7bs_captcha_shortcode_handler', true );
17
  }
18
 
19
- function cf7bs_captcha_shortcode_handler( $tag )
20
- {
21
- $tag_obj = new WPCF7_Shortcode( $tag );
22
-
23
- if( 'captchac' == $tag_obj->type && !class_exists( 'ReallySimpleCaptcha' ) )
24
- {
25
- return '<em>' . __( 'To use CAPTCHA, you need <a href="http://wordpress.org/extend/plugins/really-simple-captcha/">Really Simple CAPTCHA</a> plugin installed.', 'contact-form-7' ) . '</em>';
26
- }
27
-
28
- if( empty( $tag_obj->name ) )
29
- {
30
- return '';
31
- }
32
-
33
- $mode = $status = 'default';
34
-
35
- $validation_error = wpcf7_get_validation_error( $tag_obj->name );
36
-
37
- $class = wpcf7_form_controls_class( $tag_obj->type, 'wpcf7-text' );
38
-
39
- if( 'captchac' == $tag_obj->type )
40
- {
41
- $field = new CF7BS_Form_Field( array(
42
- 'name' => $tag_obj->name,
43
- 'id' => $tag_obj->get_option( 'id', 'id', true ),
44
- 'type' => 'file',
45
- 'value' => '1',
46
- 'label' => $tag_obj->content,
47
- 'help_text' => $validation_error,
48
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
49
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
50
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
51
- 'mode' => $mode,
52
- 'status' => $status,
53
- 'tabindex' => false,
54
- 'wrapper_class' => '',
55
- ) );
56
-
57
- $html = $field->display( false );
58
-
59
- return str_replace( '<input' . ( $tag_obj->get_option( 'id', 'id', true ) != '' ? ' id="' . esc_attr( $tag_obj->get_option( 'id', 'id', true ) ) . '"' : '' ) . ' name="' . esc_attr( $tag_obj->name ) . '" type="file">', wpcf7_captcha_shortcode_handler( $tag ), $html );
60
- }
61
- elseif( 'captchar' == $tag_obj->type )
62
- {
63
- if( $validation_error )
64
- {
65
- $class .= ' wpcf7-not-valid';
66
- $status = 'error';
67
- }
68
-
69
- // size is not used since Bootstrap input fields always scale 100%
70
- //$atts['size'] = $tag->get_size_option( '40' );
71
-
72
- $value = (string) reset( $tag_obj->values );
73
- $placeholder = '';
74
- if( wpcf7_is_posted() )
75
- {
76
- $value = '';
77
- }
78
- if( $tag_obj->has_option( 'placeholder' ) || $tag_obj->has_option( 'watermark' ) )
79
- {
80
- $placeholder = $value;
81
- $value = '';
82
- }
83
-
84
- $field = new CF7BS_Form_Field( array(
85
- 'name' => $tag_obj->name,
86
- 'id' => $tag_obj->get_option( 'id', 'id', true ),
87
- 'class' => $tag_obj->get_class_option( $class ),
88
- 'type' => 'text',
89
- 'value' => $value,
90
- 'placeholder' => $placeholder,
91
- 'label' => $tag_obj->content,
92
- 'help_text' => $validation_error,
93
- 'size' => cf7bs_get_form_property( 'size' ),
94
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
95
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
96
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
97
- 'mode' => $mode,
98
- 'status' => $status,
99
- 'maxlength' => $tag_obj->get_maxlength_option(),
100
- 'tabindex' => $tag_obj->get_option( 'tabindex', 'int', true ),
101
- 'wrapper_class' => $tag_obj->name,
102
- ) );
103
-
104
- $html = $field->display( false );
105
-
106
- return $html;
107
- }
108
-
109
- return '';
110
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_captcha' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_captcha' );
10
 
11
+ function cf7bs_add_shortcode_captcha() {
12
+ wpcf7_add_shortcode( array(
13
+ 'captchac',
14
+ 'captchar',
15
+ ), 'cf7bs_captcha_shortcode_handler', true );
 
16
  }
17
 
18
+ function cf7bs_captcha_shortcode_handler( $tag ) {
19
+ $tag_obj = new WPCF7_Shortcode( $tag );
20
+
21
+ if ( 'captchac' == $tag_obj->type && ! class_exists( 'ReallySimpleCaptcha' ) ) {
22
+ return '<em>' . __( 'To use CAPTCHA, you need <a href="http://wordpress.org/extend/plugins/really-simple-captcha/">Really Simple CAPTCHA</a> plugin installed.', 'contact-form-7' ) . '</em>';
23
+ }
24
+
25
+ if ( empty( $tag_obj->name ) ) {
26
+ return '';
27
+ }
28
+
29
+ $validation_error = wpcf7_get_validation_error( $tag_obj->name );
30
+
31
+ if ( 'captchac' == $tag_obj->type ) {
32
+ $field = new CF7BS_Form_Field( array(
33
+ 'name' => wpcf7_captcha_shortcode_handler( $tag ),
34
+ 'type' => 'custom',
35
+ 'label' => $tag_obj->content,
36
+ 'help_text' => $validation_error,
37
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
38
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
39
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
40
+ 'tabindex' => false,
41
+ 'wrapper_class' => '',
42
+ ) );
43
+
44
+ $html = $field->display( false );
45
+
46
+ return $html;
47
+ } elseif ( 'captchar' == $tag_obj->type ) {
48
+ $mode = $status = 'default';
49
+
50
+ $class = wpcf7_form_controls_class( $tag_obj->type, 'wpcf7-text' );
51
+
52
+ if ( $validation_error ) {
53
+ $class .= ' wpcf7-not-valid';
54
+ $status = 'error';
55
+ }
56
+
57
+ // size is not used since Bootstrap input fields always scale 100%
58
+ //$atts['size'] = $tag->get_size_option( '40' );
59
+
60
+ $value = (string) reset( $tag_obj->values );
61
+ $placeholder = '';
62
+ if ( wpcf7_is_posted() ) {
63
+ $value = '';
64
+ }
65
+ if ( $tag_obj->has_option( 'placeholder' ) || $tag_obj->has_option( 'watermark' ) ) {
66
+ $placeholder = $value;
67
+ $value = '';
68
+ }
69
+
70
+ $field = new CF7BS_Form_Field( array(
71
+ 'name' => $tag_obj->name,
72
+ 'id' => $tag_obj->get_option( 'id', 'id', true ),
73
+ 'class' => $tag_obj->get_class_option( $class ),
74
+ 'type' => 'text',
75
+ 'value' => $value,
76
+ 'placeholder' => $placeholder,
77
+ 'label' => $tag_obj->content,
78
+ 'help_text' => $validation_error,
79
+ 'size' => cf7bs_get_form_property( 'size' ),
80
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
81
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
82
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
83
+ 'mode' => $mode,
84
+ 'status' => $status,
85
+ 'maxlength' => $tag_obj->get_maxlength_option(),
86
+ 'tabindex' => $tag_obj->get_option( 'tabindex', 'int', true ),
87
+ 'wrapper_class' => $tag_obj->name,
88
+ ) );
89
+
90
+ $html = $field->display( false );
91
+
92
+ return $html;
93
+ }
94
+
95
+ return '';
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
modules/checkbox.php CHANGED
@@ -1,190 +1,175 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_checkbox' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_checkbox' );
10
 
11
- function cf7bs_add_shortcode_checkbox()
12
- {
13
- wpcf7_add_shortcode( array(
14
- 'checkbox',
15
- 'checkbox*',
16
- 'radio',
17
- ), 'cf7bs_checkbox_shortcode_handler', true );
18
  }
19
 
20
- function cf7bs_checkbox_shortcode_handler( $tag )
21
- {
22
- $tag = new WPCF7_Shortcode( $tag );
23
-
24
- if( empty( $tag->name ) )
25
- {
26
- return '';
27
- }
28
-
29
- $mode = $status = 'default';
30
-
31
- $validation_error = wpcf7_get_validation_error( $tag->name );
32
-
33
- $class = wpcf7_form_controls_class( $tag->type );
34
- if( $validation_error )
35
- {
36
- $class .= ' wpcf7-not-valid';
37
- $status = 'error';
38
- }
39
-
40
- $exclusive = $tag->has_option( 'exclusive' );
41
- $multiple = false;
42
-
43
- if( 'checkbox' == $tag->basetype )
44
- {
45
- $multiple = !$exclusive;
46
- }
47
- else
48
- {
49
- $exclusive = false;
50
- }
51
-
52
- if( $exclusive )
53
- {
54
- $class .= ' wpcf7-exclusive-checkbox';
55
- }
56
-
57
- if( $tag->is_required() )
58
- {
59
- $mode = 'required';
60
- }
61
-
62
- $values = (array) $tag->values;
63
- $labels = (array) $tag->labels;
64
-
65
- if( $data = (array) $tag->get_data_option() )
66
- {
67
- if( $free_text )
68
- {
69
- $values = array_merge( array_slice( $values, 0, -1 ), array_values( $data ), array_slice( $values, -1 ) );
70
- $labels = array_merge( array_slice( $labels, 0, -1 ), array_values( $data ), array_slice( $labels, -1 ) );
71
- }
72
- else
73
- {
74
- $values = array_merge( $values, array_values( $data ) );
75
- $labels = array_merge( $labels, array_values( $data ) );
76
- }
77
- }
78
-
79
- $defaults = array();
80
-
81
- $default_choice = $tag->get_default_option( null, 'multiple=1' );
82
-
83
- foreach( $default_choice as $value )
84
- {
85
- $key = array_search( $value, $values, true );
86
-
87
- if( false !== $key )
88
- {
89
- $defaults[] = (int) $key + 1;
90
- }
91
- }
92
-
93
- if( $matches = $tag->get_first_match_option( '/^default:([0-9_]+)$/' ) )
94
- {
95
- $defaults = array_merge( $defaults, explode( '_', $matches[1] ) );
96
- }
97
-
98
- $defaults = array_unique( $defaults );
99
-
100
- $options = array();
101
- $checked = '';
102
- if( $multiple )
103
- {
104
- $checked = array();
105
- }
106
-
107
- if( isset( $_POST[ $tag->name ] ) )
108
- {
109
- $post = $_POST[ $tag->name ];
110
- }
111
- else
112
- {
113
- if( isset( $_GET[ $tag->name ] ) )
114
- {
115
- if( $multiple )
116
- {
117
- $get = cf7bs_array_decode( rawurldecode( $_GET[ $tag->name ] ) );
118
- }
119
- else
120
- {
121
- $get = rawurldecode( $_GET[ $tag->name ] );
122
- }
123
- }
124
- $post = $multiple ? array() : '';
125
- }
126
- $posted = wpcf7_is_posted();
127
-
128
- foreach( (array) $tag->values as $key => $value )
129
- {
130
- $options[ $value ] = isset( $labels[ $key ] ) ? $labels[ $key ] : $value;
131
-
132
- if( $posted && !empty( $post ) )
133
- {
134
- if( $multiple && in_array( esc_sql( $value ), (array) $post ) )
135
- {
136
- $checked[] = $value;
137
- }
138
- if( !$multiple && $post == esc_sql( $value ) )
139
- {
140
- $checked = $value;
141
- }
142
- }
143
- elseif( isset( $get ) && !empty( $get ) )
144
- {
145
- if( $multiple && in_array( esc_sql( $value ), (array) $get ) )
146
- {
147
- $checked[] = $value;
148
- }
149
- if( !$multiple && $get == esc_sql( $value ) )
150
- {
151
- $checked = $value;
152
- }
153
- }
154
- elseif( in_array( $key + 1, (array) $defaults ) )
155
- {
156
- if( $multiple )
157
- {
158
- $checked[] = $value;
159
- }
160
- else
161
- {
162
- $checked = $value;
163
- }
164
- }
165
- }
166
-
167
- $field = new CF7BS_Form_Field( array(
168
- 'name' => $tag->name,
169
- 'id' => $tag->get_option( 'id', 'id', true ),
170
- 'class' => '',
171
- 'type' => $tag->basetype,
172
- 'value' => $checked,
173
- 'label' => $tag->content,
174
- 'options' => $options,
175
- 'help_text' => $validation_error,
176
- 'size' => cf7bs_get_form_property( 'size' ),
177
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
178
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
179
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
180
- 'group_layout' => cf7bs_get_form_property( 'group_layout' ),
181
- 'mode' => $mode,
182
- 'status' => $status,
183
- 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
184
- 'wrapper_class' => $tag->get_class_option( $class . ' ' . $tag->name ),
185
- ) );
186
-
187
- $html = $field->display( false );
188
-
189
- return $html;
190
- }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_checkbox' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_checkbox' );
10
 
11
+ function cf7bs_add_shortcode_checkbox() {
12
+ wpcf7_add_shortcode( array(
13
+ 'checkbox',
14
+ 'checkbox*',
15
+ 'radio',
16
+ ), 'cf7bs_checkbox_shortcode_handler', true );
 
17
  }
18
 
19
+ function cf7bs_checkbox_shortcode_handler( $tag ) {
20
+ $tag = new WPCF7_Shortcode( $tag );
21
+
22
+ if ( empty( $tag->name ) ) {
23
+ return '';
24
+ }
25
+
26
+ $mode = $status = 'default';
27
+
28
+ $validation_error = wpcf7_get_validation_error( $tag->name );
29
+
30
+ $class = wpcf7_form_controls_class( $tag->type );
31
+ if ( $validation_error ) {
32
+ $class .= ' wpcf7-not-valid';
33
+ $status = 'error';
34
+ }
35
+
36
+ $exclusive = $tag->has_option( 'exclusive' );
37
+ $free_text = $tag->has_option( 'free_text' );
38
+
39
+ $multiple = false;
40
+
41
+ if ( 'checkbox' == $tag->basetype ) {
42
+ $multiple = !$exclusive;
43
+ } else {
44
+ $exclusive = false;
45
+ }
46
+
47
+ if ( $exclusive ) {
48
+ $class .= ' wpcf7-exclusive-checkbox';
49
+ }
50
+
51
+ if ( $tag->is_required() ) {
52
+ $mode = 'required';
53
+ }
54
+
55
+ $values = (array) $tag->values;
56
+ $labels = (array) $tag->labels;
57
+
58
+ if ( $data = (array) $tag->get_data_option() ) {
59
+ if ( $free_text ) {
60
+ $values = array_merge( array_slice( $values, 0, -1 ), array_values( $data ), array_slice( $values, -1 ) );
61
+ $labels = array_merge( array_slice( $labels, 0, -1 ), array_values( $data ), array_slice( $labels, -1 ) );
62
+ } else {
63
+ $values = array_merge( $values, array_values( $data ) );
64
+ $labels = array_merge( $labels, array_values( $data ) );
65
+ }
66
+ }
67
+
68
+ $defaults = array();
69
+
70
+ $default_choice = $tag->get_default_option( null, 'multiple=1' );
71
+
72
+ foreach ( $default_choice as $value ) {
73
+ $key = array_search( $value, $values, true );
74
+
75
+ if ( false !== $key ) {
76
+ $defaults[] = (int) $key + 1;
77
+ }
78
+ }
79
+
80
+ if ( $matches = $tag->get_first_match_option( '/^default:([0-9_]+)$/' ) )
81
+ {
82
+ $defaults = array_merge( $defaults, explode( '_', $matches[1] ) );
83
+ }
84
+
85
+ $defaults = array_unique( $defaults );
86
+
87
+ $options = array();
88
+ $checked = '';
89
+ if ( $multiple ) {
90
+ $checked = array();
91
+ }
92
+
93
+ if ( isset( $_POST[ $tag->name ] ) ) {
94
+ $post = $_POST[ $tag->name ];
95
+ } else {
96
+ if ( isset( $_GET[ $tag->name ] ) ) {
97
+ if ( $multiple ) {
98
+ $get = cf7bs_array_decode( rawurldecode( $_GET[ $tag->name ] ) );
99
+ } else {
100
+ $get = rawurldecode( $_GET[ $tag->name ] );
101
+ }
102
+ }
103
+ $post = $multiple ? array() : '';
104
+ }
105
+ $posted = wpcf7_is_posted();
106
+
107
+ $count = 0;
108
+
109
+ foreach ( (array) $tag->values as $key => $value ) {
110
+ if ( $free_text && $count == count( $tag->values ) - 1 ) {
111
+ $options[ $value ] = '<input type="text" name="' . sprintf( '_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name ) . '" class="wpcf7-free-text">';
112
+ } else {
113
+ $options[ $value ] = isset( $labels[ $key ] ) ? $labels[ $key ] : $value;
114
+ }
115
+
116
+ if ( $posted && ! empty( $post ) ) {
117
+ if ( $multiple && in_array( esc_sql( $value ), (array) $post ) ) {
118
+ $checked[] = $value;
119
+ }
120
+ if ( ! $multiple && $post == esc_sql( $value ) ) {
121
+ $checked = $value;
122
+ }
123
+ } elseif ( isset( $get ) && ! empty( $get ) ) {
124
+ if ( $multiple && in_array( esc_sql( $value ), (array) $get ) ) {
125
+ $checked[] = $value;
126
+ }
127
+ if ( ! $multiple && $get == esc_sql( $value ) ) {
128
+ $checked = $value;
129
+ }
130
+ } elseif ( in_array( $key + 1, (array) $defaults ) ) {
131
+ if ( $multiple ) {
132
+ $checked[] = $value;
133
+ } else {
134
+ $checked = $value;
135
+ }
136
+ }
137
+ $count++;
138
+ }
139
+
140
+ $label = $tag->content;
141
+
142
+ if ( count( $options ) < 1 ) {
143
+ if ( $free_text ) {
144
+ $options = array( 'true' => '<input type="text" name="' . sprintf( '_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name ) . '" class="wpcf7-free-text">' );
145
+ } else {
146
+ $options = array( 'true' => $label );
147
+ $label = '';
148
+ }
149
+ }
150
+
151
+ $field = new CF7BS_Form_Field( array(
152
+ 'name' => $tag->name,
153
+ 'id' => $tag->get_option( 'id', 'id', true ),
154
+ 'class' => '',
155
+ 'type' => $tag->basetype,
156
+ 'value' => $checked,
157
+ 'label' => $label,
158
+ 'options' => $options,
159
+ 'help_text' => $validation_error,
160
+ 'size' => cf7bs_get_form_property( 'size' ),
161
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
162
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
163
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
164
+ 'group_layout' => cf7bs_get_form_property( 'group_layout' ),
165
+ 'group_type' => cf7bs_get_form_property( 'group_type' ),
166
+ 'mode' => $mode,
167
+ 'status' => $status,
168
+ 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
169
+ 'wrapper_class' => $tag->get_class_option( $class . ' ' . $tag->name ),
170
+ ) );
171
+
172
+ $html = $field->display( false );
173
+
174
+ return $html;
175
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
modules/count.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package CF7BS
4
+ * @version 1.2.0
5
+ * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
+ */
7
+
8
+ remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_count' );
9
+ add_action( 'wpcf7_init', 'cf7bs_add_shortcode_count' );
10
+
11
+ function cf7bs_add_shortcode_count() {
12
+ wpcf7_add_shortcode( 'count', 'cf7bs_count_shortcode_handler', true );
13
+ }
14
+
15
+ function cf7bs_count_shortcode_handler( $tag ) {
16
+ $tag_obj = new WPCF7_Shortcode( $tag );
17
+
18
+ if ( empty( $tag_obj->name ) ) {
19
+ return '';
20
+ }
21
+
22
+ $field = new CF7BS_Form_Field( array(
23
+ 'name' => wpcf7_count_shortcode_handler( $tag ),
24
+ 'type' => 'custom',
25
+ 'label' => $tag_obj->content,
26
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
27
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
28
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
29
+ 'tabindex' => false,
30
+ 'wrapper_class' => '',
31
+ ) );
32
+
33
+ $html = $field->display( false );
34
+
35
+ return $html;
36
+ }
modules/date.php CHANGED
@@ -1,90 +1,81 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_date' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_date' );
10
 
11
- function cf7bs_add_shortcode_date()
12
- {
13
- wpcf7_add_shortcode( array(
14
- 'date',
15
- 'date*',
16
- ), 'cf7bs_date_shortcode_handler', true );
17
  }
18
 
19
- function cf7bs_date_shortcode_handler( $tag )
20
- {
21
- $tag = new WPCF7_Shortcode( $tag );
22
 
23
- if( empty( $tag->name ) )
24
- {
25
- return '';
26
- }
27
 
28
- $mode = $status = 'default';
29
 
30
- $validation_error = wpcf7_get_validation_error( $tag->name );
31
 
32
- $class = wpcf7_form_controls_class( $tag->type );
33
- $class .= ' wpcf7-validates-as-date';
34
- if( $validation_error )
35
- {
36
- $class .= ' wpcf7-not-valid';
37
- $status = 'error';
38
- }
39
 
40
- if( $tag->is_required() )
41
- {
42
- $mode = 'required';
43
- }
44
 
45
- $value = (string) reset( $tag->values );
46
- $placeholder = '';
47
- if( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) )
48
- {
49
- $placeholder = $value;
50
- $value = '';
51
- }
52
 
53
- if( wpcf7_is_posted() && isset( $_POST[ $tag->name ] ) )
54
- {
55
- $value = stripslashes_deep( $_POST[ $tag->name ] );
56
- }
57
- elseif( isset( $_GET ) && array_key_exists( $tag->name, $_GET ) )
58
- {
59
- $value = stripslashes_deep( rawurldecode( $_GET[ $tag->name ] ) );
60
- }
61
 
62
- $field = new CF7BS_Form_Field( array(
63
- 'name' => $tag->name,
64
- 'id' => $tag->get_option( 'id', 'id', true ),
65
- 'class' => $tag->get_class_option( $class ),
66
- 'type' => wpcf7_support_html5() ? $tag->basetype : 'text',
67
- 'value' => $value,
68
- 'placeholder' => $placeholder,
69
- 'label' => $tag->content,
70
- 'options' => array(
71
- 'min' => $tag->get_option( 'min', 'date', true ),
72
- 'max' => $tag->get_option( 'max', 'date', true ),
73
- 'step' => $tag->get_option( 'step', 'int', true ),
74
- ),
75
- 'help_text' => $validation_error,
76
- 'size' => cf7bs_get_form_property( 'size' ),
77
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
78
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
79
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
80
- 'mode' => $mode,
81
- 'status' => $status,
82
- 'readonly' => $tag->has_option( 'readonly' ) ? true : false,
83
- 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
84
- 'wrapper_class' => $tag->name,
85
- ) );
86
 
87
- $html = $field->display( false );
88
 
89
- return $html;
90
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_date' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_date' );
10
 
11
+ function cf7bs_add_shortcode_date() {
12
+ wpcf7_add_shortcode( array(
13
+ 'date',
14
+ 'date*',
15
+ ), 'cf7bs_date_shortcode_handler', true );
 
16
  }
17
 
18
+ function cf7bs_date_shortcode_handler( $tag ) {
19
+ $tag = new WPCF7_Shortcode( $tag );
 
20
 
21
+ if ( empty( $tag->name ) ) {
22
+ return '';
23
+ }
 
24
 
25
+ $mode = $status = 'default';
26
 
27
+ $validation_error = wpcf7_get_validation_error( $tag->name );
28
 
29
+ $class = wpcf7_form_controls_class( $tag->type );
30
+ $class .= ' wpcf7-validates-as-date';
31
+ if ( $validation_error ) {
32
+ $class .= ' wpcf7-not-valid';
33
+ $status = 'error';
34
+ }
 
35
 
36
+ if ( $tag->is_required() ) {
37
+ $mode = 'required';
38
+ }
 
39
 
40
+ $value = (string) reset( $tag->values );
41
+ $placeholder = '';
42
+ if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
43
+ $placeholder = $value;
44
+ $value = '';
45
+ }
 
46
 
47
+ if ( wpcf7_is_posted() && isset( $_POST[ $tag->name ] ) ) {
48
+ $value = stripslashes_deep( $_POST[ $tag->name ] );
49
+ } elseif( isset( $_GET ) && array_key_exists( $tag->name, $_GET ) ) {
50
+ $value = stripslashes_deep( rawurldecode( $_GET[ $tag->name ] ) );
51
+ }
 
 
 
52
 
53
+ $field = new CF7BS_Form_Field( array(
54
+ 'name' => $tag->name,
55
+ 'id' => $tag->get_option( 'id', 'id', true ),
56
+ 'class' => $tag->get_class_option( $class ),
57
+ 'type' => wpcf7_support_html5() ? $tag->basetype : 'text',
58
+ 'value' => $value,
59
+ 'placeholder' => $placeholder,
60
+ 'label' => $tag->content,
61
+ 'options' => array(
62
+ 'min' => $tag->get_option( 'min', 'date', true ),
63
+ 'max' => $tag->get_option( 'max', 'date', true ),
64
+ 'step' => $tag->get_option( 'step', 'int', true ),
65
+ ),
66
+ 'help_text' => $validation_error,
67
+ 'size' => cf7bs_get_form_property( 'size' ),
68
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
69
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
70
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
71
+ 'mode' => $mode,
72
+ 'status' => $status,
73
+ 'readonly' => $tag->has_option( 'readonly' ) ? true : false,
74
+ 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
75
+ 'wrapper_class' => $tag->name,
76
+ ) );
77
 
78
+ $html = $field->display( false );
79
 
80
+ return $html;
81
  }
modules/file.php CHANGED
@@ -1,84 +1,75 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_file' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_file' );
10
 
11
- function cf7bs_add_shortcode_file()
12
- {
13
- wpcf7_add_shortcode( array(
14
- 'file',
15
- 'file*',
16
- ), 'cf7bs_file_shortcode_handler', true );
17
  }
18
 
19
- function cf7bs_file_shortcode_handler( $tag )
20
- {
21
- $tag = new WPCF7_Shortcode( $tag );
22
 
23
- if( empty( $tag->name ) )
24
- {
25
- return '';
26
- }
27
 
28
- $mode = $status = 'default';
29
 
30
- $validation_error = wpcf7_get_validation_error( $tag->name );
31
 
32
- $class = wpcf7_form_controls_class( $tag->type );
33
- if( $validation_error )
34
- {
35
- $class .= ' wpcf7-not-valid';
36
- $status = 'error';
37
- }
38
 
39
- // size is not used since Bootstrap input fields always scale 100%
40
- //$atts['size'] = $tag->get_size_option( '40' );
41
 
42
- if( $tag->is_required() )
43
- {
44
- $mode = 'required';
45
- }
46
 
47
- $value = (string) reset( $tag->values );
48
- $placeholder = '';
49
- if( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) )
50
- {
51
- $placeholder = $value;
52
- $value = '';
53
- }
54
- elseif( empty( $value ) )
55
- {
56
- $value = $tag->get_default_option();
57
- }
58
- if( wpcf7_is_posted() && isset( $_POST[$tag->name] ) )
59
- {
60
- $value = stripslashes_deep( $_POST[$tag->name] );
61
- }
62
 
63
- $field = new CF7BS_Form_Field( array(
64
- 'name' => $tag->name,
65
- 'id' => $tag->get_option( 'id', 'id', true ),
66
- 'class' => $tag->get_class_option( $class ),
67
- 'type' => 'file',
68
- 'value' => '1',
69
- 'label' => $tag->content,
70
- 'help_text' => $validation_error,
71
- 'size' => cf7bs_get_form_property( 'size' ),
72
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
73
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
74
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
75
- 'mode' => $mode,
76
- 'status' => $status,
77
- 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
78
- 'wrapper_class' => $tag->name,
79
- ) );
80
 
81
- $html = $field->display( false );
82
 
83
- return $html;
84
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_file' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_file' );
10
 
11
+ function cf7bs_add_shortcode_file() {
12
+ wpcf7_add_shortcode( array(
13
+ 'file',
14
+ 'file*',
15
+ ), 'cf7bs_file_shortcode_handler', true );
 
16
  }
17
 
18
+ function cf7bs_file_shortcode_handler( $tag ) {
19
+ $tag = new WPCF7_Shortcode( $tag );
 
20
 
21
+ if ( empty( $tag->name ) ) {
22
+ return '';
23
+ }
 
24
 
25
+ $mode = $status = 'default';
26
 
27
+ $validation_error = wpcf7_get_validation_error( $tag->name );
28
 
29
+ $class = wpcf7_form_controls_class( $tag->type );
30
+ if ( $validation_error ) {
31
+ $class .= ' wpcf7-not-valid';
32
+ $status = 'error';
33
+ }
 
34
 
35
+ // size is not used since Bootstrap input fields always scale 100%
36
+ //$atts['size'] = $tag->get_size_option( '40' );
37
 
38
+ if ( $tag->is_required() ) {
39
+ $mode = 'required';
40
+ }
 
41
 
42
+ $value = (string) reset( $tag->values );
43
+ $placeholder = '';
44
+ if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
45
+ $placeholder = $value;
46
+ $value = '';
47
+ } elseif ( empty( $value ) ) {
48
+ $value = $tag->get_default_option();
49
+ }
50
+ if ( wpcf7_is_posted() && isset( $_POST[$tag->name] ) ) {
51
+ $value = stripslashes_deep( $_POST[$tag->name] );
52
+ }
 
 
 
 
53
 
54
+ $field = new CF7BS_Form_Field( array(
55
+ 'name' => $tag->name,
56
+ 'id' => $tag->get_option( 'id', 'id', true ),
57
+ 'class' => $tag->get_class_option( $class ),
58
+ 'type' => 'file',
59
+ 'value' => '1',
60
+ 'label' => $tag->content,
61
+ 'help_text' => $validation_error,
62
+ 'size' => cf7bs_get_form_property( 'size' ),
63
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
64
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
65
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
66
+ 'mode' => $mode,
67
+ 'status' => $status,
68
+ 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
69
+ 'wrapper_class' => $tag->name,
70
+ ) );
71
 
72
+ $html = $field->display( false );
73
 
74
+ return $html;
75
  }
modules/number.php CHANGED
@@ -1,92 +1,83 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_number' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_number' );
10
 
11
- function cf7bs_add_shortcode_number()
12
- {
13
- wpcf7_add_shortcode( array(
14
- 'number',
15
- 'number*',
16
- 'range',
17
- 'range*',
18
- ), 'cf7bs_number_shortcode_handler', true );
19
  }
20
 
21
- function cf7bs_number_shortcode_handler( $tag )
22
- {
23
- $tag = new WPCF7_Shortcode( $tag );
24
 
25
- if( empty( $tag->name ) )
26
- {
27
- return '';
28
- }
29
 
30
- $mode = $status = 'default';
31
 
32
- $validation_error = wpcf7_get_validation_error( $tag->name );
33
 
34
- $class = wpcf7_form_controls_class( $tag->type );
35
- $class .= ' wpcf7-validates-as-number';
36
- if( $validation_error )
37
- {
38
- $class .= ' wpcf7-not-valid';
39
- $status = 'error';
40
- }
41
 
42
- if( $tag->is_required() )
43
- {
44
- $mode = 'required';
45
- }
46
 
47
- $value = (string) reset( $tag->values );
48
- $placeholder = '';
49
- if( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) )
50
- {
51
- $placeholder = $value;
52
- $value = '';
53
- }
54
 
55
- if( wpcf7_is_posted() && isset( $_POST[ $tag->name ] ) )
56
- {
57
- $value = stripslashes_deep( $_POST[ $tag->name ] );
58
- }
59
- elseif( isset( $_GET ) && array_key_exists( $tag->name, $_GET ) )
60
- {
61
- $value = stripslashes_deep( rawurldecode( $_GET[ $tag->name ] ) );
62
- }
63
 
64
- $field = new CF7BS_Form_Field( array(
65
- 'name' => $tag->name,
66
- 'id' => $tag->get_option( 'id', 'id', true ),
67
- 'class' => $tag->get_class_option( $class ),
68
- 'type' => wpcf7_support_html5() ? $tag->basetype : 'text',
69
- 'value' => $value,
70
- 'placeholder' => $placeholder,
71
- 'label' => $tag->content,
72
- 'options' => array(
73
- 'min' => $tag->get_option( 'min', 'signed_int', true ),
74
- 'max' => $tag->get_option( 'max', 'signed_int', true ),
75
- 'step' => $tag->get_option( 'step', 'int', true ),
76
- ),
77
- 'help_text' => $validation_error,
78
- 'size' => cf7bs_get_form_property( 'size' ),
79
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
80
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
81
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
82
- 'mode' => $mode,
83
- 'status' => $status,
84
- 'readonly' => $tag->has_option( 'readonly' ) ? true : false,
85
- 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
86
- 'wrapper_class' => $tag->name,
87
- ) );
88
 
89
- $html = $field->display( false );
90
 
91
- return $html;
92
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_number' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_number' );
10
 
11
+ function cf7bs_add_shortcode_number() {
12
+ wpcf7_add_shortcode( array(
13
+ 'number',
14
+ 'number*',
15
+ 'range',
16
+ 'range*',
17
+ ), 'cf7bs_number_shortcode_handler', true );
 
18
  }
19
 
20
+ function cf7bs_number_shortcode_handler( $tag ) {
21
+ $tag = new WPCF7_Shortcode( $tag );
 
22
 
23
+ if ( empty( $tag->name ) ) {
24
+ return '';
25
+ }
 
26
 
27
+ $mode = $status = 'default';
28
 
29
+ $validation_error = wpcf7_get_validation_error( $tag->name );
30
 
31
+ $class = wpcf7_form_controls_class( $tag->type );
32
+ $class .= ' wpcf7-validates-as-number';
33
+ if ( $validation_error ) {
34
+ $class .= ' wpcf7-not-valid';
35
+ $status = 'error';
36
+ }
 
37
 
38
+ if ( $tag->is_required() ) {
39
+ $mode = 'required';
40
+ }
 
41
 
42
+ $value = (string) reset( $tag->values );
43
+ $placeholder = '';
44
+ if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
45
+ $placeholder = $value;
46
+ $value = '';
47
+ }
 
48
 
49
+ if ( wpcf7_is_posted() && isset( $_POST[ $tag->name ] ) ) {
50
+ $value = stripslashes_deep( $_POST[ $tag->name ] );
51
+ } elseif ( isset( $_GET ) && array_key_exists( $tag->name, $_GET ) ) {
52
+ $value = stripslashes_deep( rawurldecode( $_GET[ $tag->name ] ) );
53
+ }
 
 
 
54
 
55
+ $field = new CF7BS_Form_Field( array(
56
+ 'name' => $tag->name,
57
+ 'id' => $tag->get_option( 'id', 'id', true ),
58
+ 'class' => $tag->get_class_option( $class ),
59
+ 'type' => wpcf7_support_html5() ? $tag->basetype : 'text',
60
+ 'value' => $value,
61
+ 'placeholder' => $placeholder,
62
+ 'label' => $tag->content,
63
+ 'options' => array(
64
+ 'min' => $tag->get_option( 'min', 'signed_int', true ),
65
+ 'max' => $tag->get_option( 'max', 'signed_int', true ),
66
+ 'step' => $tag->get_option( 'step', 'int', true ),
67
+ ),
68
+ 'help_text' => $validation_error,
69
+ 'size' => cf7bs_get_form_property( 'size' ),
70
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
71
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
72
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
73
+ 'mode' => $mode,
74
+ 'status' => $status,
75
+ 'readonly' => $tag->has_option( 'readonly' ) ? true : false,
76
+ 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
77
+ 'wrapper_class' => $tag->name,
78
+ ) );
79
 
80
+ $html = $field->display( false );
81
 
82
+ return $html;
83
  }
modules/quiz.php CHANGED
@@ -1,74 +1,70 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_quiz' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_quiz' );
10
 
11
- function cf7bs_add_shortcode_quiz()
12
- {
13
- wpcf7_add_shortcode( 'quiz', 'cf7bs_quiz_shortcode_handler', true );
14
  }
15
 
16
- function cf7bs_quiz_shortcode_handler( $tag )
17
- {
18
- $tag = new WPCF7_Shortcode( $tag );
19
 
20
- if( empty( $tag->name ) )
21
- {
22
- return '';
23
- }
24
 
25
- $status = 'default';
26
 
27
- $validation_error = wpcf7_get_validation_error( $tag->name );
28
 
29
- $class = wpcf7_form_controls_class( $tag->type );
30
- if( $validation_error )
31
- {
32
- $class .= ' wpcf7-not-valid';
33
- $status = 'error';
34
- }
35
 
36
- // size is not used since Bootstrap input fields always scale 100%
37
- //$atts['size'] = $tag->get_size_option( '40' );
38
 
39
- $pipes = $tag->pipes;
40
- if ( is_a( $pipes, 'WPCF7_Pipes' ) && ! $pipes->zero() ) {
41
- $pipe = $pipes->random_pipe();
42
- $question = $pipe->before;
43
- $answer = $pipe->after;
44
- } else {
45
- // default quiz
46
- $question = '1+1=?';
47
- $answer = '2';
48
- }
49
- $answer = wpcf7_canonicalize( $answer );
50
 
51
- $field = new CF7BS_Form_Field( array(
52
- 'name' => $tag->name,
53
- 'id' => $tag->get_option( 'id', 'id', true ),
54
- 'class' => $tag->get_class_option( $class ),
55
- 'type' => 'text',
56
- 'value' => '',
57
- 'placeholder' => '',
58
- 'label' => $tag->content,
59
- 'help_text' => $validation_error,
60
- 'size' => cf7bs_get_form_property( 'size' ),
61
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
62
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
63
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
64
- 'status' => $status,
65
- 'maxlength' => $tag->get_maxlength_option(),
66
- 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
67
- 'wrapper_class' => $tag->name,
68
- ) );
69
 
70
- $html = $field->display( false );
71
- $hidden_html = sprintf( '<input type="hidden" name="_wpcf7_quiz_answer_%1$s" value="%2$s">', $tag->name, wp_hash( $answer, 'wpcf7_quiz' ) );
72
 
73
- return str_replace( '<input', '<p class="wpcf7-quiz-label">' . esc_html( $question ) . '</p>' . $hidden_html . '<input', $html );
74
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_quiz' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_quiz' );
10
 
11
+ function cf7bs_add_shortcode_quiz() {
12
+ wpcf7_add_shortcode( 'quiz', 'cf7bs_quiz_shortcode_handler', true );
 
13
  }
14
 
15
+ function cf7bs_quiz_shortcode_handler( $tag ) {
16
+ $tag = new WPCF7_Shortcode( $tag );
 
17
 
18
+ if ( empty( $tag->name ) ) {
19
+ return '';
20
+ }
 
21
 
22
+ $status = 'default';
23
 
24
+ $validation_error = wpcf7_get_validation_error( $tag->name );
25
 
26
+ $class = wpcf7_form_controls_class( $tag->type );
27
+ if ( $validation_error ) {
28
+ $class .= ' wpcf7-not-valid';
29
+ $status = 'error';
30
+ }
 
31
 
32
+ // size is not used since Bootstrap input fields always scale 100%
33
+ //$atts['size'] = $tag->get_size_option( '40' );
34
 
35
+ $pipes = $tag->pipes;
36
+ if ( is_a( $pipes, 'WPCF7_Pipes' ) && ! $pipes->zero() ) {
37
+ $pipe = $pipes->random_pipe();
38
+ $question = $pipe->before;
39
+ $answer = $pipe->after;
40
+ } else {
41
+ // default quiz
42
+ $question = '1+1=?';
43
+ $answer = '2';
44
+ }
45
+ $answer = wpcf7_canonicalize( $answer );
46
 
47
+ $field = new CF7BS_Form_Field( array(
48
+ 'name' => $tag->name,
49
+ 'id' => $tag->get_option( 'id', 'id', true ),
50
+ 'class' => $tag->get_class_option( $class ),
51
+ 'type' => 'text',
52
+ 'value' => '',
53
+ 'placeholder' => '',
54
+ 'label' => $tag->content,
55
+ 'help_text' => $validation_error,
56
+ 'size' => cf7bs_get_form_property( 'size' ),
57
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
58
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
59
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
60
+ 'status' => $status,
61
+ 'maxlength' => $tag->get_maxlength_option(),
62
+ 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
63
+ 'wrapper_class' => $tag->name,
64
+ ) );
65
 
66
+ $html = $field->display( false );
67
+ $hidden_html = sprintf( '<input type="hidden" name="_wpcf7_quiz_answer_%1$s" value="%2$s">', $tag->name, wp_hash( $answer, 'wpcf7_quiz' ) );
68
 
69
+ return str_replace( '<input', '<p class="wpcf7-quiz-label">' . esc_html( $question ) . '</p>' . $hidden_html . '<input', $html );
70
  }
modules/select.php CHANGED
@@ -1,163 +1,132 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_select' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_select' );
10
 
11
- function cf7bs_add_shortcode_select()
12
- {
13
- wpcf7_add_shortcode( array(
14
- 'select',
15
- 'select*',
16
- ), 'cf7bs_select_shortcode_handler', true );
17
  }
18
 
19
- function cf7bs_select_shortcode_handler( $tag )
20
- {
21
- $tag = new WPCF7_Shortcode( $tag );
22
-
23
- if( empty( $tag->name ) )
24
- {
25
- return '';
26
- }
27
-
28
- $mode = $status = 'default';
29
-
30
- $validation_error = wpcf7_get_validation_error( $tag->name );
31
-
32
- $class = wpcf7_form_controls_class( $tag->type );
33
- if( $validation_error )
34
- {
35
- $class .= ' wpcf7-not-valid';
36
- $status = 'error';
37
- }
38
-
39
- if( $tag->is_required() )
40
- {
41
- $mode = 'required';
42
- }
43
-
44
- $defaults = array();
45
- if( $matches = $tag->get_first_match_option( '/^default:([0-9_]+)$/' ) )
46
- {
47
- $defaults = explode( '_', $matches[1] );
48
- }
49
- $multiple = $tag->has_option( 'multiple' );
50
- $include_blank = $tag->has_option( 'include_blank' );
51
- $first_as_label = $tag->has_option( 'first_as_label' );
52
-
53
- $values = $tag->values;
54
- $labels = $tag->labels;
55
-
56
- if( $data = (array) $tag->get_data_option() )
57
- {
58
- $values = array_merge( $values, array_values( $data ) );
59
- $labels = array_merge( $labels, array_values( $data ) );
60
- }
61
-
62
- $empty_select = empty( $values );
63
-
64
- if( $empty_select || $include_blank )
65
- {
66
- array_unshift( $labels, '---' );
67
- array_unshift( $values, '' );
68
- }
69
- elseif( $first_as_label )
70
- {
71
- $values[0] = '';
72
- }
73
-
74
- $options = array();
75
- $selected = '';
76
- if( $multiple )
77
- {
78
- $selected = array();
79
- }
80
-
81
- if( isset( $_POST[ $tag->name ] ) )
82
- {
83
- $post = $_POST[ $tag->name ];
84
- }
85
- else
86
- {
87
- if( isset( $_GET[ $tag->name ] ) )
88
- {
89
- if( $multiple )
90
- {
91
- $get = cf7bs_array_decode( rawurldecode( $_GET[ $tag->name ] ) );
92
- }
93
- else
94
- {
95
- $get = rawurldecode( $_GET[ $tag->name ] );
96
- }
97
- }
98
- $post = $multiple ? array() : '';
99
- }
100
- $posted = wpcf7_is_posted();
101
-
102
- foreach( $values as $key => $value )
103
- {
104
- $options[ $value ] = isset( $labels[ $key ] ) ? $labels[ $key ] : $value;
105
-
106
- if( $posted && !empty( $post ) )
107
- {
108
- if( $multiple && in_array( esc_sql( $value ), (array) $post ) )
109
- {
110
- $selected[] = $value;
111
- }
112
- if( !$multiple && $post == esc_sql( $value ) )
113
- {
114
- $selected = $value;
115
- }
116
- }
117
- elseif( isset( $get ) && !empty( $get ) )
118
- {
119
- if( $multiple && in_array( esc_sql( $value ), (array) $get ) )
120
- {
121
- $selected[] = $value;
122
- }
123
- if( !$multiple && $get == esc_sql( $value ) )
124
- {
125
- $selected = $value;
126
- }
127
- }
128
- elseif( !$empty_select && in_array( $key + 1, (array) $defaults ) )
129
- {
130
- if( $multiple )
131
- {
132
- $selected[] = $value;
133
- }
134
- else
135
- {
136
- $selected = $value;
137
- }
138
- }
139
- }
140
-
141
- $field = new CF7BS_Form_Field( array(
142
- 'name' => $tag->name,
143
- 'id' => $tag->get_option( 'id', 'id', true ),
144
- 'class' => $tag->get_class_option( $class ),
145
- 'type' => $multiple ? 'multiselect' : 'select',
146
- 'value' => $selected,
147
- 'label' => $tag->content,
148
- 'options' => $options,
149
- 'help_text' => $validation_error,
150
- 'size' => cf7bs_get_form_property( 'size' ),
151
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
152
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
153
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
154
- 'mode' => $mode,
155
- 'status' => $status,
156
- 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
157
- 'wrapper_class' => $tag->name,
158
- ) );
159
-
160
- $html = $field->display( false );
161
-
162
- return $html;
163
- }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_select' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_select' );
10
 
11
+ function cf7bs_add_shortcode_select() {
12
+ wpcf7_add_shortcode( array(
13
+ 'select',
14
+ 'select*',
15
+ ), 'cf7bs_select_shortcode_handler', true );
 
16
  }
17
 
18
+ function cf7bs_select_shortcode_handler( $tag ) {
19
+ $tag = new WPCF7_Shortcode( $tag );
20
+
21
+ if ( empty( $tag->name ) ) {
22
+ return '';
23
+ }
24
+
25
+ $mode = $status = 'default';
26
+
27
+ $validation_error = wpcf7_get_validation_error( $tag->name );
28
+
29
+ $class = wpcf7_form_controls_class( $tag->type );
30
+ if ( $validation_error ) {
31
+ $class .= ' wpcf7-not-valid';
32
+ $status = 'error';
33
+ }
34
+
35
+ if ( $tag->is_required() ) {
36
+ $mode = 'required';
37
+ }
38
+
39
+ $defaults = array();
40
+ if ( $matches = $tag->get_first_match_option( '/^default:([0-9_]+)$/' ) ) {
41
+ $defaults = explode( '_', $matches[1] );
42
+ }
43
+ $multiple = $tag->has_option( 'multiple' );
44
+ $include_blank = $tag->has_option( 'include_blank' );
45
+ $first_as_label = $tag->has_option( 'first_as_label' );
46
+
47
+ $values = $tag->values;
48
+ $labels = $tag->labels;
49
+
50
+ if ( $data = (array) $tag->get_data_option() ) {
51
+ $values = array_merge( $values, array_values( $data ) );
52
+ $labels = array_merge( $labels, array_values( $data ) );
53
+ }
54
+
55
+ $empty_select = empty( $values );
56
+
57
+ if ( $empty_select || $include_blank ) {
58
+ array_unshift( $labels, '---' );
59
+ array_unshift( $values, '' );
60
+ } elseif ( $first_as_label ) {
61
+ $values[0] = '';
62
+ }
63
+
64
+ $options = array();
65
+ $selected = '';
66
+ if ( $multiple ) {
67
+ $selected = array();
68
+ }
69
+
70
+ if ( isset( $_POST[ $tag->name ] ) ) {
71
+ $post = $_POST[ $tag->name ];
72
+ } else {
73
+ if ( isset( $_GET[ $tag->name ] ) ) {
74
+ if ( $multiple ) {
75
+ $get = cf7bs_array_decode( rawurldecode( $_GET[ $tag->name ] ) );
76
+ } else {
77
+ $get = rawurldecode( $_GET[ $tag->name ] );
78
+ }
79
+ }
80
+ $post = $multiple ? array() : '';
81
+ }
82
+ $posted = wpcf7_is_posted();
83
+
84
+ foreach ( $values as $key => $value ) {
85
+ $options[ $value ] = isset( $labels[ $key ] ) ? $labels[ $key ] : $value;
86
+
87
+ if ( $posted && !empty( $post ) ) {
88
+ if ( $multiple && in_array( esc_sql( $value ), (array) $post ) ) {
89
+ $selected[] = $value;
90
+ }
91
+ if ( ! $multiple && $post == esc_sql( $value ) ) {
92
+ $selected = $value;
93
+ }
94
+ } elseif ( isset( $get ) && !empty( $get ) ) {
95
+ if ( $multiple && in_array( esc_sql( $value ), (array) $get ) ) {
96
+ $selected[] = $value;
97
+ }
98
+ if ( ! $multiple && $get == esc_sql( $value ) ) {
99
+ $selected = $value;
100
+ }
101
+ } elseif( ! $empty_select && in_array( $key + 1, (array) $defaults ) ) {
102
+ if ( $multiple ) {
103
+ $selected[] = $value;
104
+ } else {
105
+ $selected = $value;
106
+ }
107
+ }
108
+ }
109
+
110
+ $field = new CF7BS_Form_Field( array(
111
+ 'name' => $tag->name,
112
+ 'id' => $tag->get_option( 'id', 'id', true ),
113
+ 'class' => $tag->get_class_option( $class ),
114
+ 'type' => $multiple ? 'multiselect' : 'select',
115
+ 'value' => $selected,
116
+ 'label' => $tag->content,
117
+ 'options' => $options,
118
+ 'help_text' => $validation_error,
119
+ 'size' => cf7bs_get_form_property( 'size' ),
120
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
121
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
122
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
123
+ 'mode' => $mode,
124
+ 'status' => $status,
125
+ 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
126
+ 'wrapper_class' => $tag->name,
127
+ ) );
128
+
129
+ $html = $field->display( false );
130
+
131
+ return $html;
132
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
modules/submit.php CHANGED
@@ -1,45 +1,42 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_submit' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_submit' );
10
 
11
- function cf7bs_add_shortcode_submit()
12
- {
13
- wpcf7_add_shortcode( 'submit', 'cf7bs_submit_shortcode_handler' );
14
  }
15
 
16
- function cf7bs_submit_shortcode_handler( $tag )
17
- {
18
- $tag = new WPCF7_Shortcode( $tag );
19
-
20
- $class = wpcf7_form_controls_class( $tag->type );
21
-
22
- $value = isset( $tag->values[0] ) ? $tag->values[0] : '';
23
- if( empty( $value ) )
24
- {
25
- $value = __( 'Send', 'contact-form-7' );
26
- }
27
-
28
- $button = new CF7BS_Button( array(
29
- 'mode' => 'submit',
30
- 'id' => $tag->get_option( 'id', 'id', true ),
31
- 'class' => $tag->get_class_option( $class ),
32
- 'title' => $value,
33
- 'type' => cf7bs_get_form_property( 'submit_type' ),
34
- 'size' => cf7bs_get_form_property( 'size' ),
35
- 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
36
- 'align' => $tag->get_option( 'align', '[A-Za-z]+', true ),
37
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
38
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
39
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
40
- ) );
41
-
42
- $html = $button->display( false );
43
-
44
- return $html;
45
- }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_submit' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_submit' );
10
 
11
+ function cf7bs_add_shortcode_submit() {
12
+ wpcf7_add_shortcode( 'submit', 'cf7bs_submit_shortcode_handler' );
 
13
  }
14
 
15
+ function cf7bs_submit_shortcode_handler( $tag ) {
16
+ $tag = new WPCF7_Shortcode( $tag );
17
+
18
+ $class = wpcf7_form_controls_class( $tag->type );
19
+
20
+ $value = isset( $tag->values[0] ) ? $tag->values[0] : '';
21
+ if ( empty( $value ) ) {
22
+ $value = __( 'Send', 'contact-form-7' );
23
+ }
24
+
25
+ $button = new CF7BS_Button( array(
26
+ 'mode' => 'submit',
27
+ 'id' => $tag->get_option( 'id', 'id', true ),
28
+ 'class' => $tag->get_class_option( $class ),
29
+ 'title' => $value,
30
+ 'type' => cf7bs_get_form_property( 'submit_type' ),
31
+ 'size' => cf7bs_get_form_property( 'size' ),
32
+ 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
33
+ 'align' => $tag->get_option( 'align', '[A-Za-z]+', true ),
34
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
35
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
36
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
37
+ ) );
38
+
39
+ $html = $button->display( false );
40
+
41
+ return $html;
42
+ }
 
 
modules/text.php CHANGED
@@ -1,101 +1,106 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_text' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_text' );
10
 
11
- function cf7bs_add_shortcode_text()
12
- {
13
- wpcf7_add_shortcode( array(
14
- 'text',
15
- 'text*',
16
- 'email',
17
- 'email*',
18
- 'url',
19
- 'url*',
20
- 'tel',
21
- 'tel*',
22
- ), 'cf7bs_text_shortcode_handler', true );
23
  }
24
 
25
- function cf7bs_text_shortcode_handler( $tag )
26
- {
27
- $tag = new WPCF7_Shortcode( $tag );
28
-
29
- if( empty( $tag->name ) )
30
- {
31
- return '';
32
- }
33
-
34
- $mode = $status = 'default';
35
-
36
- $validation_error = wpcf7_get_validation_error( $tag->name );
37
-
38
- $class = wpcf7_form_controls_class( $tag->type, 'wpcf7-text' );
39
- if( in_array( $tag->basetype, array( 'email', 'url', 'tel' ) ) )
40
- {
41
- $class .= ' wpcf7-validates-as-' . $tag->basetype;
42
- }
43
- if( $validation_error )
44
- {
45
- $class .= ' wpcf7-not-valid';
46
- $status = 'error';
47
- }
48
-
49
- // size is not used since Bootstrap input fields always scale 100%
50
- //$atts['size'] = $tag->get_size_option( '40' );
51
-
52
- if( $tag->is_required() )
53
- {
54
- $mode = 'required';
55
- }
56
-
57
- $value = (string) reset( $tag->values );
58
- $placeholder = '';
59
- if( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) )
60
- {
61
- $placeholder = $value;
62
- $value = '';
63
- }
64
- elseif( empty( $value ) )
65
- {
66
- $value = $tag->get_default_option();
67
- }
68
- if( wpcf7_is_posted() && isset( $_POST[ $tag->name ] ) )
69
- {
70
- $value = stripslashes_deep( $_POST[ $tag->name ] );
71
- }
72
- elseif( isset( $_GET ) && array_key_exists( $tag->name, $_GET ) )
73
- {
74
- $value = stripslashes_deep( rawurldecode( $_GET[ $tag->name ] ) );
75
- }
76
-
77
- $field = new CF7BS_Form_Field( array(
78
- 'name' => $tag->name,
79
- 'id' => $tag->get_option( 'id', 'id', true ),
80
- 'class' => $tag->get_class_option( $class ),
81
- 'type' => wpcf7_support_html5() ? $tag->basetype : 'text',
82
- 'value' => $value,
83
- 'placeholder' => $placeholder,
84
- 'label' => $tag->content,
85
- 'help_text' => $validation_error,
86
- 'size' => cf7bs_get_form_property( 'size' ),
87
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
88
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
89
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
90
- 'mode' => $mode,
91
- 'status' => $status,
92
- 'readonly' => $tag->has_option( 'readonly' ) ? true : false,
93
- 'maxlength' => $tag->get_maxlength_option(),
94
- 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
95
- 'wrapper_class' => $tag->name,
96
- ) );
97
-
98
- $html = $field->display( false );
99
-
100
- return $html;
 
 
 
 
 
 
101
  }
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_text' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_text' );
10
 
11
+ function cf7bs_add_shortcode_text() {
12
+ wpcf7_add_shortcode( array(
13
+ 'text',
14
+ 'text*',
15
+ 'email',
16
+ 'email*',
17
+ 'url',
18
+ 'url*',
19
+ 'tel',
20
+ 'tel*',
21
+ ), 'cf7bs_text_shortcode_handler', true );
 
22
  }
23
 
24
+ function cf7bs_text_shortcode_handler( $tag ) {
25
+ $tag = new WPCF7_Shortcode( $tag );
26
+
27
+ $input_before = $tag->get_first_match_option( '/input_before:([^\s]+)/' );
28
+ $input_after = $tag->get_first_match_option( '/input_after:([^\s]+)/' );
29
+
30
+ if ( is_array( $input_before ) && isset( $input_before[1] ) ) {
31
+ $input_before = $input_before[1];
32
+ } else {
33
+ $input_before = '';
34
+ }
35
+
36
+ if ( is_array( $input_after ) && isset( $input_after[1] ) ) {
37
+ $input_after = $input_after[1];
38
+ } else {
39
+ $input_after = '';
40
+ }
41
+
42
+ if ( empty( $tag->name ) ) {
43
+ return '';
44
+ }
45
+
46
+ $mode = $status = 'default';
47
+
48
+ $validation_error = wpcf7_get_validation_error( $tag->name );
49
+
50
+ $class = wpcf7_form_controls_class( $tag->type, 'wpcf7-text' );
51
+ if ( in_array( $tag->basetype, array( 'email', 'url', 'tel' ) ) ) {
52
+ $class .= ' wpcf7-validates-as-' . $tag->basetype;
53
+ }
54
+ if ( $validation_error ) {
55
+ $class .= ' wpcf7-not-valid';
56
+ $status = 'error';
57
+ }
58
+
59
+ // size is not used since Bootstrap input fields always scale 100%
60
+ //$atts['size'] = $tag->get_size_option( '40' );
61
+
62
+ if ( $tag->is_required() ) {
63
+ $mode = 'required';
64
+ }
65
+
66
+ $value = (string) reset( $tag->values );
67
+ $placeholder = '';
68
+ if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
69
+ $placeholder = $value;
70
+ $value = '';
71
+ } elseif ( empty( $value ) ) {
72
+ $value = $tag->get_default_option();
73
+ }
74
+ if ( wpcf7_is_posted() && isset( $_POST[ $tag->name ] ) ) {
75
+ $value = stripslashes_deep( $_POST[ $tag->name ] );
76
+ } elseif ( isset( $_GET ) && array_key_exists( $tag->name, $_GET ) ) {
77
+ $value = stripslashes_deep( rawurldecode( $_GET[ $tag->name ] ) );
78
+ }
79
+
80
+ $field = new CF7BS_Form_Field( array(
81
+ 'name' => $tag->name,
82
+ 'id' => $tag->get_option( 'id', 'id', true ),
83
+ 'class' => $tag->get_class_option( $class ),
84
+ 'type' => wpcf7_support_html5() ? $tag->basetype : 'text',
85
+ 'value' => $value,
86
+ 'placeholder' => $placeholder,
87
+ 'label' => $tag->content,
88
+ 'help_text' => $validation_error,
89
+ 'size' => cf7bs_get_form_property( 'size' ),
90
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
91
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
92
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
93
+ 'mode' => $mode,
94
+ 'status' => $status,
95
+ 'readonly' => $tag->has_option( 'readonly' ) ? true : false,
96
+ 'maxlength' => $tag->get_maxlength_option(),
97
+ 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
98
+ 'wrapper_class' => $tag->name,
99
+ 'input_before' => $input_before,
100
+ 'input_after' => $input_after,
101
+ ) );
102
+
103
+ $html = $field->display( false );
104
+
105
+ return $html;
106
  }
modules/textarea.php CHANGED
@@ -1,88 +1,85 @@
1
  <?php
2
  /**
3
  * @package CF7BS
4
- * @version 1.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_textarea' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_textarea' );
10
 
11
- function cf7bs_add_shortcode_textarea()
12
- {
13
- wpcf7_add_shortcode( array(
14
- 'textarea',
15
- 'textarea*',
16
- ), 'cf7bs_textarea_shortcode_handler', true );
17
  }
18
 
19
- function cf7bs_textarea_shortcode_handler( $tag )
20
- {
21
- $tag = new WPCF7_Shortcode( $tag );
22
 
23
- if( empty( $tag->name ) )
24
- {
25
- return '';
26
- }
27
 
28
- $mode = $status = 'default';
29
 
30
- $validation_error = wpcf7_get_validation_error( $tag->name );
31
 
32
- $class = wpcf7_form_controls_class( $tag->type );
33
- if( $validation_error )
34
- {
35
- $class .= ' wpcf7-not-valid';
36
- $status = 'error';
37
- }
38
 
39
- // cols is not used since Bootstrap input fields always scale 100%
40
- //$atts['cols'] = $tag->get_cols_option( '40' );
41
 
42
- if( $tag->is_required() )
43
- {
44
- $mode = 'required';
45
- }
46
 
47
- $value = (string) reset( $tag->values );
48
- $placeholder = '';
49
- if( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) )
50
- {
51
- $placeholder = $value;
52
- $value = '';
53
- }
54
 
55
- if( wpcf7_is_posted() && isset( $_POST[ $tag->name ] ) )
56
- {
57
- $value = stripslashes_deep( $_POST[ $tag->name ] );
58
- }
59
- elseif( isset( $_GET ) && array_key_exists( $tag->name, $_GET ) )
60
- {
61
- $value = stripslashes_deep( rawurldecode( $_GET[ $tag->name ] ) );
62
- }
63
 
64
- $field = new CF7BS_Form_Field( array(
65
- 'name' => $tag->name,
66
- 'id' => $tag->get_option( 'id', 'id', true ),
67
- 'class' => $tag->get_class_option( $class ),
68
- 'type' => 'textarea',
69
- 'value' => $value,
70
- 'placeholder' => $placeholder,
71
- 'label' => $tag->content,
72
- 'help_text' => $validation_error,
73
- 'size' => cf7bs_get_form_property( 'size' ),
74
- 'form_layout' => cf7bs_get_form_property( 'layout' ),
75
- 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
76
- 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
77
- 'mode' => $mode,
78
- 'status' => $status,
79
- 'readonly' => $tag->has_option( 'readonly' ) ? true : false,
80
- 'maxlength' => $tag->get_maxlength_option(),
81
- 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
82
- 'wrapper_class' => $tag->name,
83
- ) );
84
 
85
- $html = $field->display( false );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
- return $html;
88
- }
 
 
1
  <?php
2
  /**
3
  * @package CF7BS
4
+ * @version 1.2.0
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
  remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_textarea' );
9
  add_action( 'wpcf7_init', 'cf7bs_add_shortcode_textarea' );
10
 
11
+ function cf7bs_add_shortcode_textarea() {
12
+ wpcf7_add_shortcode( array(
13
+ 'textarea',
14
+ 'textarea*',
15
+ ), 'cf7bs_textarea_shortcode_handler', true );
 
16
  }
17
 
18
+ function cf7bs_textarea_shortcode_handler( $tag ) {
19
+ $tag = new WPCF7_Shortcode( $tag );
 
20
 
21
+ if ( empty( $tag->name ) ) {
22
+ return '';
23
+ }
 
24
 
25
+ $mode = $status = 'default';
26
 
27
+ $validation_error = wpcf7_get_validation_error( $tag->name );
28
 
29
+ $class = wpcf7_form_controls_class( $tag->type );
30
+ if ( $validation_error ) {
31
+ $class .= ' wpcf7-not-valid';
32
+ $status = 'error';
33
+ }
 
34
 
35
+ // cols is not used since Bootstrap input fields always scale 100%
36
+ //$atts['cols'] = $tag->get_cols_option( '40' );
37
 
38
+ if ( $tag->is_required() ) {
39
+ $mode = 'required';
40
+ }
 
41
 
42
+ $value = (string) reset( $tag->values );
43
+ $placeholder = '';
44
+ if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
45
+ $placeholder = $value;
46
+ $value = '';
47
+ }
 
48
 
49
+ if ( wpcf7_is_posted() && isset( $_POST[ $tag->name ] ) ) {
50
+ $value = stripslashes_deep( $_POST[ $tag->name ] );
51
+ } elseif ( isset( $_GET ) && array_key_exists( $tag->name, $_GET ) ) {
52
+ $value = stripslashes_deep( rawurldecode( $_GET[ $tag->name ] ) );
53
+ }
 
 
 
54
 
55
+ $rows = $tag->get_rows_option();
56
+ if ( ! $rows ) {
57
+ $rows = 4;
58
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
+ $field = new CF7BS_Form_Field( array(
61
+ 'name' => $tag->name,
62
+ 'id' => $tag->get_option( 'id', 'id', true ),
63
+ 'class' => $tag->get_class_option( $class ),
64
+ 'type' => 'textarea',
65
+ 'value' => $value,
66
+ 'placeholder' => $placeholder,
67
+ 'label' => $tag->content,
68
+ 'help_text' => $validation_error,
69
+ 'size' => cf7bs_get_form_property( 'size' ),
70
+ 'form_layout' => cf7bs_get_form_property( 'layout' ),
71
+ 'form_label_width' => cf7bs_get_form_property( 'label_width' ),
72
+ 'form_breakpoint' => cf7bs_get_form_property( 'breakpoint' ),
73
+ 'mode' => $mode,
74
+ 'status' => $status,
75
+ 'readonly' => $tag->has_option( 'readonly' ) ? true : false,
76
+ 'maxlength' => $tag->get_maxlength_option(),
77
+ 'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
78
+ 'wrapper_class' => $tag->name,
79
+ 'rows' => $rows,
80
+ ) );
81
 
82
+ $html = $field->display( false );
83
+
84
+ return $html;
85
+ }
package.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "name": "bootstrap-for-contact-form-7",
3
  "pluginName": "Bootstrap for Contact Form 7",
4
- "version": "1.1.1",
5
  "description": "This plugin modifies the output of the popular Contact Form 7 plugin to be styled in compliance with themes using the Bootstrap CSS framework.",
6
  "keywords": [
7
  "wordpress", "plugin", "contact form 7", "wpcf7", "bootstrap", "bootstrap 3", "bootstrap framework", "addon", "contact form 7 addon", "contact form", "cf7bs", "css"
@@ -35,4 +35,4 @@
35
  "grunt-banner": "~0.2.3",
36
  "grunt-text-replace": "~0.3.12"
37
  }
38
- }
1
  {
2
  "name": "bootstrap-for-contact-form-7",
3
  "pluginName": "Bootstrap for Contact Form 7",
4
+ "version": "1.2.0",
5
  "description": "This plugin modifies the output of the popular Contact Form 7 plugin to be styled in compliance with themes using the Bootstrap CSS framework.",
6
  "keywords": [
7
  "wordpress", "plugin", "contact form 7", "wpcf7", "bootstrap", "bootstrap 3", "bootstrap framework", "addon", "contact form 7 addon", "contact form", "cf7bs", "css"
35
  "grunt-banner": "~0.2.3",
36
  "grunt-text-replace": "~0.3.12"
37
  }
38
+ }
readme.txt CHANGED
@@ -8,8 +8,8 @@ Donate link: http://leaves-and-love.net/wordpress-plugins/
8
  Contributors: flixos90
9
  Requires at least: 3.6
10
  Tested up to: 4.2
11
- Stable tag: 1.1.1
12
- Version: 1.1.1
13
  License: GPL v2
14
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
15
  Tags: contact form 7, wpcf7, bootstrap, bootstrap 3, bootstrap framework, addon, css framework, contact form 7 addon, contact form, cf7bs, css
@@ -51,21 +51,29 @@ When using a well-known framework which provides general styles for all the impo
51
 
52
  = How can I use a different form layout for my form? =
53
 
54
- To modify the layout (or one of the other six form properties), you need to use the filter `'cf7bs_form_' . $form_id . '_properties'` where `$form_id` must be the ID of the form you'd like to modify. You find this number in the form shortcode. An array is passed to the function you specify, containing entries with the following keys:
55
 
56
- * `layout` - possible values: default, inline, horizontal; default value: default
57
- * `label_width` - possible values: any integer between 1 and 11; default value: 3
58
- * `breakpoint` - possible values: xs, sm, md, lg; default value: sm
59
- * `size` - possible values: default, small, large; default value: default
60
- * `required_html` - possible values: any HTML output to append to labels for required fields; default value: `<span class="required">*</span>`
61
- * `group_layout` - possible values: default, inline, buttons; default value: default
62
- * `group_type` - possible values: default, primary, success, info, warning, danger; default value: default
63
- * `submit_type` - possible values: default, primary, success, info, warning, danger; default value: primary
 
 
 
 
64
 
65
  So if you need to change the layout to a horizontal one, the function can look like this: `function yourfunction( $properties ) { $properties['layout'] = 'horizontal'; return $properties; }`
66
 
67
  You could also modify the default form properties (affecting every form on your site) by using the filter `cf7bs_default_form_properties`.
68
 
 
 
 
 
69
  = Why do my labels always appear in a separate line? =
70
 
71
  If your labels still appear in a separate line although you have already changed the layout, you might still be using the shortcode the same way you did before. Please read the description to see what to look out for.
@@ -94,6 +102,19 @@ If you're a developer and you have some ideas to improve the plugin or to solve
94
 
95
  == Changelog ==
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  = 1.1.1 =
98
  * Fixed: exclusive option for checkbox now working
99
  * Fixed: default option for radio/checkbox now working
8
  Contributors: flixos90
9
  Requires at least: 3.6
10
  Tested up to: 4.2
11
+ Stable tag: 1.2.0
12
+ Version: 1.2.0
13
  License: GPL v2
14
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
15
  Tags: contact form 7, wpcf7, bootstrap, bootstrap 3, bootstrap framework, addon, css framework, contact form 7 addon, contact form, cf7bs, css
51
 
52
  = How can I use a different form layout for my form? =
53
 
54
+ The easiest method to modify the layout (or one of the other seven form properties) is to add the properties and their desired values into the "Additional Settings" tab of Contact Form 7 (note that you need to have a current version of CF7 to have that feature available).
55
 
56
+ As an alternative (or if you're using an older version), you could also use the filter `'cf7bs_form_' . $form_id . '_properties'` where `$form_id` must be the ID of the form you'd like to modify. You find this number in the form shortcode. An array of `'property' => 'property_value'` is passed to the function you specify so that you can override the defaults.
57
+
58
+ The following is a list of the eight available form properties, valid values for them and their default values.
59
+
60
+ * `layout` - adjusts the form's layout; valid values: default, inline, horizontal; default value: default
61
+ * `label_width` - adjusts the form's label width (applies only to horizontal layout); valid values: any integer between 1 and 11; default value: 3
62
+ * `breakpoint` - adjusts the responsive breakpoint (applies only to horizontal layout); valid values: xs, sm, md, lg; default value: sm
63
+ * `size` - adjusts the size of all input fields; valid values: default, small, large; default value: default
64
+ * `required_html` - adjusts the HTML output to append to required fields' labels; valid values: any HTML output; default value: `<span class="required">*</span>`
65
+ * `group_layout` - adjusts the layout of checkbox and radio groups; valid values: default, inline, buttons; default value: default
66
+ * `group_type` - adjusts the color of checkbox and radio groups with buttons layout; valid values: default, primary, success, info, warning, danger; default value: default
67
+ * `submit_type` - adjusts the color of the submit button; valid values: default, primary, success, info, warning, danger; default value: primary
68
 
69
  So if you need to change the layout to a horizontal one, the function can look like this: `function yourfunction( $properties ) { $properties['layout'] = 'horizontal'; return $properties; }`
70
 
71
  You could also modify the default form properties (affecting every form on your site) by using the filter `cf7bs_default_form_properties`.
72
 
73
+ = How do I use the input group feature of Bootstrap? =
74
+
75
+ All textual input fields support the input group feature that Bootstrap provides. To use it, add an attribute `input_before` and/or `input_after` to any text / email / url / tel input (for example `[text* twitter-username input_before:@]Your Twitter Handle[/text*]`).
76
+
77
  = Why do my labels always appear in a separate line? =
78
 
79
  If your labels still appear in a separate line although you have already changed the layout, you might still be using the shortcode the same way you did before. Please read the description to see what to look out for.
102
 
103
  == Changelog ==
104
 
105
+ = 1.2.0 =
106
+ * Added: new CF7 count shortcode is now supported
107
+ * Enhanced: form properties can now be modified without any code (i.e. without a filter); the properties can be defined in the new "Additional Settings" tab of Contact Form 7
108
+ * Enhanced: textual inputs now support Bootstrap's input group feature
109
+ * Enhanced: checkbox and radio types can now show an actual label; it is only used as the checkbox label if no option is provided
110
+ * Tweaked: plugin now adheres to WordPress Coding Standards
111
+ * Fixed: improved display method for captcha images
112
+ * Fixed: textarea row attribute now honored
113
+ * Fixed: free_text attribute on checkbox and radio types now honored
114
+ * Fixed: form attribute 'group_type' now honored
115
+ * Fixed: additional CF7 styles are now outputted in the head
116
+ * Fixed: check if CF7 functions are available before calling them
117
+
118
  = 1.1.1 =
119
  * Fixed: exclusive option for checkbox now working
120
  * Fixed: default option for radio/checkbox now working