Visual Form Builder - Version 1.3

Version Description

New, faster way to add form items and ability to customize Confirmation. Fix for validation on security field.

Download this release

Release Info

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

Code changes from version 1.2.1 to 1.3

class-entries-list.php CHANGED
@@ -271,11 +271,11 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
271
  $data[] =
272
  array(
273
  'entry_id' => $entry->entries_id,
274
- 'form' => $entry->form_title,
275
- 'subject' => $entry->subject,
276
- 'sender_name' => $entry->sender_name,
277
- 'sender_email' => $entry->sender_email,
278
- 'emails_to' => implode( ',', unserialize( $entry->emails_to ) ),
279
  'date' => $entry->date_submitted,
280
  'ip_address' => $entry->ip_address,
281
  'data' => unserialize( $entry->data )
271
  $data[] =
272
  array(
273
  'entry_id' => $entry->entries_id,
274
+ 'form' => stripslashes( $entry->form_title ),
275
+ 'subject' => stripslashes( $entry->subject ),
276
+ 'sender_name' => stripslashes( $entry->sender_name ),
277
+ 'sender_email' => stripslashes( $entry->sender_email ),
278
+ 'emails_to' => implode( ',', unserialize( stripslashes( $entry->emails_to ) ) ),
279
  'date' => $entry->date_submitted,
280
  'ip_address' => $entry->ip_address,
281
  'data' => unserialize( $entry->data )
css/visual-form-builder-admin.css CHANGED
@@ -1,6 +1,6 @@
1
  label.error{color:red;display:block;}
2
  #visual-form-builder-update input.error, #visual-form-builder-update textarea.error{border:1px solid red;}
3
- .menu-item-handle.fieldset{
4
  background-image: -moz-linear-gradient(top, #E3E3E3 0%, #CCCCCC 100%);
5
  background-image: -o-linear-gradient(top, #E3E3E3 0%, #CCCCCC 100%);
6
  background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #E3E3E3), color-stop(1, #CCCCCC));
@@ -15,4 +15,39 @@ label.error{color:red;display:block;}
15
  .visual-form-builder-inline-edit .title{display:block;float:left;width:5em;font-style:italic;}
16
  .visual-form-builder-inline-edit .input-text-wrap{display:block;margin-left:5em;}
17
  .visual-form-builder-inline-edit .input-text-wrap input[type="text"]{width:100%;border:#DDD solid 1px;border-radius:3px;}
18
- .subsubsub{float:none;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  label.error{color:red;display:block;}
2
  #visual-form-builder-update input.error, #visual-form-builder-update textarea.error{border:1px solid red;}
3
+ .menu-item-handle.fieldset, #form-element-fieldset{
4
  background-image: -moz-linear-gradient(top, #E3E3E3 0%, #CCCCCC 100%);
5
  background-image: -o-linear-gradient(top, #E3E3E3 0%, #CCCCCC 100%);
6
  background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #E3E3E3), color-stop(1, #CCCCCC));
15
  .visual-form-builder-inline-edit .title{display:block;float:left;width:5em;font-style:italic;}
16
  .visual-form-builder-inline-edit .input-text-wrap{display:block;margin-left:5em;}
17
  .visual-form-builder-inline-edit .input-text-wrap input[type="text"]{width:100%;border:#DDD solid 1px;border-radius:3px;}
18
+ .subsubsub{float:none;}
19
+ .nav-tabs-arrow-left{display:none;}
20
+ #form-items input{width:104px;float:left;margin:0 5px 10px 0;}
21
+ #form-element-text{background:url(sprite.png) 0 -89px no-repeat transparent;}
22
+ #form-element-textarea{background:url(sprite.png) 0 -173px no-repeat transparent;}
23
+ #form-element-checkbox{background:url(sprite.png) 0 -259px no-repeat transparent;}
24
+ #form-element-radio{background:url(sprite.png) 0 -51px no-repeat transparent;}
25
+ #form-element-select{background:url(sprite.png) 0 -7px no-repeat transparent;}
26
+ #form-element-address{background:url(sprite.png) 0 -129px no-repeat transparent;}
27
+ #form-element-datepicker{background:url(sprite.png) 0 -215px no-repeat transparent;}
28
+ #form-element-email{background:url(sprite.png) 0 -304px no-repeat transparent;}
29
+ #form-element-url{background:url(sprite.png) 0 -356px no-repeat transparent;}
30
+ #form-element-currency{background:url(sprite.png) 0 -405px no-repeat transparent;}
31
+ #form-element-digits{background:url(sprite.png) 0 -452px no-repeat transparent;}
32
+ #form-element-time{background:url(sprite.png) 0 -489px no-repeat transparent;}
33
+ #form-element-phone{background:url(sprite.png) 0 -529px no-repeat transparent;}
34
+ #form-details-nav{font-size:1.0em;font-weight:bold;padding-top:10px;}
35
+ #form-details-nav a{padding:5px 10px;text-decoration:none;}
36
+ #form-details-nav a.current{
37
+ background-color:#777;
38
+ background-image: -ms-linear-gradient(bottom, #6d6d6d, #808080); /* IE10 */
39
+ background-image: -moz-linear-gradient(bottom, #6d6d6d, #808080); /* Firefox */
40
+ background-image: -o-linear-gradient(bottom, #6d6d6d, #808080); /* Opera */
41
+ background-image: -webkit-gradient(linear, left bottom, left top, from(#6d6d6d), to(#808080)); /* old Webkit */
42
+ background-image: -webkit-linear-gradient(bottom, #6d6d6d, #808080); /* new Webkit */
43
+ background-image: linear-gradient(bottom, #6d6d6d, #808080); /* proposed W3C Markup */
44
+ color:white;
45
+ border-radius:5px;
46
+ height:40px;
47
+ text-shadow:0 -1px 0 #333333;
48
+ border-color: #dfdfdf;
49
+ }
50
+ .form-details, #form-success-message-text, #form-success-message-page, #form-success-message-redirect{display:none;}
51
+ .form-details-current, .active{display:block;}
52
+ #confirmation-message textarea{font-family:Consolas,Monaco,monospace;width:75%;height:10em;margin-top:10px;}
53
+ #form-success-message-page, #form-success-message-redirect{margin-top:10px;}
css/visual-form-builder.css CHANGED
@@ -29,6 +29,7 @@ form.visual-form-builder li{width:auto !important;}
29
  width:48%;
30
  }
31
  .visual-form-builder span.right input, .visual-form-builder span.right select, .visual-form-builder span.left input, .visual-form-builder span.left select{width:100%;}
 
32
  .visual-form-builder li div label, .visual-form-builder li span label{font-size:90%;}
33
  .visual-form-builder fieldset{
34
  background-color:#eeeeee;
@@ -43,7 +44,9 @@ form.visual-form-builder li{width:auto !important;}
43
  padding:0 6px;
44
  color:#990000;
45
  border-bottom:1px dotted #CCCCCC;
 
46
  }
 
47
  .visual-form-builder label, label.desc{
48
  display:block;
49
  margin:0;
29
  width:48%;
30
  }
31
  .visual-form-builder span.right input, .visual-form-builder span.right select, .visual-form-builder span.left input, .visual-form-builder span.left select{width:100%;}
32
+ .visual-form-builder span.time{float:left;margin:0 0.3em 0 0;}
33
  .visual-form-builder li div label, .visual-form-builder li span label{font-size:90%;}
34
  .visual-form-builder fieldset{
35
  background-color:#eeeeee;
44
  padding:0 6px;
45
  color:#990000;
46
  border-bottom:1px dotted #CCCCCC;
47
+ font-size:inherit;
48
  }
49
+ .visual-form-builder .legend h3{font-size:20px;}
50
  .visual-form-builder label, label.desc{
51
  display:block;
52
  margin:0;
js/visual-form-builder-validate.js CHANGED
@@ -1,7 +1,7 @@
1
  jQuery(document).ready(function($) {
2
  $( '.visual-form-builder' ).validate({
3
  rules: {
4
- secret:{
5
  maxlength:2
6
  }
7
  },
@@ -15,6 +15,17 @@ jQuery(document).ready(function($) {
15
  }
16
  });
17
 
 
 
 
 
 
 
 
 
 
 
 
18
  /* Display jQuery UI date picker */
19
  $( '.vfb-date-picker' ).datepicker();
20
  });
1
  jQuery(document).ready(function($) {
2
  $( '.visual-form-builder' ).validate({
3
  rules: {
4
+ "vfb-secret":{
5
  maxlength:2
6
  }
7
  },
15
  }
16
  });
17
 
18
+ /* Custom validation method to check multiple emails */
19
+ $.validator.addMethod( 'phone', function( value, element ) {
20
+ /* Strip out all spaces, periods, dashes, parentheses, and plus signs */
21
+ value = value.replace(/[\+\s\(\)\.\-\ ]/g, '');
22
+
23
+ return this.optional(element) || value.length > 9 &&
24
+ value.match( /^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/ );
25
+
26
+ }, 'Please enter a valid phone number. Most US/Canada and International formats accepted.'
27
+ );
28
+
29
  /* Display jQuery UI date picker */
30
  $( '.vfb-date-picker' ).datepicker();
31
  });
js/visual-form-builder.js CHANGED
@@ -22,9 +22,6 @@ jQuery(document).ready(function($) {
22
  tabsWidth[i] = Math.abs( $(this).outerWidth() ) + 6;
23
  });
24
 
25
- /* Hide the left arrow on load */
26
- $( '.nav-tabs-arrow-left' ).hide();
27
-
28
  var count = 0;
29
 
30
  /* Move tabs to the right */
@@ -111,11 +108,8 @@ jQuery(document).ready(function($) {
111
  }
112
  });
113
 
114
- /* Hide the spinner on load */
115
- $('img.waiting').hide();
116
-
117
  /* Show/hide the spinner image when creating a field */
118
- $( '#submit-create-field' ).click( function(e){
119
  $.ajax({
120
  url: ajaxurl,
121
  async: false,
@@ -126,6 +120,31 @@ jQuery(document).ready(function($) {
126
  });
127
  });
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  /* Validate the sender details section */
130
  $( '#visual-form-builder-update' ).validate({
131
  rules: {
@@ -133,7 +152,9 @@ jQuery(document).ready(function($) {
133
  required: true
134
  },
135
  form_email_from_name: {
136
- required: true
 
 
137
  },
138
  form_email_to: {
139
  required: true,
@@ -144,7 +165,10 @@ jQuery(document).ready(function($) {
144
  return $( '#form_email_from_override option:selected' ).val() == ''
145
  },
146
  email: true
147
- }
 
 
 
148
  },
149
  errorPlacement: function( error, element ) {
150
  error.insertAfter( element.parent() );
22
  tabsWidth[i] = Math.abs( $(this).outerWidth() ) + 6;
23
  });
24
 
 
 
 
25
  var count = 0;
26
 
27
  /* Move tabs to the right */
108
  }
109
  });
110
 
 
 
 
111
  /* Show/hide the spinner image when creating a field */
112
+ $( '#form-items' ).submit( function(e){
113
  $.ajax({
114
  url: ajaxurl,
115
  async: false,
120
  });
121
  });
122
 
123
+ /* Display the selected confirmation type on load */
124
+ var confirmation = $( '.form-success-type:checked' ).val();
125
+ $( '#form-success-message-' + confirmation ).show();
126
+
127
+ /* Control the Confirmation Message tabs */
128
+ $( '.form-success-type' ).change(function(){
129
+ var type = $( this ).val();
130
+
131
+ if ( 'text' == type ) {
132
+ $( '#form-success-message-text' ).show();
133
+ $( '#form-success-message-page' ).hide();
134
+ $( '#form-success-message-redirect' ).hide();
135
+ }
136
+ else if ( 'page' == type ) {
137
+ $( '#form-success-message-text' ).hide();
138
+ $( '#form-success-message-page' ).show();
139
+ $( '#form-success-message-redirect' ).hide();
140
+ }
141
+ else if ( 'redirect' == type ) {
142
+ $( '#form-success-message-text' ).hide();
143
+ $( '#form-success-message-page' ).hide();
144
+ $( '#form-success-message-redirect' ).show();
145
+ }
146
+ });
147
+
148
  /* Validate the sender details section */
149
  $( '#visual-form-builder-update' ).validate({
150
  rules: {
152
  required: true
153
  },
154
  form_email_from_name: {
155
+ required : function( element ){
156
+ return $( '#form_email_from_name_override option:selected' ).val() == ''
157
+ }
158
  },
159
  form_email_to: {
160
  required: true,
165
  return $( '#form_email_from_override option:selected' ).val() == ''
166
  },
167
  email: true
168
+ },
169
+ form_success_message_redirect: {
170
+ url: true
171
+ },
172
  },
173
  errorPlacement: function( error, element ) {
174
  error.insertAfter( element.parent() );
readme.txt CHANGED
@@ -1,15 +1,15 @@
1
  === Visual Form Builder ===
2
  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.1
6
- Stable tag: 1.2.1
7
 
8
  Dynamically build forms using a simple interface. Forms include jQuery validation, a basic logic-based verification system, and entry tracking.
9
 
10
  == Description ==
11
 
12
- *Visual Form Builder* is a plugin that allows you to build simple contact forms using an easy-to-use and familiar interface.
13
 
14
  **Features**
15
 
@@ -18,7 +18,9 @@ Dynamically build forms using a simple interface. Forms include jQuery validatio
18
  * Store form entries in your WordPress database and can manage them via the dashboard.
19
  * Send form submissions to multiple emails
20
  * Utilizes jQuery Form Validation
21
- * Save time by adding a complete address block field
 
 
22
  * Easy date fields using the jQuery UI Date Picker
23
 
24
  == Installation ==
@@ -81,6 +83,14 @@ To use the more complex features of the Date Picker plugin, you will need to:
81
 
82
  == Changelog ==
83
 
 
 
 
 
 
 
 
 
84
  **Version 1.2.1**
85
 
86
  * Fix bug where entries table does not install
@@ -105,5 +115,8 @@ To use the more complex features of the Date Picker plugin, you will need to:
105
 
106
  == Upgrade Notice ==
107
 
 
 
 
108
  = 1.2.1 =
109
  Recommended update immediately! Fix for bug where entries table does not install.
1
  === Visual Form Builder ===
2
  Contributors: mmuro
3
  Tags: form, forms, form to email, email form, email, input, validation, jquery, shortcode
4
+ Requires at least: 3.1
5
  Tested up to: 3.2.1
6
+ Stable tag: 1.3
7
 
8
  Dynamically build forms using a simple interface. Forms include jQuery validation, a basic logic-based verification system, and entry tracking.
9
 
10
  == Description ==
11
 
12
+ *Visual Form Builder* is a plugin that allows you to build contact forms using an easy-to-use and familiar interface.
13
 
14
  **Features**
15
 
18
  * Store form entries in your WordPress database and can manage them via the dashboard.
19
  * Send form submissions to multiple emails
20
  * Utilizes jQuery Form Validation
21
+ * Customized Confirmation Messages
22
+ * Redirect to a WordPress Page or a URL
23
+ * Standard and Advanced Fields
24
  * Easy date fields using the jQuery UI Date Picker
25
 
26
  == Installation ==
83
 
84
  == Changelog ==
85
 
86
+ **Version 1.3**
87
+
88
+ * Fix bug where jQuery validation was missing from security field
89
+ * Update Form Items UI to make it easier and quicker to add fields
90
+ * Add six more Form Items
91
+ * Add Confirmation customization
92
+ * Update CSS output for some elements
93
+
94
  **Version 1.2.1**
95
 
96
  * Fix bug where entries table does not install
115
 
116
  == Upgrade Notice ==
117
 
118
+ = 1.3 =
119
+ New, faster way to add form items and ability to customize Confirmation. Fix for validation on security field.
120
+
121
  = 1.2.1 =
122
  Recommended update immediately! Fix for bug where entries table does not install.
screenshot-1.png CHANGED
Binary file
uninstall.php CHANGED
@@ -12,5 +12,6 @@
12
  $wpdb->query( "DROP TABLE IF EXISTS $fields_table" );
13
  $wpdb->query( "DROP TABLE IF EXISTS $entries_table" );
14
 
 
15
  delete_option( 'visual-form-builder-screen-options' );
16
  ?>
12
  $wpdb->query( "DROP TABLE IF EXISTS $fields_table" );
13
  $wpdb->query( "DROP TABLE IF EXISTS $entries_table" );
14
 
15
+ delete_option( 'vfb_db_version' );
16
  delete_option( 'visual-form-builder-screen-options' );
17
  ?>
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, a basic logic-based verification system, and entry tracking.
5
  Author: Matthew Muro
6
- Version: 1.2.1
7
  */
8
 
9
  /*
@@ -27,7 +27,7 @@ $visual_form_builder = new Visual_Form_Builder();
27
  /* Restrict Categories class */
28
  class Visual_Form_Builder{
29
 
30
- public $vfb_db_version = '1.2.1';
31
 
32
  public function __construct(){
33
  global $wpdb;
@@ -77,7 +77,8 @@ class Visual_Form_Builder{
77
  }
78
 
79
  add_shortcode( 'vfb', array( &$this, 'form_code' ) );
80
- add_action( 'init', array( &$this, 'email' ) );
 
81
 
82
  /* Add jQuery and CSS to the front-end */
83
  add_action( 'wp_head', array( &$this, 'form_css' ) );
@@ -90,6 +91,7 @@ class Visual_Form_Builder{
90
  * @since 1.2
91
  */
92
  public function includes(){
 
93
  require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-entries-list.php' );
94
  }
95
 
@@ -102,7 +104,7 @@ class Visual_Form_Builder{
102
  $text = "<p><strong>Getting Started</strong></p>
103
  <ul>
104
  <li>Click on the + tab, give your form a name and click Create Form.</li>
105
- <li>Select form fields from the box on the left and click Create Field to add it to your form.</li>
106
  <li>Edit the information for each form field by clicking on the down arrow.</li>
107
  <li>Drag and drop the elements to put them in order.</li>
108
  <li>Click Save Form to save your changes.</li>
@@ -124,6 +126,15 @@ class Visual_Form_Builder{
124
  <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>.
125
  <li><em>Number</em>: makes the element require a decimal number.</li>
126
  <li><em>Digits</em>: makes the element require digits only.</li>
 
 
 
 
 
 
 
 
 
127
  </ul>
128
  <p><strong>Tips</strong></p>
129
  <ul>
@@ -199,15 +210,15 @@ class Visual_Form_Builder{
199
  $field_sql = "CREATE TABLE $field_table_name (
200
  field_id BIGINT(20) NOT NULL AUTO_INCREMENT,
201
  form_id BIGINT(20) NOT NULL,
202
- field_key TINYTEXT NOT NULL,
203
- field_type TINYTEXT NOT NULL,
204
  field_options TEXT,
205
  field_description TEXT,
206
- field_name TINYTEXT NOT NULL,
207
  field_sequence TINYINT DEFAULT '0',
208
- field_validation TINYTEXT,
209
- field_required TINYTEXT,
210
- field_size TINYTEXT,
211
  UNIQUE KEY (field_id)
212
  );";
213
 
@@ -217,11 +228,13 @@ class Visual_Form_Builder{
217
  form_key TINYTEXT NOT NULL,
218
  form_title TEXT NOT NULL,
219
  form_email_subject TEXT,
220
- form_email_to TEXT,
221
- form_email_from TEXT,
222
- form_email_from_name TEXT,
223
- form_email_from_override TEXT,
224
- form_email_from_name_override TEXT,
 
 
225
  UNIQUE KEY (form_id)
226
  );";
227
 
@@ -230,11 +243,11 @@ class Visual_Form_Builder{
230
  form_id BIGINT(20) NOT NULL,
231
  data TEXT NOT NULL,
232
  subject TEXT,
233
- sender_name TEXT,
234
- sender_email TEXT,
235
- emails_to TEXT,
236
- date_submitted TEXT,
237
- ip_address TEXT,
238
  UNIQUE KEY (entries_id)
239
  );";
240
 
@@ -336,12 +349,16 @@ class Visual_Form_Builder{
336
  'form_title' => $form_title
337
  );
338
 
 
339
  $this->message = '<div id="message" class="updated"><p>The <strong>' . $form_title . '</strong> form has been created.</p></div>';
340
 
 
341
  $wpdb->insert( $this->form_table_name, $newdata );
342
 
 
343
  $new_form_selected = $wpdb->insert_id;
344
 
 
345
  $initial_fieldset = array(
346
  'form_id' => $wpdb->insert_id,
347
  'field_key' => 'fieldset',
@@ -350,9 +367,12 @@ class Visual_Form_Builder{
350
  'field_sequence' => 0
351
  );
352
 
 
353
  $wpdb->insert( $this->field_table_name, $initial_fieldset );
354
 
 
355
  wp_redirect( 'options-general.php?page=visual-form-builder&form=' . $new_form_selected );
 
356
 
357
  break;
358
 
@@ -367,6 +387,20 @@ class Visual_Form_Builder{
367
  $form_from_name = esc_html( $_REQUEST['form_email_from_name'] );
368
  $form_from_override = esc_html( $_REQUEST['form_email_from_override'] );
369
  $form_from_name_override = esc_html( $_REQUEST['form_email_from_name_override'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
 
371
  check_admin_referer( 'update_form-' . $form_id );
372
 
@@ -378,25 +412,28 @@ class Visual_Form_Builder{
378
  'form_email_from' => $form_from,
379
  'form_email_from_name' => $form_from_name,
380
  'form_email_from_override' => $form_from_override,
381
- 'form_email_from_name_override' => $form_from_name_override
 
 
382
  );
383
 
384
  $where = array(
385
  'form_id' => $form_id
386
  );
387
 
 
388
  $wpdb->update( $this->form_table_name, $newdata, $where );
389
 
390
  /* Loop through each field and update all at once */
391
  if ( !empty( $_REQUEST['field_id'] ) ) {
392
  foreach ( $_REQUEST['field_id'] as $id ) {
393
- $field_name = esc_html( $_REQUEST['field_name-' . $id] );
394
  $field_key = sanitize_title( $field_name );
395
- $field_desc = esc_html( $_REQUEST['field_description-' . $id] );
396
- $field_options = serialize( esc_html( $_REQUEST['field_options-' . $id] ) );
397
- $field_validation = esc_html( $_REQUEST['field_validation-' . $id] );
398
- $field_required = esc_html( $_REQUEST['field_required-' . $id] );
399
- $field_size = esc_html( $_REQUEST['field_size-' . $id] );
400
 
401
  $field_data = array(
402
  'field_key' => $field_key,
@@ -409,28 +446,35 @@ class Visual_Form_Builder{
409
  );
410
 
411
  $where = array(
412
- 'form_id' => absint( $_REQUEST['form_id'] ),
413
  'field_id' => $id
414
  );
415
 
 
416
  $wpdb->update( $this->field_table_name, $field_data, $where );
417
  }
418
  }
419
 
 
420
  $this->message = '<div id="message" class="updated"><p>The <strong>' . $form_title . '</strong> form has been updated.</p></div>';
421
 
422
  break;
423
 
424
  case 'delete_form' :
425
  $id = absint( $_REQUEST['form'] );
 
426
  check_admin_referer( 'delete-form-' . $id );
427
 
 
428
  $wpdb->query( $wpdb->prepare( "DELETE FROM $this->form_table_name WHERE form_id = %d", $id ) );
429
  $wpdb->query( $wpdb->prepare( "DELETE FROM $this->field_table_name WHERE form_id = %d", $id ) );
430
 
 
431
  $this->message = '<div id="message" class="updated"><p>This form has been deleted.</p></div>';
432
 
 
433
  wp_redirect( 'options-general.php?page=visual-form-builder' );
 
434
 
435
  break;
436
 
@@ -440,11 +484,15 @@ class Visual_Form_Builder{
440
 
441
  check_admin_referer( 'delete-field-' . $form_id );
442
 
 
443
  $wpdb->query( $wpdb->prepare( "DELETE FROM $this->field_table_name WHERE field_id = %d", $field_id ) );
444
 
 
445
  $this->message = '<div id="message" class="updated"><p>The field has been deleted.</p></div>';
446
 
 
447
  wp_redirect( 'options-general.php?page=visual-form-builder&form=' . $form_id );
 
448
 
449
  break;
450
 
@@ -454,9 +502,30 @@ class Visual_Form_Builder{
454
  $field_name = esc_html( $_REQUEST['field_type'] );
455
  $field_type = strtolower( esc_html( $_REQUEST['field_type'] ) );
456
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
  check_admin_referer( 'create-field-' . $form_id );
458
 
 
459
  $sequence_last_row = $wpdb->get_row( "SELECT field_sequence FROM $this->field_table_name WHERE form_id = $form_id ORDER BY field_sequence DESC LIMIT 1" );
 
 
460
  $field_sequence = ( !empty( $sequence_last_row ) ) ? $sequence_last_row->field_sequence + 1 : 0;
461
 
462
  $newdata = array(
@@ -464,9 +533,11 @@ class Visual_Form_Builder{
464
  'field_key' => $field_key,
465
  'field_name' => $field_name,
466
  'field_type' => $field_type,
467
- 'field_sequence' => $field_sequence
 
468
  );
469
 
 
470
  $wpdb->insert( $this->field_table_name, $newdata );
471
 
472
  break;
@@ -482,14 +553,15 @@ class Visual_Form_Builder{
482
  public function visual_form_builder_process_sort_callback() {
483
  global $wpdb;
484
 
 
485
  $order = explode( ',', $_REQUEST['order'] );
486
- $i = 0;
487
 
488
  foreach ( $order as $k => $v ) {
 
489
  preg_match( '/(\d+)/', $v, $matches );
490
 
 
491
  $wpdb->update( $this->field_table_name, array( 'field_sequence' => $k ), array( 'field_id' => $matches[0] ) );
492
- $i++;
493
  }
494
 
495
  die(1);
@@ -506,6 +578,7 @@ class Visual_Form_Builder{
506
  /* Set variables depending on which tab is selected */
507
  $form_nav_selected_id = ( isset( $_REQUEST['form'] ) ) ? $_REQUEST['form'] : '0';
508
  $action = ( isset( $_REQUEST['form'] ) && $_REQUEST['form'] !== '0' ) ? 'update_form' : 'create_form';
 
509
 
510
  /* Query to get all forms */
511
  $order = sanitize_sql_orderby( 'form_id DESC' );
@@ -518,6 +591,7 @@ class Visual_Form_Builder{
518
  foreach ( $forms as $form ) {
519
  $form_id = ( $form_nav_selected_id == $form->form_id ) ? $form->form_id : '';
520
 
 
521
  if ( $form_nav_selected_id == $form->form_id )
522
  $form_name = stripslashes( $form->form_title );
523
  }
@@ -564,28 +638,23 @@ class Visual_Form_Builder{
564
  <h3 class="hndle"><span>Form Items</span></h3>
565
  <div class="inside" >
566
  <div class="taxonomydiv">
567
- <ul id="taxonomy-category-tabs" class="taxonomy-tabs add-menu-item-tabs">
568
- <li class="tabs"><a href="#" class="nav-tab-link">Input Type</a></li>
569
- </ul>
570
- <div id="input-type" class="tabs-panel tabs-panel-active">
571
- <ul>
572
- <li><input type="radio" id="form-element-fieldset" name="field_type" value="Fieldset"<?php echo $disabled; ?> /> Fieldset</li>
573
- <li><input type="radio" id="form-element-text" name="field_type" value="Text"<?php echo $disabled; ?> /> Text</li>
574
- <li><input type="radio" id="form-element-textarea" name="field_type" value="Textarea"<?php echo $disabled; ?> /> Textarea</li>
575
- <li><input type="radio" id="form-element-checkbox" name="field_type" value="Checkbox"<?php echo $disabled; ?> /> Checkbox</li>
576
- <li><input type="radio" id="form-element-radio" name="field_type" value="Radio"<?php echo $disabled; ?> /> Radio</li>
577
- <li><input type="radio" id="form-element-select" name="field_type" value="Select"<?php echo $disabled; ?> /> Select</li>
578
- <li><input type="radio" id="form-element-address" name="field_type" value="Address"<?php echo $disabled; ?> /> Address</li>
579
- <li><input type="radio" id="form-element-datepicker" name="field_type" value="Date"<?php echo $disabled; ?> /> Date Picker</li>
580
- </ul>
581
- </div>
582
-
583
- <p class="button-controls">
584
- <span class="add-to-menu">
585
- <img id="add-to-form" alt="" src="<?php echo admin_url( '/images/wpspin_light.gif' ); ?>" class="waiting" />
586
- <input type="submit" id="submit-create-field" name="submit" value="Add to Form" class="button-secondary submit-add-to-menu"<?php echo $disabled; ?> />
587
- </span>
588
- </p>
589
  </div>
590
  </div>
591
  </div>
@@ -618,6 +687,7 @@ class Visual_Form_Builder{
618
  <?php
619
  /* Loop through each for and build the tabs */
620
  foreach ( $forms as $form ) {
 
621
  /* Control selected tab */
622
  if ( $form_nav_selected_id == $form->form_id ) :
623
  echo '<span class="nav-tab nav-tab-active">' . stripslashes( $form->form_title ) . '</span>';
@@ -629,20 +699,19 @@ class Visual_Form_Builder{
629
  $form_email_from_override = stripslashes( $form->form_email_from_override);
630
  $form_email_from_name_override = stripslashes( $form->form_email_from_name_override);
631
  $form_email_to = unserialize( stripslashes( $form->form_email_to ) );
 
 
632
 
633
- $email_query = "SELECT * FROM $this->field_table_name WHERE form_id = $form_nav_selected_id AND field_type='text' AND field_validation = 'email' AND field_required = 'yes'";
634
- $emails = $wpdb->get_results( $email_query );
635
-
636
  $sender_query = "SELECT * FROM $this->field_table_name WHERE form_id = $form_nav_selected_id AND field_type='text' AND field_validation = '' AND field_required = 'yes'";
637
  $senders = $wpdb->get_results( $sender_query );
 
 
 
 
 
638
  else :
639
- echo '<a href="' .
640
- esc_url( add_query_arg(
641
- array(
642
- 'form' => $form->form_id
643
- ),
644
- admin_url( 'options-general.php?page=visual-form-builder' )
645
- ) ) . '" class="nav-tab" id="' . $form->form_key . '">' . stripslashes( $form->form_title ) . '</a>';
646
  endif;
647
 
648
  }
@@ -652,14 +721,7 @@ class Visual_Form_Builder{
652
  ?>
653
  <span class="nav-tab menu-add-new nav-tab-active"><?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add form' ) ); ?></span>
654
  <?php else : ?>
655
- <a href="<?php
656
- echo esc_url(add_query_arg(
657
- array(
658
- 'form' => 0,
659
- ),
660
- admin_url( 'options-general.php?page=visual-form-builder' )
661
- ));
662
- ?>" class="nav-tab menu-add-new"><?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add form' ) ); ?></a>
663
  <?php endif; ?>
664
  </div>
665
  </div>
@@ -679,49 +741,94 @@ class Visual_Form_Builder{
679
  <input type="text" value="<?php echo ( isset( $form_title ) ) ? $form_title : ''; ?>" title="Enter form name here" class="menu-name regular-text menu-item-textbox" id="form-name" name="form_title" />
680
  </label>
681
  <?php
682
- /* Display sender details if we're on a form, otherwise just the form name */
683
  if ( $form_nav_selected_id !== '0' ) :
684
  ?>
685
  <br class="clear" />
 
 
 
 
 
686
 
687
- <p><em>The forms you build here will send information to one or more email addresses when submitted by a user on your site. Use the fields below to customize the details of that email.</em></p>
688
- <label for="form-email-subject" class="menu-name-label howto open-label">
689
- <span class="sender-labels">E-mail Subject</span>
690
- <input type="text" value="<?php echo $form_subject; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-subject" name="form_email_subject" />
691
- </label>
692
- <br class="clear" />
693
- <label for="form-email-sender-name" class="menu-name-label howto open-label">
694
- <span class="sender-labels">Sender Name</span>
695
- <input type="text" value="<?php echo $form_email_from_name; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-sender-name" name="form_email_from_name"<?php echo ( $form_email_from_name_override != '' ) ? ' readonly="readonly"' : ''; ?> />
696
- </label>
697
- <span>OR</span>
698
- <select name="form_email_from_name_override" id="form_email_from_name_override">
699
- <option value="" <?php selected( $form_email_from_name_override, '' ); ?>>Select a required text field</option>
700
- <?php foreach( $senders as $sender ) {
701
- echo '<option value="' . $sender->field_id . '"' . selected( $form_email_from_name_override, $sender->field_id ) . '>' . $sender->field_name . '</option>';
702
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
703
  ?>
704
- </select>
705
- <br class="clear" />
706
- <label for="form-email-sender" class="menu-name-label howto open-label">
707
- <span class="sender-labels">Sender E-mail</span>
708
- <input type="text" value="<?php echo $form_email_from; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-sender" name="form_email_from"<?php echo ( $form_email_from_override != '' ) ? ' readonly="readonly"' : ''; ?> />
709
- </label>
710
- <span>OR</span>
711
- <select name="form_email_from_override" id="form_email_from_override">
712
- <option value="" <?php selected( $form_email_from_override, '' ); ?>>Select a required text field with email validation</option>
713
- <?php foreach( $emails as $email ) {
714
- echo '<option value="' . $email->field_id . '"' . selected( $form_email_from_override, $email->field_id ) . '>' . $email->field_name . '</option>';
715
- }
716
  ?>
717
- </select>
718
- <br class="clear" />
719
- <label for="form-email-to" class="menu-name-label howto open-label">
720
- <span class="sender-labels">E-mail(s) To</span>
721
- <input type="text" value="<?php echo $form_email_to; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-to" name="form_email_to" />
722
- </label>
723
- <span><em>(multiple emails separated by commas)</em></span>
724
- <?php endif; ?>
725
  <br class="clear" />
726
  <div class="publishing-action">
727
  <input type="submit" value="<?php echo ( $action == 'create_form' ) ? 'Create Form' : 'Save Form'; ?>" class="button-primary menu-save" id="save_form" name="save_form" />
@@ -746,14 +853,16 @@ class Visual_Form_Builder{
746
  <?php else :
747
 
748
  if ( !empty( $form_nav_selected_id ) && $form_nav_selected_id !== '0' ) :
 
749
  echo '<div class="post-body-plain" id="menu-instructions"><p>Select form inputs from the box at left to begin building your custom form. An initial fieldset has been automatically added to get you started.</p></div>';
750
 
 
751
  $query_fields = "SELECT * FROM $this->field_table_name WHERE form_id = $form_nav_selected_id ORDER BY field_sequence ASC";
752
-
753
  $fields = $wpdb->get_results( $query_fields );
754
 
755
- echo '<ul id="menu-to-edit" class="menu ui-sortable">';
756
 
 
757
  foreach ( $fields as $field ) :
758
  ?>
759
  <li id="form_item_<?php echo $field->field_id; ?>" class="form-item">
@@ -787,7 +896,9 @@ class Visual_Form_Builder{
787
  </label>
788
  </p>
789
 
790
- <?php if ( in_array( $field->field_type, array( 'radio', 'checkbox', 'select' ) ) ) : ?>
 
 
791
  <p class="description description-wide">
792
  <?php
793
  if ( !empty( $field->field_options ) ) {
@@ -811,13 +922,19 @@ class Visual_Form_Builder{
811
  <p class="description description-thin">
812
  <label for="edit-form-item-validation">
813
  Validation<br />
814
- <select name="field_validation-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-validation-<?php echo $field->field_id; ?>"<?php echo ( $field->field_type !== 'text' ) ? ' disabled="disabled"' : ''; ?>>
 
 
 
 
815
  <option value="" <?php selected( $field->field_validation, '' ); ?>>None</option>
816
  <option value="email" <?php selected( $field->field_validation, 'email' ); ?>>Email</option>
817
  <option value="url" <?php selected( $field->field_validation, 'url' ); ?>>URL</option>
818
  <option value="date" <?php selected( $field->field_validation, 'date' ); ?>>Date</option>
819
  <option value="number" <?php selected( $field->field_validation, 'number' ); ?>>Number</option>
820
  <option value="digits" <?php selected( $field->field_validation, 'digits' ); ?>>Digits</option>
 
 
821
  </select>
822
  </label>
823
  </p>
@@ -831,7 +948,7 @@ class Visual_Form_Builder{
831
  </label>
832
  </p>
833
 
834
- <?php if ( !in_array( $field->field_type, array( 'radio', 'checkbox' ) ) ) : ?>
835
  <p class="description description-wide">
836
  <label for="edit-form-item-size">
837
  Size<br />
@@ -875,6 +992,42 @@ class Visual_Form_Builder{
875
  endif;
876
  }
877
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
878
  /**
879
  * Output form via shortcode
880
  *
@@ -896,7 +1049,7 @@ class Visual_Form_Builder{
896
 
897
  /* If form is submitted, show success message, otherwise the form */
898
  if ( isset( $_REQUEST['visual-form-builder-submit'] ) && in_array( $_REQUEST['visual-form-builder-submit'], array( 'Submit', 'submit' ) ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'visual-form-builder-nonce' ) ) {
899
- $output = '<p id="form_success">Your form was successfully submitted. Thank you for contacting us.</p>';
900
  }
901
  else {
902
  /* Get forms */
@@ -920,9 +1073,8 @@ class Visual_Form_Builder{
920
  foreach ( $fields as $field ) {
921
  if ( $field->field_type == 'fieldset' ) {
922
  /* Close each fieldset */
923
- if ( $open_fieldset == true ) {
924
- $output .= '</ul></fieldset>';
925
- }
926
 
927
  $output .= '<fieldset><div class="legend"><h3>' . $field->field_name . '</h3></div><ul>';
928
  $open_fieldset = true;
@@ -931,20 +1083,26 @@ class Visual_Form_Builder{
931
  /* If field is required, build the span and add setup the 'required' class */
932
  $required_span = ( !empty( $field->field_required ) && $field->field_required === 'yes' ) ? ' <span>*</span>' : '';
933
  $required = ( !empty( $field->field_required ) && $field->field_required === 'yes' ) ? ' required' : '';
934
-
935
- $output .= '<li><label for="' . $field->field_key . '" class="desc">'. stripslashes( $field->field_name ) . $required_span . '</label>';
 
936
  }
937
 
938
  switch ( $field->field_type ) {
939
- case 'text':
 
 
 
 
 
940
 
941
  if ( !empty( $field->field_description ) )
942
- $output .= '<span><input type="text" name="vfb-' . esc_html( $field->field_key ) . '" id="vfb-' . esc_html( $field->field_key ) . '" value="" class="text ' . $field->field_size . $required . '" /><label>' . $field->field_description . '</label></span>';
943
  else
944
- $output .= '<input type="text" name="vfb-' . esc_html( $field->field_key ) . '" id="vfb-' . esc_html( $field->field_key ) . '" value="" class="text ' . $field->field_size . $required . '" />';
945
  break;
946
 
947
- case 'textarea':
948
 
949
  if ( !empty( $field->field_description ) )
950
  $output .= '<span><label>' . $field->field_description . '</label></span>';
@@ -982,8 +1140,8 @@ class Visual_Form_Builder{
982
  /* Loop through each option and output */
983
  foreach ( $options as $option => $value ) {
984
  $output .= '<span>
985
- <input type="radio" name="vfb-'. $field->field_key . '" value="'. $value . '" class="radio ' . $required . '" />'.
986
- ' <label for="' . $field->field_key . '" class="choice">' . $value . '</label>' .
987
  '</span>';
988
  }
989
 
@@ -999,11 +1157,12 @@ class Visual_Form_Builder{
999
  $options = explode( ',', unserialize( $field->field_options ) );
1000
 
1001
  $output .= '<div>';
1002
-
1003
  /* Loop through each option and output */
1004
  foreach ( $options as $option => $value ) {
1005
- $output .= '<span><input type="checkbox" name="vfb-'. $field->field_key . '[]" id="vfb-'. $field->field_key . '" value="'. trim( $value ) . '" class="checkbox ' . $required . '" />'.
1006
- ' <label for="' . $field->field_key . '" class="choice">' . trim( $value ) . '</label></span>';
 
1007
  }
1008
 
1009
  $output .= '</div>';
@@ -1014,11 +1173,12 @@ class Visual_Form_Builder{
1014
 
1015
  if ( !empty( $field->field_description ) )
1016
  $output .= '<span><label>' . $field->field_description . '</label></span>';
1017
-
 
1018
  $output .= '<div>
1019
  <span class="full">
1020
 
1021
- <input type="text" name="vfb-address" maxlength="150" id="vfb-address" class="text medium" />
1022
  <label>Address</label>
1023
  </span>
1024
  <span class="full">
@@ -1027,259 +1187,27 @@ class Visual_Form_Builder{
1027
  </span>
1028
  <span class="left">
1029
 
1030
- <input type="text" name="vfb-city" maxlength="150" id="vfb-city" class="text medium" />
1031
  <label>City</label>
1032
  </span>
1033
  <span class="right">
1034
- <input type="text" name="vfb-state" maxlength="150" id="vfb-state" class="text medium" />
1035
  <label>State / Province / Region</label>
1036
  </span>
1037
  <span class="left">
1038
 
1039
- <input type="text" name="vfb-zip" maxlength="150" id="vfb-zip" class="text medium" />
1040
  <label>Postal / Zip Code</label>
1041
  </span>
1042
  <span class="right">
1043
- <select class="select" name="vfb-country" id="vfb-country">
1044
- <option selected="selected" value=""></option>
1045
- <option value="Afghanistan">Afghanistan</option>
1046
- <option value="Albania">Albania</option>
1047
-
1048
- <option value="Algeria">Algeria</option>
1049
- <option value="Andorra">Andorra</option>
1050
- <option value="Angola">Angola</option>
1051
- <option value="Antigua and Barbuda">Antigua and Barbuda</option>
1052
- <option value="Argentina">Argentina</option>
1053
- <option value="Armenia">Armenia</option>
1054
-
1055
- <option value="Aruba">Aruba</option>
1056
- <option value="Australia">Australia</option>
1057
- <option value="Austria">Austria</option>
1058
- <option value="Azerbaijan">Azerbaijan</option>
1059
- <option value="Bahamas">Bahamas</option>
1060
- <option value="Bahrain">Bahrain</option>
1061
-
1062
- <option value="Bangladesh">Bangladesh</option>
1063
- <option value="Barbados">Barbados</option>
1064
- <option value="Belarus">Belarus</option>
1065
- <option value="Belgium">Belgium</option>
1066
- <option value="Belize">Belize</option>
1067
- <option value="Benin">Benin</option>
1068
-
1069
- <option value="Bermuda">Bermuda</option>
1070
- <option value="Bhutan">Bhutan</option>
1071
- <option value="Bolivia">Bolivia</option>
1072
- <option value="Bosnia and Herzegovina">Bosnia and Herzegovina</option>
1073
- <option value="Botswana">Botswana</option>
1074
- <option value="Brazil">Brazil</option>
1075
-
1076
- <option value="Brunei">Brunei</option>
1077
- <option value="Bulgaria">Bulgaria</option>
1078
- <option value="Burkina Faso">Burkina Faso</option>
1079
- <option value="Burundi">Burundi</option>
1080
- <option value="Cambodia">Cambodia</option>
1081
- <option value="Cameroon">Cameroon</option>
1082
-
1083
- <option value="Canada">Canada</option>
1084
- <option value="Cape Verde">Cape Verde</option>
1085
- <option value="Central African Republic">Central African Republic</option>
1086
- <option value="Chad">Chad</option>
1087
- <option value="Chile">Chile</option>
1088
- <option value="China">China</option>
1089
-
1090
- <option value="Colombia">Colombia</option>
1091
- <option value="Comoros">Comoros</option>
1092
- <option value="Democratic Republic of the Congo">Democratic Republic of the Congo</option>
1093
- <option value="Republic of the Congo">Republic of the Congo</option>
1094
- <option value="Cook Islands">Cook Islands</option>
1095
- <option value="Costa Rica">Costa Rica</option>
1096
-
1097
- <option value="C&ocirc;te d&lsquo;Ivoire">C&ocirc;te d&lsquo;Ivoire</option>
1098
- <option value="Croatia">Croatia</option>
1099
- <option value="Cuba">Cuba</option>
1100
- <option value="Cyprus">Cyprus</option>
1101
- <option value="Czech Republic">Czech Republic</option>
1102
- <option value="Denmark">Denmark</option>
1103
-
1104
- <option value="Djibouti">Djibouti</option>
1105
- <option value="Dominica">Dominica</option>
1106
- <option value="Dominican Republic">Dominican Republic</option>
1107
- <option value="East Timor">East Timor</option>
1108
- <option value="Ecuador">Ecuador</option>
1109
- <option value="Egypt">Egypt</option>
1110
-
1111
- <option value="El Salvador">El Salvador</option>
1112
- <option value="Equatorial Guinea">Equatorial Guinea</option>
1113
- <option value="Eritrea">Eritrea</option>
1114
- <option value="Estonia">Estonia</option>
1115
- <option value="Ethiopia">Ethiopia</option>
1116
- <option value="Faroe Islands">Faroe Islands</option>
1117
-
1118
- <option value="Fiji">Fiji</option>
1119
- <option value="Finland">Finland</option>
1120
- <option value="France">France</option>
1121
- <option value="Gabon">Gabon</option>
1122
- <option value="Gambia">Gambia</option>
1123
- <option value="Georgia">Georgia</option>
1124
-
1125
- <option value="Germany">Germany</option>
1126
- <option value="Ghana">Ghana</option>
1127
- <option value="Gibraltar">Gibraltar</option>
1128
- <option value="Greece">Greece</option>
1129
- <option value="Grenada">Grenada</option>
1130
- <option value="Guatemala">Guatemala</option>
1131
-
1132
- <option value="Guinea">Guinea</option>
1133
- <option value="Guinea-Bissau">Guinea-Bissau</option>
1134
- <option value="Guyana">Guyana</option>
1135
- <option value="Haiti">Haiti</option>
1136
- <option value="Honduras">Honduras</option>
1137
- <option value="Hong Kong">Hong Kong</option>
1138
-
1139
- <option value="Hungary">Hungary</option>
1140
- <option value="Iceland">Iceland</option>
1141
- <option value="India">India</option>
1142
- <option value="Indonesia">Indonesia</option>
1143
- <option value="Iran">Iran</option>
1144
- <option value="Iraq">Iraq</option>
1145
-
1146
- <option value="Ireland">Ireland</option>
1147
- <option value="Israel">Israel</option>
1148
- <option value="Italy">Italy</option>
1149
- <option value="Jamaica">Jamaica</option>
1150
- <option value="Japan">Japan</option>
1151
- <option value="Jordan">Jordan</option>
1152
-
1153
- <option value="Kazakhstan">Kazakhstan</option>
1154
- <option value="Kenya">Kenya</option>
1155
- <option value="Kiribati">Kiribati</option>
1156
- <option value="North Korea">North Korea</option>
1157
- <option value="South Korea">South Korea</option>
1158
- <option value="Kuwait">Kuwait</option>
1159
-
1160
- <option value="Kyrgyzstan">Kyrgyzstan</option>
1161
- <option value="Laos">Laos</option>
1162
- <option value="Latvia">Latvia</option>
1163
- <option value="Lebanon">Lebanon</option>
1164
- <option value="Lesotho">Lesotho</option>
1165
- <option value="Liberia">Liberia</option>
1166
-
1167
- <option value="Libya">Libya</option>
1168
- <option value="Liechtenstein">Liechtenstein</option>
1169
- <option value="Lithuania">Lithuania</option>
1170
- <option value="Luxembourg">Luxembourg</option>
1171
- <option value="Macedonia">Macedonia</option>
1172
- <option value="Madagascar">Madagascar</option>
1173
-
1174
- <option value="Malawi">Malawi</option>
1175
- <option value="Malaysia">Malaysia</option>
1176
- <option value="Maldives">Maldives</option>
1177
- <option value="Mali">Mali</option>
1178
- <option value="Malta">Malta</option>
1179
- <option value="Marshall Islands">Marshall Islands</option>
1180
-
1181
- <option value="Mauritania">Mauritania</option>
1182
- <option value="Mauritius">Mauritius</option>
1183
- <option value="Mexico">Mexico</option>
1184
- <option value="Micronesia">Micronesia</option>
1185
- <option value="Moldova">Moldova</option>
1186
- <option value="Monaco">Monaco</option>
1187
-
1188
- <option value="Mongolia">Mongolia</option>
1189
- <option value="Montenegro">Montenegro</option>
1190
- <option value="Morocco">Morocco</option>
1191
- <option value="Mozambique">Mozambique</option>
1192
- <option value="Myanmar">Myanmar</option>
1193
- <option value="Namibia">Namibia</option>
1194
-
1195
- <option value="Nauru">Nauru</option>
1196
- <option value="Nepal">Nepal</option>
1197
- <option value="Netherlands">Netherlands</option>
1198
- <option value="Netherlands Antilles">Netherlands Antilles</option>
1199
- <option value="New Zealand">New Zealand</option>
1200
- <option value="Nicaragua">Nicaragua</option>
1201
-
1202
- <option value="Niger">Niger</option>
1203
- <option value="Nigeria">Nigeria</option>
1204
- <option value="Norway">Norway</option>
1205
- <option value="Oman">Oman</option>
1206
- <option value="Pakistan">Pakistan</option>
1207
- <option value="Palau">Palau</option>
1208
-
1209
- <option value="Palestine">Palestine</option>
1210
- <option value="Panama">Panama</option>
1211
- <option value="Papua New Guinea">Papua New Guinea</option>
1212
- <option value="Paraguay">Paraguay</option>
1213
- <option value="Peru">Peru</option>
1214
- <option value="Philippines">Philippines</option>
1215
-
1216
- <option value="Poland">Poland</option>
1217
- <option value="Portugal">Portugal</option>
1218
- <option value="Puerto Rico">Puerto Rico</option>
1219
- <option value="Qatar">Qatar</option>
1220
- <option value="Romania">Romania</option>
1221
- <option value="Russia">Russia</option>
1222
-
1223
- <option value="Rwanda">Rwanda</option>
1224
- <option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option>
1225
- <option value="Saint Lucia">Saint Lucia</option>
1226
- <option value="Saint Vincent and the Grenadines">Saint Vincent and the Grenadines</option>
1227
- <option value="Samoa">Samoa</option>
1228
- <option value="San Marino">San Marino</option>
1229
-
1230
- <option value="Sao Tome and Principe">Sao Tome and Principe</option>
1231
- <option value="Saudi Arabia">Saudi Arabia</option>
1232
- <option value="Senegal">Senegal</option>
1233
- <option value="Serbia and Montenegro">Serbia and Montenegro</option>
1234
- <option value="Seychelles">Seychelles</option>
1235
- <option value="Sierra Leone">Sierra Leone</option>
1236
-
1237
- <option value="Singapore">Singapore</option>
1238
- <option value="Slovakia">Slovakia</option>
1239
- <option value="Slovenia">Slovenia</option>
1240
- <option value="Solomon Islands">Solomon Islands</option>
1241
- <option value="Somalia">Somalia</option>
1242
- <option value="South Africa">South Africa</option>
1243
-
1244
- <option value="Spain">Spain</option>
1245
- <option value="Sri Lanka">Sri Lanka</option>
1246
- <option value="Sudan">Sudan</option>
1247
- <option value="Suriname">Suriname</option>
1248
- <option value="Swaziland">Swaziland</option>
1249
- <option value="Sweden">Sweden</option>
1250
-
1251
- <option value="Switzerland">Switzerland</option>
1252
- <option value="Syria">Syria</option>
1253
- <option value="Taiwan">Taiwan</option>
1254
- <option value="Tajikistan">Tajikistan</option>
1255
- <option value="Tanzania">Tanzania</option>
1256
- <option value="Thailand">Thailand</option>
1257
-
1258
- <option value="Togo">Togo</option>
1259
- <option value="Tonga">Tonga</option>
1260
- <option value="Trinidad and Tobago">Trinidad and Tobago</option>
1261
- <option value="Tunisia">Tunisia</option>
1262
- <option value="Turkey">Turkey</option>
1263
- <option value="Turkmenistan">Turkmenistan</option>
1264
-
1265
- <option value="Tuvalu">Tuvalu</option>
1266
- <option value="Uganda">Uganda</option>
1267
- <option value="Ukraine">Ukraine</option>
1268
- <option value="United Arab Emirates">United Arab Emirates</option>
1269
- <option value="United Kingdom">United Kingdom</option>
1270
- <option value="United States">United States</option>
1271
-
1272
- <option value="Uruguay">Uruguay</option>
1273
- <option value="Uzbekistan">Uzbekistan</option>
1274
- <option value="Vanuatu">Vanuatu</option>
1275
- <option value="Vatican City">Vatican City</option>
1276
- <option value="Venezuela">Venezuela</option>
1277
- <option value="Vietnam">Vietnam</option>
1278
-
1279
- <option value="Yemen">Yemen</option>
1280
- <option value="Zambia">Zambia</option>
1281
- <option value="Zimbabwe">Zimbabwe</option>
1282
- </select>
1283
  <label>Country</label>
1284
  </span>
1285
  </div>';
@@ -1295,13 +1223,48 @@ class Visual_Form_Builder{
1295
  $output .= '<input type="text" name="vfb-' . esc_html( $field->field_key ) . '" id="vfb-' . esc_html( $field->field_key ) . '" value="" class="text vfb-date-picker ' . $field->field_size . $required . '" />';
1296
 
1297
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1298
  }
1299
 
1300
  $output .= '</li>';
1301
  }
1302
 
1303
- $output .= '</ul></fieldset>';
 
1304
 
 
1305
  $output .= '<fieldset>
1306
  <div class="legend">
1307
  <h3>Verification</h3>
@@ -1343,7 +1306,7 @@ class Visual_Form_Builder{
1343
  global $wpdb, $post;
1344
 
1345
  /* Security check before moving any further */
1346
- if ( isset( $_REQUEST['visual-form-builder-submit'] ) && $_REQUEST['visual-form-builder-submit'] == 'Submit' && $_REQUEST['vfb-spam'] == '' && is_numeric( $_REQUEST['vfb-secret'] ) && strlen( $_REQUEST['vfb-secret'] ) == 2 ) {
1347
  $nonce = $_REQUEST['_wpnonce'];
1348
 
1349
  /* Security check to verify the nonce */
@@ -1372,25 +1335,26 @@ class Visual_Form_Builder{
1372
  $form_from_name = $form->form_email_from_name;
1373
  }
1374
 
1375
- /* Sender email override query */
1376
- $email_query = "SELECT fields.field_key FROM $this->form_table_name AS forms LEFT JOIN $this->field_table_name AS fields ON forms.form_email_from_override = fields.field_id WHERE forms.form_id = $form_id";
1377
- $emails = $wpdb->get_results( $email_query );
1378
-
1379
  /* Sender name override query */
1380
  $sender_query = "SELECT fields.field_key FROM $this->form_table_name AS forms LEFT JOIN $this->field_table_name AS fields ON forms.form_email_from_name_override = fields.field_id WHERE forms.form_id = $form_id";
1381
  $senders = $wpdb->get_results( $sender_query );
 
 
 
 
1382
 
 
 
 
 
 
 
1383
  /* Loop through email results and assign sender email to override, if needed */
1384
  foreach ( $emails as $email ) {
1385
  if ( !empty( $email->field_key ) )
1386
  $form_from = $_POST[ 'vfb-' . $email->field_key ];
1387
  }
1388
 
1389
- /* Loop through name results and assign sender name to override, if needed */
1390
- foreach( $senders as $sender ) {
1391
- if ( !empty( $sender->field_key ) )
1392
- $form_from_name = $_POST[ 'vfb-' . $sender->field_key ];
1393
- }
1394
 
1395
  /* Prepare the beginning of the content */
1396
  $message = '<html><body><table rules="all" style="border-color: #666;" cellpadding="10">';
@@ -1401,9 +1365,16 @@ class Visual_Form_Builder{
1401
  $key = str_replace( 'vfb-', '', $key );
1402
  $key = strtolower( str_replace( '-', ' ', $key ) );
1403
 
1404
- /* If there are multiple values, build the list, otherwise it's a single value */
1405
- $value = is_array( $value ) ? implode( ', ', $value ) : esc_html( $value );
1406
-
 
 
 
 
 
 
 
1407
  /* Hide fields that aren't necessary to the body of the message */
1408
  if ( !in_array( $key, array( 'spam', 'secret', 'visual form builder submit', '_wpnonce', 'form_id' ) ) ) {
1409
  $message .= '<tr><td><strong>' . ucwords( $key ) . ': </strong></td><td>' . $value . '</td></tr>';
@@ -1442,7 +1413,11 @@ class Visual_Form_Builder{
1442
  foreach ( $form_to as $email ) {
1443
  $mail_sent = wp_mail( $email, esc_html( $form_subject ), $message, $headers );
1444
  }
1445
- }
 
 
 
 
1446
  }
1447
  }
1448
 
3
  Plugin Name: Visual Form Builder
4
  Description: Dynamically build forms using a simple interface. Forms include jQuery validation, a basic logic-based verification system, and entry tracking.
5
  Author: Matthew Muro
6
+ Version: 1.3
7
  */
8
 
9
  /*
27
  /* Restrict Categories class */
28
  class Visual_Form_Builder{
29
 
30
+ public $vfb_db_version = '1.3';
31
 
32
  public function __construct(){
33
  global $wpdb;
77
  }
78
 
79
  add_shortcode( 'vfb', array( &$this, 'form_code' ) );
80
+ add_action( 'init', array( &$this, 'email' ), 10 );
81
+ add_action( 'init', array( &$this, 'confirmation' ), 12 );
82
 
83
  /* Add jQuery and CSS to the front-end */
84
  add_action( 'wp_head', array( &$this, 'form_css' ) );
91
  * @since 1.2
92
  */
93
  public function includes(){
94
+ /* Load the Entries class */
95
  require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-entries-list.php' );
96
  }
97
 
104
  $text = "<p><strong>Getting Started</strong></p>
105
  <ul>
106
  <li>Click on the + tab, give your form a name and click Create Form.</li>
107
+ <li>Select form fields from the box on the left and click a field to add it to your form.</li>
108
  <li>Edit the information for each form field by clicking on the down arrow.</li>
109
  <li>Drag and drop the elements to put them in order.</li>
110
  <li>Click Save Form to save your changes.</li>
126
  <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>.
127
  <li><em>Number</em>: makes the element require a decimal number.</li>
128
  <li><em>Digits</em>: makes the element require digits only.</li>
129
+ <li><em>Phone</em>: makes the element require a US or International phone number. Most formats are accepted.</li>
130
+ <li><em>Time</em>: choose either 12- or 24-hour time format (NOTE: only available with the Time field).</li>
131
+ </ul>
132
+ <p><strong>Confirmation</strong><p>
133
+ <ul>
134
+ <li>Each form allows you to customize the confirmation by selecing either a Text Message, a WordPress Page, or to Redirect to a URL.</li>
135
+ <li><em>Text</em> allows you to enter a custom formatted message that will be displayed on the page after your form is submitted. HTML is allowed here.</li>
136
+ <li><em>Page</em> displays a dropdown of all WordPress Pages you have created. Select one to redirect the user to that page after your form is submitted.</li>
137
+ <li><em>Redirect</em> will only accept URLs and can be used to send the user to a different site completely, if you choose.
138
  </ul>
139
  <p><strong>Tips</strong></p>
140
  <ul>
210
  $field_sql = "CREATE TABLE $field_table_name (
211
  field_id BIGINT(20) NOT NULL AUTO_INCREMENT,
212
  form_id BIGINT(20) NOT NULL,
213
+ field_key VARCHAR(25) NOT NULL,
214
+ field_type VARCHAR(25) NOT NULL,
215
  field_options TEXT,
216
  field_description TEXT,
217
+ field_name VARCHAR(255) NOT NULL,
218
  field_sequence TINYINT DEFAULT '0',
219
+ field_validation VARCHAR(25),
220
+ field_required VARCHAR(25),
221
+ field_size VARCHAR(25),
222
  UNIQUE KEY (field_id)
223
  );";
224
 
228
  form_key TINYTEXT NOT NULL,
229
  form_title TEXT NOT NULL,
230
  form_email_subject TEXT,
231
+ form_email_to VARCHAR(255),
232
+ form_email_from VARCHAR(255),
233
+ form_email_from_name VARCHAR(255),
234
+ form_email_from_override VARCHAR(255),
235
+ form_email_from_name_override VARCHAR(255),
236
+ form_success_type VARCHAR(25) DEFAULT 'text',
237
+ form_success_message TEXT,
238
  UNIQUE KEY (form_id)
239
  );";
240
 
243
  form_id BIGINT(20) NOT NULL,
244
  data TEXT NOT NULL,
245
  subject TEXT,
246
+ sender_name VARCHAR(255),
247
+ sender_email VARCHAR(25),
248
+ emails_to VARCHAR(255),
249
+ date_submitted VARCHAR(25),
250
+ ip_address VARCHAR(25),
251
  UNIQUE KEY (entries_id)
252
  );";
253
 
349
  'form_title' => $form_title
350
  );
351
 
352
+ /* Set message to display */
353
  $this->message = '<div id="message" class="updated"><p>The <strong>' . $form_title . '</strong> form has been created.</p></div>';
354
 
355
+ /* Create the form */
356
  $wpdb->insert( $this->form_table_name, $newdata );
357
 
358
+ /* Get form ID to add our first field */
359
  $new_form_selected = $wpdb->insert_id;
360
 
361
+ /* Setup the initial fieldset */
362
  $initial_fieldset = array(
363
  'form_id' => $wpdb->insert_id,
364
  'field_key' => 'fieldset',
367
  'field_sequence' => 0
368
  );
369
 
370
+ /* Add the first fieldset to get things started */
371
  $wpdb->insert( $this->field_table_name, $initial_fieldset );
372
 
373
+ /* Redirect to keep the URL clean (use AJAX in the future?) */
374
  wp_redirect( 'options-general.php?page=visual-form-builder&form=' . $new_form_selected );
375
+ exit();
376
 
377
  break;
378
 
387
  $form_from_name = esc_html( $_REQUEST['form_email_from_name'] );
388
  $form_from_override = esc_html( $_REQUEST['form_email_from_override'] );
389
  $form_from_name_override = esc_html( $_REQUEST['form_email_from_name_override'] );
390
+ $form_success_type = esc_html( $_REQUEST['form_success_type'] );
391
+
392
+ /* Add confirmation based on which type was selected */
393
+ switch ( $form_success_type ) {
394
+ case 'text' :
395
+ $form_success_message = wp_richedit_pre( $_REQUEST['form_success_message_text'] );
396
+ break;
397
+ case 'page' :
398
+ $form_success_message = esc_html( $_REQUEST['form_success_message_page'] );
399
+ break;
400
+ case 'redirect' :
401
+ $form_success_message = esc_html( $_REQUEST['form_success_message_redirect'] );
402
+ break;
403
+ }
404
 
405
  check_admin_referer( 'update_form-' . $form_id );
406
 
412
  'form_email_from' => $form_from,
413
  'form_email_from_name' => $form_from_name,
414
  'form_email_from_override' => $form_from_override,
415
+ 'form_email_from_name_override' => $form_from_name_override,
416
+ 'form_success_type' => $form_success_type,
417
+ 'form_success_message' => $form_success_message
418
  );
419
 
420
  $where = array(
421
  'form_id' => $form_id
422
  );
423
 
424
+ /* Update form details */
425
  $wpdb->update( $this->form_table_name, $newdata, $where );
426
 
427
  /* Loop through each field and update all at once */
428
  if ( !empty( $_REQUEST['field_id'] ) ) {
429
  foreach ( $_REQUEST['field_id'] as $id ) {
430
+ $field_name = ( isset( $_REQUEST['field_name-' . $id] ) ) ? esc_html( $_REQUEST['field_name-' . $id] ) : '';
431
  $field_key = sanitize_title( $field_name );
432
+ $field_desc = ( isset( $_REQUEST['field_description-' . $id] ) ) ? esc_html( $_REQUEST['field_description-' . $id] ) : '';
433
+ $field_options = ( isset( $_REQUEST['field_options-' . $id] ) ) ? serialize( esc_html( $_REQUEST['field_options-' . $id] ) ) : '';
434
+ $field_validation = ( isset( $_REQUEST['field_validation-' . $id] ) ) ? esc_html( $_REQUEST['field_validation-' . $id] ) : '';
435
+ $field_required = ( isset( $_REQUEST['field_required-' . $id] ) ) ? esc_html( $_REQUEST['field_required-' . $id] ) : '';
436
+ $field_size = ( isset( $_REQUEST['field_size-' . $id] ) ) ? esc_html( $_REQUEST['field_size-' . $id] ) : '';
437
 
438
  $field_data = array(
439
  'field_key' => $field_key,
446
  );
447
 
448
  $where = array(
449
+ 'form_id' => $_REQUEST['form_id'],
450
  'field_id' => $id
451
  );
452
 
453
+ /* Update all fields */
454
  $wpdb->update( $this->field_table_name, $field_data, $where );
455
  }
456
  }
457
 
458
+ /* Set message to display */
459
  $this->message = '<div id="message" class="updated"><p>The <strong>' . $form_title . '</strong> form has been updated.</p></div>';
460
 
461
  break;
462
 
463
  case 'delete_form' :
464
  $id = absint( $_REQUEST['form'] );
465
+
466
  check_admin_referer( 'delete-form-' . $id );
467
 
468
+ /* Delete form and all fields */
469
  $wpdb->query( $wpdb->prepare( "DELETE FROM $this->form_table_name WHERE form_id = %d", $id ) );
470
  $wpdb->query( $wpdb->prepare( "DELETE FROM $this->field_table_name WHERE form_id = %d", $id ) );
471
 
472
+ /* Set message to display */
473
  $this->message = '<div id="message" class="updated"><p>This form has been deleted.</p></div>';
474
 
475
+ /* Redirect to keep the URL clean (use AJAX in the future?) */
476
  wp_redirect( 'options-general.php?page=visual-form-builder' );
477
+ exit();
478
 
479
  break;
480
 
484
 
485
  check_admin_referer( 'delete-field-' . $form_id );
486
 
487
+ /* Delete the field */
488
  $wpdb->query( $wpdb->prepare( "DELETE FROM $this->field_table_name WHERE field_id = %d", $field_id ) );
489
 
490
+ /* Set message to display */
491
  $this->message = '<div id="message" class="updated"><p>The field has been deleted.</p></div>';
492
 
493
+ /* Redirect to keep the URL clean (use AJAX in the future?) */
494
  wp_redirect( 'options-general.php?page=visual-form-builder&form=' . $form_id );
495
+ exit();
496
 
497
  break;
498
 
502
  $field_name = esc_html( $_REQUEST['field_type'] );
503
  $field_type = strtolower( esc_html( $_REQUEST['field_type'] ) );
504
 
505
+ /* Set defaults for validation */
506
+ switch ( $field_type ) {
507
+ case 'email' :
508
+ case 'url' :
509
+ case 'phone' :
510
+ $field_validation = $field_type;
511
+ break;
512
+ case 'currency' :
513
+ $field_validation = 'number';
514
+ break;
515
+ case 'number' :
516
+ $field_validation = 'digits';
517
+ break;
518
+ case 'time' :
519
+ $field_validation = 'time-12';
520
+ break;
521
+ }
522
+
523
  check_admin_referer( 'create-field-' . $form_id );
524
 
525
+ /* Get the last row's sequence */
526
  $sequence_last_row = $wpdb->get_row( "SELECT field_sequence FROM $this->field_table_name WHERE form_id = $form_id ORDER BY field_sequence DESC LIMIT 1" );
527
+
528
+ /* If it's not the first for this form, add 1 */
529
  $field_sequence = ( !empty( $sequence_last_row ) ) ? $sequence_last_row->field_sequence + 1 : 0;
530
 
531
  $newdata = array(
533
  'field_key' => $field_key,
534
  'field_name' => $field_name,
535
  'field_type' => $field_type,
536
+ 'field_sequence' => $field_sequence,
537
+ 'field_validation' => $field_validation
538
  );
539
 
540
+ /* Create the field */
541
  $wpdb->insert( $this->field_table_name, $newdata );
542
 
543
  break;
553
  public function visual_form_builder_process_sort_callback() {
554
  global $wpdb;
555
 
556
+ /* Get the order of the fields as make an array */
557
  $order = explode( ',', $_REQUEST['order'] );
 
558
 
559
  foreach ( $order as $k => $v ) {
560
+ /* Find the digits from each field */
561
  preg_match( '/(\d+)/', $v, $matches );
562
 
563
+ /* Update each field with it's new sequence */
564
  $wpdb->update( $this->field_table_name, array( 'field_sequence' => $k ), array( 'field_id' => $matches[0] ) );
 
565
  }
566
 
567
  die(1);
578
  /* Set variables depending on which tab is selected */
579
  $form_nav_selected_id = ( isset( $_REQUEST['form'] ) ) ? $_REQUEST['form'] : '0';
580
  $action = ( isset( $_REQUEST['form'] ) && $_REQUEST['form'] !== '0' ) ? 'update_form' : 'create_form';
581
+ $details_meta = ( isset( $_REQUEST['details'] ) ) ? $_REQUEST['details'] : 'email';
582
 
583
  /* Query to get all forms */
584
  $order = sanitize_sql_orderby( 'form_id DESC' );
591
  foreach ( $forms as $form ) {
592
  $form_id = ( $form_nav_selected_id == $form->form_id ) ? $form->form_id : '';
593
 
594
+ /* If we are on a form, set the form name for the shortcode box */
595
  if ( $form_nav_selected_id == $form->form_id )
596
  $form_name = stripslashes( $form->form_title );
597
  }
638
  <h3 class="hndle"><span>Form Items</span></h3>
639
  <div class="inside" >
640
  <div class="taxonomydiv">
641
+ <p><strong>Click</strong> to Add a Field <img id="add-to-form" alt="" src="<?php echo admin_url( '/images/wpspin_light.gif' ); ?>" class="waiting" /></p>
642
+ <ul>
643
+ <li><input type="submit" id="form-element-fieldset" class="button-secondary" name="field_type" value="Fieldset"<?php echo $disabled; ?> /></li>
644
+ <li><input type="submit" id="form-element-text" class="button-secondary" name="field_type" value="Text"<?php echo $disabled; ?> /></li>
645
+ <li><input type="submit" id="form-element-textarea" class="button-secondary" name="field_type" value="Textarea"<?php echo $disabled; ?> /></li>
646
+ <li><input type="submit" id="form-element-checkbox" class="button-secondary" name="field_type" value="Checkbox"<?php echo $disabled; ?> /></li>
647
+ <li><input type="submit" id="form-element-radio" class="button-secondary" name="field_type" value="Radio"<?php echo $disabled; ?> /></li>
648
+ <li><input type="submit" id="form-element-select" class="button-secondary" name="field_type" value="Select"<?php echo $disabled; ?> /></li>
649
+ <li><input type="submit" id="form-element-address" class="button-secondary" name="field_type" value="Address"<?php echo $disabled; ?> /></li>
650
+ <li><input type="submit" id="form-element-datepicker" class="button-secondary" name="field_type" value="Date"<?php echo $disabled; ?> /></li>
651
+ <li><input type="submit" id="form-element-email" class="button-secondary" name="field_type" value="Email"<?php echo $disabled; ?> /></li>
652
+ <li><input type="submit" id="form-element-url" class="button-secondary" name="field_type" value="URL"<?php echo $disabled; ?> /></li>
653
+ <li><input type="submit" id="form-element-currency" class="button-secondary" name="field_type" value="Currency"<?php echo $disabled; ?> /></li>
654
+ <li><input type="submit" id="form-element-digits" class="button-secondary" name="field_type" value="Number"<?php echo $disabled; ?> /></li>
655
+ <li><input type="submit" id="form-element-time" class="button-secondary" name="field_type" value="Time"<?php echo $disabled; ?> /></li>
656
+ <li><input type="submit" id="form-element-phone" class="button-secondary" name="field_type" value="Phone"<?php echo $disabled; ?> /></li>
657
+ </ul>
 
 
 
 
 
658
  </div>
659
  </div>
660
  </div>
687
  <?php
688
  /* Loop through each for and build the tabs */
689
  foreach ( $forms as $form ) {
690
+
691
  /* Control selected tab */
692
  if ( $form_nav_selected_id == $form->form_id ) :
693
  echo '<span class="nav-tab nav-tab-active">' . stripslashes( $form->form_title ) . '</span>';
699
  $form_email_from_override = stripslashes( $form->form_email_from_override);
700
  $form_email_from_name_override = stripslashes( $form->form_email_from_name_override);
701
  $form_email_to = unserialize( stripslashes( $form->form_email_to ) );
702
+ $form_success_type = stripslashes( $form->form_success_type );
703
+ $form_success_message = stripslashes( $form->form_success_message );
704
 
705
+ /* Only show required text fields for the sender name override */
 
 
706
  $sender_query = "SELECT * FROM $this->field_table_name WHERE form_id = $form_nav_selected_id AND field_type='text' AND field_validation = '' AND field_required = 'yes'";
707
  $senders = $wpdb->get_results( $sender_query );
708
+
709
+ /* Only show required email fields for the email override */
710
+ $email_query = "SELECT * FROM $this->field_table_name WHERE (form_id = $form_nav_selected_id AND field_type='text' AND field_validation = 'email' AND field_required = 'yes') OR (form_id = $form_nav_selected_id AND field_type='email' AND field_validation = 'email' AND field_required = 'yes')";
711
+ $emails = $wpdb->get_results( $email_query );
712
+
713
  else :
714
+ echo '<a href="' . esc_url( add_query_arg( array( 'form' => $form->form_id ), admin_url( 'options-general.php?page=visual-form-builder' ) ) ) . '" class="nav-tab" id="' . $form->form_key . '">' . stripslashes( $form->form_title ) . '</a>';
 
 
 
 
 
 
715
  endif;
716
 
717
  }
721
  ?>
722
  <span class="nav-tab menu-add-new nav-tab-active"><?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add form' ) ); ?></span>
723
  <?php else : ?>
724
+ <a href="<?php echo esc_url( add_query_arg( array( 'form' => 0 ), admin_url( 'options-general.php?page=visual-form-builder' ) ) ); ?>" class="nav-tab menu-add-new"><?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add form' ) ); ?></a>
 
 
 
 
 
 
 
725
  <?php endif; ?>
726
  </div>
727
  </div>
741
  <input type="text" value="<?php echo ( isset( $form_title ) ) ? $form_title : ''; ?>" title="Enter form name here" class="menu-name regular-text menu-item-textbox" id="form-name" name="form_title" />
742
  </label>
743
  <?php
744
+ /* Display sender details and confirmation message if we're on a form, otherwise just the form name */
745
  if ( $form_nav_selected_id !== '0' ) :
746
  ?>
747
  <br class="clear" />
748
+
749
+ <div id="form-details-nav">
750
+ <a href="<?php echo add_query_arg( array( 'form' => $form_nav_selected_id, 'details' => 'email' ), admin_url( 'options-general.php?page=visual-form-builder' ) ); ?>" class="<?php echo ( 'email' == $details_meta ) ? 'current' : ''; ?>" title="Customize Email Details">Email Details</a>
751
+ <a href="<?php echo add_query_arg( array( 'form' => $form_nav_selected_id, 'details' => 'confirmation' ), admin_url( 'options-general.php?page=visual-form-builder' ) ); ?>" class="<?php echo ( 'confirmation' == $details_meta ) ? 'current' : ''; ?>" title="Customize Confirmation Message">Confirmation</a>
752
+ </div>
753
 
754
+ <div id="email-details" class="<?php echo ( 'email' == $details_meta ) ? 'form-details-current' : 'form-details'; ?>">
755
+ <p><em>The forms you build here will send information to one or more email addresses when submitted by a user on your site. Use the fields below to customize the details of that email.</em></p>
756
+ <label for="form-email-subject" class="menu-name-label howto open-label">
757
+ <span class="sender-labels">E-mail Subject</span>
758
+ <input type="text" value="<?php echo $form_subject; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-subject" name="form_email_subject" />
759
+ </label>
760
+ <br class="clear" />
761
+ <label for="form-email-sender-name" class="menu-name-label howto open-label">
762
+ <span class="sender-labels">Sender Name</span>
763
+ <input type="text" value="<?php echo $form_email_from_name; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-sender-name" name="form_email_from_name"<?php echo ( $form_email_from_name_override != '' ) ? ' readonly="readonly"' : ''; ?> />
764
+ </label>
765
+ <span>OR</span>
766
+ <select name="form_email_from_name_override" id="form_email_from_name_override">
767
+ <option value="" <?php selected( $form_email_from_name_override, '' ); ?>>Select a required text field</option>
768
+ <?php
769
+ foreach( $senders as $sender ) {
770
+ echo '<option value="' . $sender->field_id . '"' . selected( $form_email_from_name_override, $sender->field_id ) . '>' . $sender->field_name . '</option>';
771
+ }
772
+ ?>
773
+ </select>
774
+ <br class="clear" />
775
+ <label for="form-email-sender" class="menu-name-label howto open-label">
776
+ <span class="sender-labels">Sender E-mail</span>
777
+ <input type="text" value="<?php echo $form_email_from; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-sender" name="form_email_from"<?php echo ( $form_email_from_override != '' ) ? ' readonly="readonly"' : ''; ?> />
778
+ </label>
779
+ <span>OR</span>
780
+ <select name="form_email_from_override" id="form_email_from_override">
781
+ <option value="" <?php selected( $form_email_from_override, '' ); ?>>Select a required text field with email validation</option>
782
+ <?php
783
+ foreach( $emails as $email ) {
784
+ echo '<option value="' . $email->field_id . '"' . selected( $form_email_from_override, $email->field_id ) . '>' . $email->field_name . '</option>';
785
+ }
786
+ ?>
787
+ </select>
788
+ <br class="clear" />
789
+ <label for="form-email-to" class="menu-name-label howto open-label">
790
+ <span class="sender-labels">E-mail(s) To</span>
791
+ <input type="text" value="<?php echo $form_email_to; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-to" name="form_email_to" />
792
+ </label>
793
+ <span><em>(multiple emails separated by commas)</em></span>
794
+ </div>
795
+
796
+ <div id="confirmation-message" class="<?php echo ( 'confirmation' == $details_meta ) ? 'form-details-current' : 'form-details'; ?>">
797
+ <p><em>After someone submits a form, you can control what is displayed. By default, it's a message but you can send them to another WordPress Page or a custom URL.</em></p>
798
+ <label for="form-success-text" class="menu-name-label open-label">
799
+ <input type="radio" value="text" id="form-success-type-text" class="form-success-type" name="form_success_type" <?php checked( $form_success_type, 'text' ); ?> />
800
+ <span>Text</span>
801
+ </label>
802
+ <label for="form-success-page" class="menu-name-label open-label">
803
+ <input type="radio" value="page" id="form-success-type-page" class="form-success-type" name="form_success_type" <?php checked( $form_success_type, 'page' ); ?>/>
804
+ <span>Page</span>
805
+ </label>
806
+ <label for="form-success-redirect" class="menu-name-label open-label">
807
+ <input type="radio" value="redirect" id="form-success-type-redirect" class="form-success-type" name="form_success_type" <?php checked( $form_success_type, 'redirect' ); ?>/>
808
+ <span>Redirect</span>
809
+ </label>
810
+ <br class="clear" />
811
+
812
+ <?php
813
+ /* If there's no text message, make sure there is something displayed by setting a default */
814
+ if ( $form_success_message === '' )
815
+ $default_text = '<p id="form_success">Your form was successfully submitted. Thank you for contacting us.</p>';
816
  ?>
817
+ <textarea id="form-success-message-text" class="form-success-message<?php echo ( 'text' == $form_success_type ) ? ' active' : ''; ?>" name="form_success_message_text"><?php echo $default_text; ?><?php echo ( 'text' == $form_success_type ) ? $form_success_message : ''; ?></textarea>
818
+
819
+ <?php
820
+ /* Display all Pages */
821
+ wp_dropdown_pages( array(
822
+ 'name' => 'form_success_message_page',
823
+ 'id' => 'form-success-message-page',
824
+ 'show_option_none' => 'Select a Page',
825
+ 'selected' => $form_success_message
826
+ ));
 
 
827
  ?>
828
+ <input type="text" value="<?php echo ( 'redirect' == $form_success_type ) ? $form_success_message : ''; ?>" id="form-success-message-redirect" class="form-success-message regular-text<?php echo ( 'redirect' == $form_success_type ) ? ' active' : ''; ?>" name="form_success_message_redirect" />
829
+
830
+ </div>
831
+ <?php endif; ?>
 
 
 
 
832
  <br class="clear" />
833
  <div class="publishing-action">
834
  <input type="submit" value="<?php echo ( $action == 'create_form' ) ? 'Create Form' : 'Save Form'; ?>" class="button-primary menu-save" id="save_form" name="save_form" />
853
  <?php else :
854
 
855
  if ( !empty( $form_nav_selected_id ) && $form_nav_selected_id !== '0' ) :
856
+ /* Display help text for adding fields */
857
  echo '<div class="post-body-plain" id="menu-instructions"><p>Select form inputs from the box at left to begin building your custom form. An initial fieldset has been automatically added to get you started.</p></div>';
858
 
859
+ /* Display all fields for the selected form */
860
  $query_fields = "SELECT * FROM $this->field_table_name WHERE form_id = $form_nav_selected_id ORDER BY field_sequence ASC";
 
861
  $fields = $wpdb->get_results( $query_fields );
862
 
863
+ echo '<ul id="menu-to-edit" class="menu ui-sortable droppable">';
864
 
865
+ /* Loop through each field and display */
866
  foreach ( $fields as $field ) :
867
  ?>
868
  <li id="form_item_<?php echo $field->field_id; ?>" class="form-item">
896
  </label>
897
  </p>
898
 
899
+ <?php
900
+ /* Display the Options input only for radio, checkbox, and select fields */
901
+ if ( in_array( $field->field_type, array( 'radio', 'checkbox', 'select' ) ) ) : ?>
902
  <p class="description description-wide">
903
  <?php
904
  if ( !empty( $field->field_options ) ) {
922
  <p class="description description-thin">
923
  <label for="edit-form-item-validation">
924
  Validation<br />
925
+ <select name="field_validation-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-validation-<?php echo $field->field_id; ?>"<?php echo ( in_array( $field->field_type, array( 'radio', 'select', 'checkbox', 'address', 'date', 'textarea' ) ) ) ? ' disabled="disabled"' : ''; ?>>
926
+ <?php if ( $field->field_type == 'time' ) : ?>
927
+ <option value="time-12" <?php selected( $field->field_validation, 'time-12' ); ?>>12 Hour Format</option>
928
+ <option value="time-24" <?php selected( $field->field_validation, 'time-24' ); ?>>24 Hour Format</option>
929
+ <?php else : ?>
930
  <option value="" <?php selected( $field->field_validation, '' ); ?>>None</option>
931
  <option value="email" <?php selected( $field->field_validation, 'email' ); ?>>Email</option>
932
  <option value="url" <?php selected( $field->field_validation, 'url' ); ?>>URL</option>
933
  <option value="date" <?php selected( $field->field_validation, 'date' ); ?>>Date</option>
934
  <option value="number" <?php selected( $field->field_validation, 'number' ); ?>>Number</option>
935
  <option value="digits" <?php selected( $field->field_validation, 'digits' ); ?>>Digits</option>
936
+ <option value="phone" <?php selected( $field->field_validation, 'phone' ); ?>>Phone</option>
937
+ <?php endif; ?>
938
  </select>
939
  </label>
940
  </p>
948
  </label>
949
  </p>
950
 
951
+ <?php if ( !in_array( $field->field_type, array( 'radio', 'checkbox', 'time' ) ) ) : ?>
952
  <p class="description description-wide">
953
  <label for="edit-form-item-size">
954
  Size<br />
992
  endif;
993
  }
994
 
995
+ /**
996
+ * Handle confirmation when form is submitted
997
+ *
998
+ * @since 1.3
999
+ */
1000
+ function confirmation(){
1001
+ global $wpdb;
1002
+
1003
+ $form_id = ( isset( $_REQUEST['form_id'] ) ) ? $_REQUEST['form_id'] : '';
1004
+
1005
+ if ( isset( $_REQUEST['visual-form-builder-submit'] ) && in_array( $_REQUEST['visual-form-builder-submit'], array( 'Submit', 'submit' ) ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'visual-form-builder-nonce' ) ) {
1006
+ /* Get forms */
1007
+ $order = sanitize_sql_orderby( 'form_id DESC' );
1008
+ $query = "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order";
1009
+
1010
+ $forms = $wpdb->get_results( $query );
1011
+
1012
+ foreach ( $forms as $form ) {
1013
+ /* If text, return output and format the HTML for display */
1014
+ if ( 'text' == $form->form_success_type )
1015
+ return html_entity_decode( wp_kses_stripslashes( $form->form_success_message ) );
1016
+ /* If page, redirect to the permalink */
1017
+ elseif ( 'page' == $form->form_success_type ) {
1018
+ $page = get_permalink( $form->form_success_message );
1019
+ wp_redirect( $page );
1020
+ exit();
1021
+ }
1022
+ /* If redirect, redirect to the URL */
1023
+ elseif ( 'redirect' == $form->form_success_type ) {
1024
+ wp_redirect( $form->form_success_message );
1025
+ exit();
1026
+ }
1027
+ }
1028
+ }
1029
+ }
1030
+
1031
  /**
1032
  * Output form via shortcode
1033
  *
1049
 
1050
  /* If form is submitted, show success message, otherwise the form */
1051
  if ( isset( $_REQUEST['visual-form-builder-submit'] ) && in_array( $_REQUEST['visual-form-builder-submit'], array( 'Submit', 'submit' ) ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'visual-form-builder-nonce' ) ) {
1052
+ $output = $this->confirmation();
1053
  }
1054
  else {
1055
  /* Get forms */
1073
  foreach ( $fields as $field ) {
1074
  if ( $field->field_type == 'fieldset' ) {
1075
  /* Close each fieldset */
1076
+ if ( $open_fieldset == true )
1077
+ $output .= '</ul><br /></fieldset>';
 
1078
 
1079
  $output .= '<fieldset><div class="legend"><h3>' . $field->field_name . '</h3></div><ul>';
1080
  $open_fieldset = true;
1083
  /* If field is required, build the span and add setup the 'required' class */
1084
  $required_span = ( !empty( $field->field_required ) && $field->field_required === 'yes' ) ? ' <span>*</span>' : '';
1085
  $required = ( !empty( $field->field_required ) && $field->field_required === 'yes' ) ? ' required' : '';
1086
+ $validation = ( !empty( $field->field_validation ) ) ? " $field->field_validation" : '';
1087
+
1088
+ $output .= '<li><label for="vfb-' . $field->field_key . '" class="desc">'. stripslashes( $field->field_name ) . $required_span . '</label>';
1089
  }
1090
 
1091
  switch ( $field->field_type ) {
1092
+ case 'text' :
1093
+ case 'email' :
1094
+ case 'url' :
1095
+ case 'currency' :
1096
+ case 'number' :
1097
+ case 'phone' :
1098
 
1099
  if ( !empty( $field->field_description ) )
1100
+ $output .= '<span><input type="text" name="vfb-' . esc_html( $field->field_key ) . '" id="vfb-' . esc_html( $field->field_key ) . '" value="" class="text ' . $field->field_size . $required . $validation . '" /><label>' . $field->field_description . '</label></span>';
1101
  else
1102
+ $output .= '<input type="text" name="vfb-' . esc_html( $field->field_key ) . '" id="vfb-' . esc_html( $field->field_key ) . '" value="" class="text ' . $field->field_size . $required . $validation . '" />';
1103
  break;
1104
 
1105
+ case 'textarea' :
1106
 
1107
  if ( !empty( $field->field_description ) )
1108
  $output .= '<span><label>' . $field->field_description . '</label></span>';
1140
  /* Loop through each option and output */
1141
  foreach ( $options as $option => $value ) {
1142
  $output .= '<span>
1143
+ <input type="radio" name="vfb-'. $field->field_key . '" id="vfb-'. $field->field_key . '-' . $option . '" value="'. $value . '" class="radio' . $required . '" />'.
1144
+ ' <label for="vfb-' . $field->field_key . '-' . $option . '" class="choice">' . $value . '</label>' .
1145
  '</span>';
1146
  }
1147
 
1157
  $options = explode( ',', unserialize( $field->field_options ) );
1158
 
1159
  $output .= '<div>';
1160
+
1161
  /* Loop through each option and output */
1162
  foreach ( $options as $option => $value ) {
1163
+
1164
+ $output .= '<span><input type="checkbox" name="vfb-'. $field->field_key . '[]" id="vfb-'. $field->field_key . '-' . $option . '" value="'. trim( $value ) . '" class="checkbox' . $required . '" />'.
1165
+ ' <label for="vfb-' . $field->field_key . '-' . $option . '" class="choice">' . trim( $value ) . '</label></span>';
1166
  }
1167
 
1168
  $output .= '</div>';
1173
 
1174
  if ( !empty( $field->field_description ) )
1175
  $output .= '<span><label>' . $field->field_description . '</label></span>';
1176
+
1177
+ $countries = array( "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Central African Republic", "Chad", "Chile", "China", "Colombi", "Comoros", "Congo (Brazzaville)", "Congo", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor (Timor Timur)", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Fiji", "Finland", "France", "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepa", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Qatar", "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia and Montenegro", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States of America", "Uruguay", "Uzbekistan", "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe" );
1178
  $output .= '<div>
1179
  <span class="full">
1180
 
1181
+ <input type="text" name="vfb-address" maxlength="150" id="vfb-address" class="text medium' . $required . '" />
1182
  <label>Address</label>
1183
  </span>
1184
  <span class="full">
1187
  </span>
1188
  <span class="left">
1189
 
1190
+ <input type="text" name="vfb-city" maxlength="150" id="vfb-city" class="text medium' . $required . '" />
1191
  <label>City</label>
1192
  </span>
1193
  <span class="right">
1194
+ <input type="text" name="vfb-state" maxlength="150" id="vfb-state" class="text medium' . $required . '" />
1195
  <label>State / Province / Region</label>
1196
  </span>
1197
  <span class="left">
1198
 
1199
+ <input type="text" name="vfb-zip" maxlength="150" id="vfb-zip" class="text medium' . $required . '" />
1200
  <label>Postal / Zip Code</label>
1201
  </span>
1202
  <span class="right">
1203
+ <select class="select' . $required . '" name="vfb-country" id="vfb-country">
1204
+ <option selected="selected" value=""></option>';
1205
+
1206
+ foreach ( $countries as $country ) {
1207
+ $output .= "<option value='$country'>$country</option>";
1208
+ }
1209
+
1210
+ $output .= '</select>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1211
  <label>Country</label>
1212
  </span>
1213
  </div>';
1223
  $output .= '<input type="text" name="vfb-' . esc_html( $field->field_key ) . '" id="vfb-' . esc_html( $field->field_key ) . '" value="" class="text vfb-date-picker ' . $field->field_size . $required . '" />';
1224
 
1225
  break;
1226
+
1227
+ case 'time' :
1228
+ if ( !empty( $field->field_description ) )
1229
+ $output .= '<span><label>' . $field->field_description . '</label></span>';
1230
+
1231
+ /* Get the time format (12 or 24) */
1232
+ $time_format = str_replace( 'time-', '', $validation );
1233
+ /* Set whether we start with 0 or 1 and how many total hours */
1234
+ $hour_start = ( $time_format == '12' ) ? 1 : 0;
1235
+ $hour_total = ( $time_format == '12' ) ? 12 : 23;
1236
+
1237
+ /* Hour */
1238
+ $output .= '<span class="time"><select name="vfb-'. $field->field_key . '[hour]" id="vfb-'. $field->field_key . '" class="select' . $required . '">';
1239
+ for ( $i = $hour_start; $i <= $hour_total; $i++ ) {
1240
+ /* Add the leading zero */
1241
+ $hour = ( $i < 10 ) ? "0$i" : $i;
1242
+ $output .= "<option value='$hour'>$hour</option>";
1243
+ }
1244
+ $output .= '</select><label>HH</label></span>';
1245
+
1246
+ /* Minute */
1247
+ $output .= '<span class="time"><select name="vfb-'. $field->field_key . '[min]" id="vfb-'. $field->field_key . '" class="select' . $required . '">';
1248
+ for ( $i = 0; $i <= 55; $i+=5 ) {
1249
+ /* Add the leading zero */
1250
+ $min = ( $i < 10 ) ? "0$i" : $i;
1251
+ $output .= "<option value='$min'>$min</option>";
1252
+ }
1253
+ $output .= '</select><label>MM</label></span>';
1254
+
1255
+ /* AM/PM */
1256
+ if ( $time_format == '12' )
1257
+ $output .= '<span class="time"><select name="vfb-'. $field->field_key . '[ampm]" id="vfb-'. $field->field_key . '" class="select' . $required . '"><option value="AM">AM</option><option value="PM">PM</option></select><label>AM/PM</label></span>';
1258
+ break;
1259
  }
1260
 
1261
  $output .= '</li>';
1262
  }
1263
 
1264
+ /* Close user-added fields */
1265
+ $output .= '</ul><br /></fieldset>';
1266
 
1267
+ /* Output our security test */
1268
  $output .= '<fieldset>
1269
  <div class="legend">
1270
  <h3>Verification</h3>
1306
  global $wpdb, $post;
1307
 
1308
  /* Security check before moving any further */
1309
+ if ( isset( $_REQUEST['visual-form-builder-submit'] ) && $_REQUEST['visual-form-builder-submit'] == 'Submit' && $_REQUEST['vfb-spam'] == '' && is_numeric( $_REQUEST['vfb-secret'] ) && strlen( $_REQUEST['vfb-secret'] ) == 2 ) :
1310
  $nonce = $_REQUEST['_wpnonce'];
1311
 
1312
  /* Security check to verify the nonce */
1335
  $form_from_name = $form->form_email_from_name;
1336
  }
1337
 
 
 
 
 
1338
  /* Sender name override query */
1339
  $sender_query = "SELECT fields.field_key FROM $this->form_table_name AS forms LEFT JOIN $this->field_table_name AS fields ON forms.form_email_from_name_override = fields.field_id WHERE forms.form_id = $form_id";
1340
  $senders = $wpdb->get_results( $sender_query );
1341
+
1342
+ /* Sender email override query */
1343
+ $email_query = "SELECT fields.field_key FROM $this->form_table_name AS forms LEFT JOIN $this->field_table_name AS fields ON forms.form_email_from_override = fields.field_id WHERE forms.form_id = $form_id";
1344
+ $emails = $wpdb->get_results( $email_query );
1345
 
1346
+ /* Loop through name results and assign sender name to override, if needed */
1347
+ foreach( $senders as $sender ) {
1348
+ if ( !empty( $sender->field_key ) )
1349
+ $form_from_name = $_POST[ 'vfb-' . $sender->field_key ];
1350
+ }
1351
+
1352
  /* Loop through email results and assign sender email to override, if needed */
1353
  foreach ( $emails as $email ) {
1354
  if ( !empty( $email->field_key ) )
1355
  $form_from = $_POST[ 'vfb-' . $email->field_key ];
1356
  }
1357
 
 
 
 
 
 
1358
 
1359
  /* Prepare the beginning of the content */
1360
  $message = '<html><body><table rules="all" style="border-color: #666;" cellpadding="10">';
1365
  $key = str_replace( 'vfb-', '', $key );
1366
  $key = strtolower( str_replace( '-', ' ', $key ) );
1367
 
1368
+ /* If time field, build proper output */
1369
+ if ( is_array( $value ) && array_key_exists( 'hour', $value ) && array_key_exists( 'min', $value ) )
1370
+ $value = ( array_key_exists( 'ampm', $value ) ) ? substr_replace( implode( ':', $value ), ' ', 5, 1 ) : implode( ':', $value );
1371
+ /* If multiple values, build the list */
1372
+ elseif ( is_array( $value ) )
1373
+ $value = implode( ', ', $value );
1374
+ /* Lastly, handle single values */
1375
+ else
1376
+ $value = esc_html( $value );
1377
+
1378
  /* Hide fields that aren't necessary to the body of the message */
1379
  if ( !in_array( $key, array( 'spam', 'secret', 'visual form builder submit', '_wpnonce', 'form_id' ) ) ) {
1380
  $message .= '<tr><td><strong>' . ucwords( $key ) . ': </strong></td><td>' . $value . '</td></tr>';
1413
  foreach ( $form_to as $email ) {
1414
  $mail_sent = wp_mail( $email, esc_html( $form_subject ), $message, $headers );
1415
  }
1416
+ elseif ( isset( $_REQUEST['visual-form-builder-submit'] ) ) :
1417
+ /* If any of the security checks fail, provide some user feedback */
1418
+ if ( $_REQUEST['vfb-spam'] !== '' || !is_numeric( $_REQUEST['vfb-secret'] ) || strlen( $_REQUEST['vfb-secret'] ) !== 2 )
1419
+ wp_die( 'Ooops! Looks like you have failed the security validation for this form. Please go back and try again.' );
1420
+ endif;
1421
  }
1422
  }
1423