Visual Form Builder - Version 1.1

Version Description

Bug fix for all checkbox options not being submitted

Download this release

Release Info

Developer mmuro
Plugin Icon 128x128 Visual Form Builder
Version 1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1

Files changed (2) hide show
  1. readme.txt +13 -2
  2. visual-form-builder.php +61 -7
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: mmuro
3
  Tags: form, forms, form to email, email form, email, input, validation, jquery, shortcode
4
  Requires at least: 3.0
5
  Tested up to: 3.2
6
- Stable tag: 1.0
7
 
8
  Dynamically build forms using a simple interface. Forms include jQuery validation and a basic logic-based verification system.
9
 
@@ -79,6 +79,17 @@ To use the more complex features of the Date Picker plugin, you will need to:
79
 
80
  == Changelog ==
81
 
 
 
 
 
 
 
82
  **Version 1.0**
83
 
84
- * Plugin launch!
 
 
 
 
 
3
  Tags: form, forms, form to email, email form, email, input, validation, jquery, shortcode
4
  Requires at least: 3.0
5
  Tested up to: 3.2
6
+ Stable tag: 1.1
7
 
8
  Dynamically build forms using a simple interface. Forms include jQuery validation and a basic logic-based verification system.
9
 
79
 
80
  == Changelog ==
81
 
82
+ **Version 1.1**
83
+
84
+ * Fix bug that prevented all selected checkbox options from being submitted
85
+ * Add more help text on contextual Help tab
86
+ * Fix missing closing paragraph tag on success message
87
+
88
  **Version 1.0**
89
 
90
+ * Plugin launch!
91
+
92
+ == Upgrade Notice ==
93
+
94
+ = 1.1 =
95
+ Bug fix for all checkbox options not being submitted
visual-form-builder.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Visual Form Builder
4
  Description: Dynamically build forms using a simple interface. Forms include jQuery validation and a basic logic-based verification system.
5
  Author: Matthew Muro
6
- Version: 1.0
7
  */
8
 
9
  /*
@@ -27,6 +27,8 @@ $visual_form_builder = new Visual_Form_Builder();
27
  /* Restrict Categories class */
28
  class Visual_Form_Builder{
29
 
 
 
30
  public function __construct(){
31
  global $wpdb;
32
 
@@ -62,10 +64,20 @@ class Visual_Form_Builder{
62
  add_action( 'template_redirect', array( &$this, 'form_validation' ) );
63
  }
64
 
 
 
 
 
 
65
  public function form_admin_css(){
66
  wp_enqueue_style( 'visual-form-builder-style', plugins_url( 'visual-form-builder' ) . '/css/visual-form-builder-admin.css' );
67
  }
68
 
 
 
 
 
 
69
  public function add_visual_form_builder_contextual_help(){
70
  $text = "<p><strong>Getting Started</strong></p>
71
  <ul>
@@ -75,6 +87,24 @@ class Visual_Form_Builder{
75
  <li>Drag and drop the elements to put them in order.</li>
76
  <li>Click Save Form to save your changes.</li>
77
  </ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  <p><strong>Tips</strong></p>
79
  <ul>
80
  <li>Fieldsets, a way to group form fields, are an essential piece of this plugin's HTML. As such, at least one fieldset is required and must be first in the order. Subsequent fieldsets may be placed wherever you would like to start your next grouping of fields.</li>
@@ -84,9 +114,18 @@ class Visual_Form_Builder{
84
 
85
  add_contextual_help( 'settings_page_visual-form-builder', $text );
86
  }
 
 
 
 
 
 
87
  static function install_db() {
88
  global $wpdb;
89
 
 
 
 
90
  $field_table_name = $wpdb->prefix . 'visual_form_builder_fields';
91
  $form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
92
 
@@ -126,6 +165,14 @@ class Visual_Form_Builder{
126
  /* Check to see if the table already exists before creating it */
127
  if ( $wpdb->get_var( "SHOW TABLES LIKE '$form_table_name'" ) != $form_table_name )
128
  dbDelta( $form_sql );
 
 
 
 
 
 
 
 
129
  }
130
 
131
  /**
@@ -733,7 +780,7 @@ class Visual_Form_Builder{
733
  $open_fieldset = false;
734
 
735
  if ( isset( $_REQUEST['success'] ) && $_REQUEST['success'] == 1 && wp_verify_nonce( $_REQUEST['key'], 'visual-form-builder-success-nonce' ) ) {
736
- $output = '<p id="form_success">Your form was successfully submitted. Thank you for contacting us.';
737
  }
738
  else {
739
  foreach ( $forms as $form ) :
@@ -801,6 +848,7 @@ class Visual_Form_Builder{
801
  $output .= '<span><label>' . $field->field_description . '</label></span>';
802
 
803
  $options = explode( ',', unserialize( $field->field_options ) );
 
804
  $output .= '<div>';
805
 
806
  /* Loop through each option and output */
@@ -826,8 +874,8 @@ class Visual_Form_Builder{
826
 
827
  /* Loop through each option and output */
828
  foreach ( $options as $option => $value ) {
829
- $output .= '<span><input type="checkbox" name="'. $field->field_key. '" id="'. $field->field_key. '" value="'. $value . '" class="checkbox ' . $required . '" />'.
830
- ' <label for="' . $field->field_key . '" class="choice">' . $value . '</label></span>';
831
  }
832
 
833
  $output .= '</div>';
@@ -1166,7 +1214,7 @@ class Visual_Form_Builder{
1166
  public function email() {
1167
  global $wpdb, $post;
1168
 
1169
- /* Resets the options */
1170
  if ( isset( $_REQUEST['visual-form-builder-submit'] ) && $_REQUEST['visual-form-builder-submit'] == 'Submit' && $_REQUEST['spam'] == '' && is_numeric( $_REQUEST['secret'] ) && strlen( $_REQUEST['secret'] ) == 2 ) {
1171
  $nonce = $_REQUEST['_wpnonce'];
1172
 
@@ -1177,6 +1225,7 @@ class Visual_Form_Builder{
1177
  /* Set submitted action to display success message */
1178
  $this->submitted = true;
1179
 
 
1180
  $form_id = absint( $_REQUEST['form_id'] );
1181
 
1182
  /* Query to get all forms */
@@ -1186,6 +1235,7 @@ class Visual_Form_Builder{
1186
  /* Build our forms as an object */
1187
  $forms = $wpdb->get_results( $query );
1188
 
 
1189
  foreach ( $forms as $form ) {
1190
  $form_title = $form->form_title;
1191
  $form_subject = $form->form_email_subject;
@@ -1199,10 +1249,13 @@ class Visual_Form_Builder{
1199
 
1200
  /* Loop through each form field and build the body of the message */
1201
  foreach ( $_POST as $key => $value ) {
 
1202
  $key = strtolower( str_replace( '-', ' ', $key ) );
1203
 
1204
- $value = esc_html( $value );
 
1205
 
 
1206
  if ( !in_array( $key, array( 'spam', 'secret', 'visual form builder submit', '_wpnonce', 'form_id' ) ) )
1207
  $message .= '<tr><td><strong>' . ucwords( $key ) . ': </strong></td><td>' . $value . '</td></tr>';
1208
  }
@@ -1234,5 +1287,6 @@ class Visual_Form_Builder{
1234
  }
1235
  }
1236
 
1237
- register_activation_hook(__FILE__, array( 'Visual_Form_Builder', 'install_db' ) );
 
1238
  ?>
3
  Plugin Name: Visual Form Builder
4
  Description: Dynamically build forms using a simple interface. Forms include jQuery validation and a basic logic-based verification system.
5
  Author: Matthew Muro
6
+ Version: 1.1
7
  */
8
 
9
  /*
27
  /* Restrict Categories class */
28
  class Visual_Form_Builder{
29
 
30
+ public $vfb_db_version = '1.1';
31
+
32
  public function __construct(){
33
  global $wpdb;
34
 
64
  add_action( 'template_redirect', array( &$this, 'form_validation' ) );
65
  }
66
 
67
+ /**
68
+ * Queue plugin CSS for admin styles
69
+ *
70
+ * @since 1.0
71
+ */
72
  public function form_admin_css(){
73
  wp_enqueue_style( 'visual-form-builder-style', plugins_url( 'visual-form-builder' ) . '/css/visual-form-builder-admin.css' );
74
  }
75
 
76
+ /**
77
+ * Register contextual help. This is for the Help tab dropdown
78
+ *
79
+ * @since 1.0
80
+ */
81
  public function add_visual_form_builder_contextual_help(){
82
  $text = "<p><strong>Getting Started</strong></p>
83
  <ul>
87
  <li>Drag and drop the elements to put them in order.</li>
88
  <li>Click Save Form to save your changes.</li>
89
  </ul>
90
+ <p><strong>Form Item Configuration</strong></p>
91
+ <ul>
92
+ <li><em>Name</em> will change the display name of your form input.</li>
93
+ <li><em>Description</em> will be displayed below the associated input.</li>
94
+ <li><em>Validation</em> allows you to select from several of jQuery's Form Validation methods for text inputs. For more about the types of validation, read the <em>Validation</em> section below.</li>
95
+ <li><em>Required</em> is either Yes or No. Selecting 'Yes' will make the associated input a required field and the form will not submit until the user fills this field out correctly.</li>
96
+ <li><em>Options</em> will only be active for Radio and Checkboxes. This field contols how many options are available for the associated input. Multiple options must be separated by commas (ex: <em>Option 1, Option 2, Option 3</em>).</li>
97
+ <li><em>Size</em> controls the width of Text, Textarea, Select, and Date Picker input fields. The default is set to Medium but if you need a longer text input, select Large.</li>
98
+ </ul>
99
+ <p><strong>Validation</strong><p>
100
+ <ul>
101
+ <li>Visual Form Builder uses the <a href='http://docs.jquery.com/Plugins/Validation/Validator'>jQuery Form Validation plugin</a> to perform clientside form validation.</li>
102
+ <li><em>Email</em>: makes the element require a valid email.</li>
103
+ <li><em>URL</em>: makes the element require a valid url.</li>
104
+ <li><em>Date</em>: makes the element require a date. <a href='http://docs.jquery.com/Plugins/Validation/Methods/date'>Refer to documentation for various accepted formats</a>.
105
+ <li><em>Number</em>: makes the element require a decimal number.</li>
106
+ <li><em>Digits</em>: makes the element require digits only.</li>
107
+ </ul>
108
  <p><strong>Tips</strong></p>
109
  <ul>
110
  <li>Fieldsets, a way to group form fields, are an essential piece of this plugin's HTML. As such, at least one fieldset is required and must be first in the order. Subsequent fieldsets may be placed wherever you would like to start your next grouping of fields.</li>
114
 
115
  add_contextual_help( 'settings_page_visual-form-builder', $text );
116
  }
117
+
118
+ /**
119
+ * Install database tables
120
+ *
121
+ * @since 1.0
122
+ */
123
  static function install_db() {
124
  global $wpdb;
125
 
126
+ /* Declare version again here because this is a static function */
127
+ $vfb_db_version = '1.1';
128
+
129
  $field_table_name = $wpdb->prefix . 'visual_form_builder_fields';
130
  $form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
131
 
165
  /* Check to see if the table already exists before creating it */
166
  if ( $wpdb->get_var( "SHOW TABLES LIKE '$form_table_name'" ) != $form_table_name )
167
  dbDelta( $form_sql );
168
+
169
+ /* Add a database version to help with upgrades */
170
+ if ( !get_option( 'vfb_db_version' ) )
171
+ update_option( 'vfb_db_version', $vfb_db_version );
172
+
173
+ if ( get_option( 'vfb_db_version' ) != $vfb_db_version )
174
+ update_option( 'vfb_db_version', $vfb_db_version );
175
+
176
  }
177
 
178
  /**
780
  $open_fieldset = false;
781
 
782
  if ( isset( $_REQUEST['success'] ) && $_REQUEST['success'] == 1 && wp_verify_nonce( $_REQUEST['key'], 'visual-form-builder-success-nonce' ) ) {
783
+ $output = '<p id="form_success">Your form was successfully submitted. Thank you for contacting us.</p>';
784
  }
785
  else {
786
  foreach ( $forms as $form ) :
848
  $output .= '<span><label>' . $field->field_description . '</label></span>';
849
 
850
  $options = explode( ',', unserialize( $field->field_options ) );
851
+
852
  $output .= '<div>';
853
 
854
  /* Loop through each option and output */
874
 
875
  /* Loop through each option and output */
876
  foreach ( $options as $option => $value ) {
877
+ $output .= '<span><input type="checkbox" name="'. $field->field_key. '[]" id="'. $field->field_key. '" value="'. trim( $value ) . '" class="checkbox ' . $required . '" />'.
878
+ ' <label for="' . $field->field_key . '" class="choice">' . trim( $value ) . '</label></span>';
879
  }
880
 
881
  $output .= '</div>';
1214
  public function email() {
1215
  global $wpdb, $post;
1216
 
1217
+ /* Security check before moving any further */
1218
  if ( isset( $_REQUEST['visual-form-builder-submit'] ) && $_REQUEST['visual-form-builder-submit'] == 'Submit' && $_REQUEST['spam'] == '' && is_numeric( $_REQUEST['secret'] ) && strlen( $_REQUEST['secret'] ) == 2 ) {
1219
  $nonce = $_REQUEST['_wpnonce'];
1220
 
1225
  /* Set submitted action to display success message */
1226
  $this->submitted = true;
1227
 
1228
+ /* Tells us which form to get from the database */
1229
  $form_id = absint( $_REQUEST['form_id'] );
1230
 
1231
  /* Query to get all forms */
1235
  /* Build our forms as an object */
1236
  $forms = $wpdb->get_results( $query );
1237
 
1238
+ /* Get sender and email details */
1239
  foreach ( $forms as $form ) {
1240
  $form_title = $form->form_title;
1241
  $form_subject = $form->form_email_subject;
1249
 
1250
  /* Loop through each form field and build the body of the message */
1251
  foreach ( $_POST as $key => $value ) {
1252
+ /* Remove dashes and lowercase */
1253
  $key = strtolower( str_replace( '-', ' ', $key ) );
1254
 
1255
+ /* If there are multiple values, build the list, otherwise it's a single value */
1256
+ $value = is_array( $value ) ? implode( ', ', $value ) : esc_html( $value );
1257
 
1258
+ /* Hide fields that aren't necessary to the body of the message */
1259
  if ( !in_array( $key, array( 'spam', 'secret', 'visual form builder submit', '_wpnonce', 'form_id' ) ) )
1260
  $message .= '<tr><td><strong>' . ucwords( $key ) . ': </strong></td><td>' . $value . '</td></tr>';
1261
  }
1287
  }
1288
  }
1289
 
1290
+ /* On plugin activation, install the databases and add/update the DB version */
1291
+ register_activation_hook( __FILE__, array( 'Visual_Form_Builder', 'install_db' ) );
1292
  ?>