Visual Form Builder - Version 1.2.1

Version Description

Recommended update immediately! Fix for bug where entries table does not install.

Download this release

Release Info

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

Code changes from version 1.1 to 1.2.1

class-entries-list.php ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Include the wp_list_table class if running <WP 3.1 */
4
+ if( !class_exists( 'WP_List_Table' ) ) {
5
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
6
+ }
7
+
8
+ /**
9
+ * Class that builds our Entries table
10
+ *
11
+ * @since 1.2
12
+ */
13
+ class VisualFormBuilder_Entries_List extends WP_List_Table {
14
+
15
+ function __construct(){
16
+ global $status, $page, $wpdb;
17
+
18
+ /* Setup global database table names */
19
+ $this->field_table_name = $wpdb->prefix . 'visual_form_builder_fields';
20
+ $this->form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
21
+ $this->entries_table_name = $wpdb->prefix . 'visual_form_builder_entries';
22
+
23
+ /* Set parent defaults */
24
+ parent::__construct( array(
25
+ 'singular' => 'entry',
26
+ 'plural' => 'entries',
27
+ 'ajax' => false
28
+ ) );
29
+ }
30
+
31
+ /**
32
+ * Display column names. We'll handle the Form column separately.
33
+ *
34
+ * @since 1.2
35
+ * @returns $item string Column name
36
+ */
37
+ function column_default($item, $column_name){
38
+ switch ( $column_name ) {
39
+ case 'subject':
40
+ case 'sender_name':
41
+ case 'sender_email':
42
+ case 'emails_to':
43
+ case 'date':
44
+ case 'ip_address':
45
+ return $item[ $column_name ];
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Builds the on:hover links for the Form column
51
+ *
52
+ * @since 1.2
53
+ */
54
+ function column_form($item){
55
+
56
+ /* Build row actions */
57
+ $actions = array(
58
+ 'view' => sprintf( '<a href="#" id="%4$s" class="view-entry">View</a>', $_REQUEST['page'], $_REQUEST['view'], 'view', $item['entry_id'] ),
59
+ 'delete' => sprintf( '<a href="?page=%s&view=%s&action=%s&entry=%s">Delete</a>', $_REQUEST['page'], $_REQUEST['view'], 'delete', $item['entry_id'] ),
60
+ );
61
+
62
+ /* Build the form's data for display only */
63
+ $data = '<fieldset class="visual-form-builder-inline-edit"><div class="visual-form-builder-inline-edit-col">';
64
+ foreach ( $item['data'] as $k => $v ) {
65
+ $data .= '<label><span class="title">' . ucwords( $k ) . '</span><span class="input-text-wrap"><input class="ptitle" type="text" value="' . $v . '" readonly="readonly" /></span></label>';
66
+ }
67
+ $data .= '</div></fieldset><p class="submit"><a id="' . $item['entry_id'] . '" class="button-secondary alignleft visual-form-builder-inline-edit-cancel">Cancel</a></p>';
68
+
69
+ /* Hide the data intially */
70
+ $hidden_div = '<div id="entry-' . $item['entry_id'] . '" class="hidden">' . $data . '</div>';
71
+
72
+ return sprintf( '%1$s %2$s %3$s', $item['form'], $this->row_actions( $actions ), $hidden_div );
73
+ }
74
+
75
+ /**
76
+ * Used for checkboxes and bulk editing
77
+ *
78
+ * @since 1.2
79
+ */
80
+ function column_cb($item){
81
+ return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_args['singular'], $item['entry_id'] );
82
+ }
83
+
84
+ /**
85
+ * Builds the actual columns
86
+ *
87
+ * @since 1.2
88
+ */
89
+ function get_columns(){
90
+ $columns = array(
91
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
92
+ 'form' => 'Form',
93
+ 'subject' => 'Email Subject',
94
+ 'sender_name' => 'Sender Name',
95
+ 'sender_email' => 'Sender Email',
96
+ 'emails_to' => 'Emailed To',
97
+ 'ip_address' => 'IP Address',
98
+ 'date' => 'Date Submitted'
99
+ );
100
+
101
+ return $columns;
102
+ }
103
+
104
+ /**
105
+ * A custom function to get the entries and sort them
106
+ *
107
+ * @since 1.2
108
+ * @returns array() $cols SQL results
109
+ */
110
+ function get_entries( $orderby = 'date', $order = 'DESC' ){
111
+ global $wpdb;
112
+
113
+ switch ( $orderby ) {
114
+ case 'date':
115
+ $order_col = 'date_submitted';
116
+ break;
117
+ case 'form':
118
+ $order_col = 'form_title';
119
+ break;
120
+ case 'subject':
121
+ case 'ip_address':
122
+ case 'sender_name':
123
+ case 'sender_email':
124
+ $order_col = $orderby;
125
+ break;
126
+ }
127
+
128
+ $where = '';
129
+
130
+ /* If the form filter dropdown is used */
131
+ if ( $this->current_filter_action() )
132
+ $where = 'WHERE forms.form_id = ' . $this->current_filter_action();
133
+
134
+
135
+ $sql_order = sanitize_sql_orderby( "$order_col $order" );
136
+ $query = "SELECT forms.form_title, entries.* FROM $this->form_table_name AS forms INNER JOIN $this->entries_table_name AS entries ON entries.form_id = forms.form_id $where ORDER BY $sql_order";
137
+
138
+ $cols = $wpdb->get_results( $query );
139
+
140
+ return $cols;
141
+ }
142
+
143
+ /**
144
+ * Setup which columns are sortable. Default is by Date.
145
+ *
146
+ * @since 1.2
147
+ * @returns array() $sortable_columns Sortable columns
148
+ */
149
+ function get_sortable_columns() {
150
+ $sortable_columns = array(
151
+ 'form' => array( 'form', false ),
152
+ 'subject' => array( 'subject', false ),
153
+ 'sender_name' => array( 'sender_name', false ),
154
+ 'sender_email' => array( 'sender_email', false ),
155
+ 'date' => array( 'date', true )
156
+ );
157
+
158
+ return $sortable_columns;
159
+ }
160
+
161
+ /**
162
+ * Define our bulk actions
163
+ *
164
+ * @since 1.2
165
+ * @returns array() $actions Bulk actions
166
+ */
167
+ function get_bulk_actions() {
168
+ $actions = array(
169
+ 'delete' => 'Delete'
170
+ );
171
+
172
+ return $actions;
173
+ }
174
+
175
+ /**
176
+ * Process our bulk actions
177
+ *
178
+ * @since 1.2
179
+ */
180
+ function process_bulk_action() {
181
+ $entry_id = ( is_array( $_REQUEST['entry'] ) ) ? $_REQUEST['entry'] : array( $_REQUEST['entry'] );
182
+
183
+ if ( 'delete' === $this->current_action() ) {
184
+ global $wpdb;
185
+
186
+ foreach ( $entry_id as $id ) {
187
+ $id = absint( $id );
188
+ $wpdb->query( "DELETE FROM $this->entries_table_name WHERE entries_id = $id" );
189
+ }
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Adds our forms filter dropdown
195
+ *
196
+ * @since 1.2
197
+ */
198
+ function extra_tablenav( $which ) {
199
+ global $wpdb;
200
+ $query = "SELECT DISTINCT forms.form_title, forms.form_id FROM $this->form_table_name AS forms ORDER BY forms.form_title ASC";
201
+
202
+ $cols = $wpdb->get_results( $query );
203
+
204
+ /* Only display the dropdown on the top of the table */
205
+ if ( 'top' == $which ) {
206
+ echo '<div class="alignleft actions">
207
+ <select id="form-filter" name="form-filter">
208
+ <option value="-1"' . selected( $this->current_filter_action(), -1 ) . '>View all forms</option>';
209
+
210
+ foreach ( $cols as $form ) {
211
+ echo '<option value="' . $form->form_id . '"' . selected( $this->current_filter_action(), $form->form_id ) . '>' . $form->form_title . '</option>';
212
+ }
213
+
214
+ echo '</select>
215
+ <input type="submit" value="Filter" class="button-secondary" />
216
+ </div>';
217
+ }
218
+ }
219
+
220
+ /**
221
+ * Set our forms filter action
222
+ *
223
+ * @since 1.2
224
+ * @returns int Form ID
225
+ */
226
+ function current_filter_action() {
227
+ if ( isset( $_REQUEST['form-filter'] ) && -1 != $_REQUEST['form-filter'] )
228
+ return $_REQUEST['form-filter'];
229
+
230
+ return false;
231
+ }
232
+
233
+ /**
234
+ * Prepares our data for display
235
+ *
236
+ * @since 1.2
237
+ */
238
+ function prepare_items() {
239
+ global $wpdb;
240
+
241
+ /* Get screen options from the wp_options table */
242
+ $options = get_option( 'visual-form-builder-screen-options' );
243
+
244
+ /* How many to show per page */
245
+ $per_page = $options['per_page'];
246
+
247
+ /* Get column headers */
248
+ $columns = $this->get_columns();
249
+ $hidden = array();
250
+
251
+ /* Get sortable columns */
252
+ $sortable = $this->get_sortable_columns();
253
+
254
+ /* Build the column headers */
255
+ $this->_column_headers = array($columns, $hidden, $sortable);
256
+
257
+ /* Handle our bulk actions */
258
+ $this->process_bulk_action();
259
+
260
+ /* Set our ORDER BY and ASC/DESC to sort the entries */
261
+ $orderby = ( !empty( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : 'date';
262
+ $order = ( !empty( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : 'desc';
263
+
264
+ /* Get the sorted entries */
265
+ $entries = $this->get_entries( $orderby, $order );
266
+
267
+ $data = array();
268
+
269
+ /* Loop trough the entries and setup the data to be displayed for each row */
270
+ foreach ( $entries as $entry ) {
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 )
282
+ );
283
+ }
284
+
285
+ /* What page are we looking at? */
286
+ $current_page = $this->get_pagenum();
287
+
288
+ /* How many entries do we have? */
289
+ $total_items = count( $entries );
290
+
291
+ /* Calculate pagination */
292
+ $data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
293
+
294
+ /* Add sorted data to the items property */
295
+ $this->items = $data;
296
+
297
+ /* Register our pagination */
298
+ $this->set_pagination_args( array(
299
+ 'total_items' => $total_items,
300
+ 'per_page' => $per_page,
301
+ 'total_pages' => ceil( $total_items / $per_page )
302
+ ) );
303
+ }
304
+ }
305
+ ?>
css/visual-form-builder-admin.css CHANGED
@@ -8,4 +8,11 @@ label.error{color:red;display:block;}
8
  box-shadow:0 1px 0 #e3e3e3 inset;
9
  }
10
  .sender-labels{width:80px;}
11
- .is-field-required{color:#BC1212; vertical-align:middle;}
 
 
 
 
 
 
 
8
  box-shadow:0 1px 0 #e3e3e3 inset;
9
  }
10
  .sender-labels{width:80px;}
11
+ .is-field-required{color:#BC1212; vertical-align:middle;}
12
+ .visual-form-builder-inline-edit{width:100%;}
13
+ .visual-form-builder-inline-edit-col{padding:0 0.5em;}
14
+ .visual-form-builder-inline-edit label{display:block;margin:0.2em 0;}
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;}
js/visual-form-builder.js CHANGED
@@ -61,7 +61,25 @@ jQuery(document).ready(function($) {
61
  $( '.nav-tabs' ).animate({ marginLeft: '+=' + tabsWidth[count] });
62
  });
63
 
 
 
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  /* Handle sorting the field items */
67
  $( '#menu-to-edit' ).sortable({
@@ -122,7 +140,9 @@ jQuery(document).ready(function($) {
122
  multiemail: true
123
  },
124
  form_email_from: {
125
- required: true,
 
 
126
  email: true
127
  }
128
  },
@@ -131,6 +151,26 @@ jQuery(document).ready(function($) {
131
  }
132
  });
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  /* Custom validation method to check multiple emails */
135
  $.validator.addMethod( 'multiemail', function( value, element ) {
136
 
61
  $( '.nav-tabs' ).animate({ marginLeft: '+=' + tabsWidth[count] });
62
  });
63
 
64
+ /* Display entries form data */
65
+ $( '.view-entry' ).click( function( e ){
66
 
67
+ var id = $( e.target ).attr( 'id' );
68
+
69
+ $( e.target ).closest( 'td' ).children( '#entry-' + id ).slideToggle( 'fast' );
70
+
71
+ return false;
72
+ });
73
+
74
+ /* Hide entries form data */
75
+ $( '.visual-form-builder-inline-edit-cancel' ).click( function( e ){
76
+
77
+ var id = $( e.target ).attr( 'id' );
78
+
79
+ $( e.target ).closest( 'td' ).children( '#entry-' + id ).slideToggle( 'fast' );
80
+
81
+ return false;
82
+ });
83
 
84
  /* Handle sorting the field items */
85
  $( '#menu-to-edit' ).sortable({
140
  multiemail: true
141
  },
142
  form_email_from: {
143
+ required: function( element ){
144
+ return $( '#form_email_from_override option:selected' ).val() == ''
145
+ },
146
  email: true
147
  }
148
  },
151
  }
152
  });
153
 
154
+ /* Make Sender Name field readonly if the override is active */
155
+ $( '#form_email_from_name_override' ).change( function(){
156
+ if( $( '#form_email_from_name_override' ).val() == '' ) {
157
+ $( '#form-email-sender-name' ).attr( 'readonly', false );
158
+ }
159
+ else{
160
+ $( '#form-email-sender-name' ).attr( 'readonly', 'readonly' );
161
+ }
162
+ });
163
+
164
+ /* Make Sender Email field readonly if the override is active */
165
+ $( '#form_email_from_override' ).change( function(){
166
+ if( $( '#form_email_from_override' ).val() == '' ) {
167
+ $( '#form-email-sender' ).attr( 'readonly', false );
168
+ }
169
+ else{
170
+ $( '#form-email-sender' ).attr( 'readonly', 'readonly' );
171
+ }
172
+ });
173
+
174
  /* Custom validation method to check multiple emails */
175
  $.validator.addMethod( 'multiemail', function( value, element ) {
176
 
readme.txt CHANGED
@@ -2,10 +2,10 @@
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
6
- Stable tag: 1.1
7
 
8
- Dynamically build forms using a simple interface. Forms include jQuery validation and a basic logic-based verification system.
9
 
10
  == Description ==
11
 
@@ -15,6 +15,7 @@ Dynamically build forms using a simple interface. Forms include jQuery validatio
15
 
16
  * Setup and organize your form using a drag-and-drop interface
17
  * Automatically includes a basic logic-based verification system
 
18
  * Send form submissions to multiple emails
19
  * Utilizes jQuery Form Validation
20
  * Save time by adding a complete address block field
@@ -76,9 +77,22 @@ To use the more complex features of the Date Picker plugin, you will need to:
76
 
77
  1. Visual Form Builder page
78
  2. Configuring field item options
 
79
 
80
  == Changelog ==
81
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  **Version 1.1**
83
 
84
  * Fix bug that prevented all selected checkbox options from being submitted
@@ -91,5 +105,5 @@ To use the more complex features of the Date Picker plugin, you will need to:
91
 
92
  == Upgrade Notice ==
93
 
94
- = 1.1 =
95
- Bug fix for all checkbox options not being submitted
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
 
15
 
16
  * Setup and organize your form using a drag-and-drop interface
17
  * Automatically includes a basic logic-based verification system
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
77
 
78
  1. Visual Form Builder page
79
  2. Configuring field item options
80
+ 3. Entries management screen
81
 
82
  == Changelog ==
83
 
84
+ **Version 1.2.1**
85
+
86
+ * Fix bug where entries table does not install
87
+
88
+ **Version 1.2**
89
+
90
+ * Fix bug where reserved words may have been used
91
+ * Fix bug where multiple open validation dropdowns could not be used in the builder
92
+ * Add entries tracking and management feature
93
+ * Improve form submission by removing wp_redirect
94
+ * Add Sender Name and Email override
95
+
96
  **Version 1.1**
97
 
98
  * Fix bug that prevented all selected checkbox options from being submitted
105
 
106
  == Upgrade Notice ==
107
 
108
+ = 1.2.1 =
109
+ Recommended update immediately! Fix for bug where entries table does not install.
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
screenshot-3.png ADDED
Binary file
uninstall.php CHANGED
@@ -6,7 +6,11 @@
6
 
7
  $form_table = $wpdb->prefix . 'visual_form_builder_fields';
8
  $fields_table = $wpdb->prefix . 'visual_form_builder_forms';
 
9
 
10
  $wpdb->query( "DROP TABLE IF EXISTS $form_table" );
11
  $wpdb->query( "DROP TABLE IF EXISTS $fields_table" );
 
 
 
12
  ?>
6
 
7
  $form_table = $wpdb->prefix . 'visual_form_builder_fields';
8
  $fields_table = $wpdb->prefix . 'visual_form_builder_forms';
9
+ $entries_table = $wpdb->prefix . 'visual_form_builder_entries';
10
 
11
  $wpdb->query( "DROP TABLE IF EXISTS $form_table" );
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
  ?>
visual-form-builder.php CHANGED
@@ -1,9 +1,9 @@
1
  <?php
2
  /*
3
  Plugin Name: Visual Form Builder
4
- Description: Dynamically build forms using a simple interface. Forms include jQuery validation and a basic logic-based verification system.
5
  Author: Matthew Muro
6
- Version: 1.1
7
  */
8
 
9
  /*
@@ -27,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.1';
31
 
32
  public function __construct(){
33
  global $wpdb;
@@ -35,6 +35,7 @@ class Visual_Form_Builder{
35
  /* Setup global database table names */
36
  $this->field_table_name = $wpdb->prefix . 'visual_form_builder_fields';
37
  $this->form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
 
38
 
39
  /* Make sure we are in the admin before proceeding. */
40
  if ( is_admin() ) {
@@ -44,6 +45,13 @@ class Visual_Form_Builder{
44
  add_action( 'wp_ajax_visual_form_builder_process_sort', array( &$this, 'visual_form_builder_process_sort_callback' ) );
45
  add_action( 'admin_init', array( &$this, 'add_visual_form_builder_contextual_help' ) );
46
 
 
 
 
 
 
 
 
47
  /* Adds a Settings link to the Plugins page */
48
  add_filter( 'plugin_action_links', array( &$this, 'visual_form_builder_plugin_action_links' ), 10, 2 );
49
 
@@ -51,6 +59,18 @@ class Visual_Form_Builder{
51
  if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'visual-form-builder' )
52
  wp_admin_css( 'nav-menu' );
53
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  /* Load the jQuery and CSS we need if we're on our plugin page */
55
  add_action( 'load-settings_page_visual-form-builder', array( &$this, 'form_admin_scripts' ) );
56
  add_action( 'load-settings_page_visual-form-builder', array( &$this, 'form_admin_css' ) );
@@ -65,18 +85,18 @@ class Visual_Form_Builder{
65
  }
66
 
67
  /**
68
- * Queue plugin CSS for admin styles
69
  *
70
- * @since 1.0
71
  */
72
- public function form_admin_css(){
73
- wp_enqueue_style( 'visual-form-builder-style', plugins_url( 'visual-form-builder' ) . '/css/visual-form-builder-admin.css' );
74
  }
75
 
76
  /**
77
  * Register contextual help. This is for the Help tab dropdown
78
  *
79
- * @since 1.0
80
  */
81
  public function add_visual_form_builder_contextual_help(){
82
  $text = "<p><strong>Getting Started</strong></p>
@@ -115,6 +135,53 @@ class Visual_Form_Builder{
115
  add_contextual_help( 'settings_page_visual-form-builder', $text );
116
  }
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  /**
119
  * Install database tables
120
  *
@@ -123,11 +190,9 @@ class Visual_Form_Builder{
123
  static function install_db() {
124
  global $wpdb;
125
 
126
- /* Declare version again here because this is a static function */
127
- $vfb_db_version = '1.1';
128
-
129
  $field_table_name = $wpdb->prefix . 'visual_form_builder_fields';
130
  $form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
 
131
 
132
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
133
 
@@ -155,24 +220,38 @@ class Visual_Form_Builder{
155
  form_email_to TEXT,
156
  form_email_from TEXT,
157
  form_email_from_name TEXT,
 
 
158
  UNIQUE KEY (form_id)
159
  );";
160
 
161
- /* Check to see if the table already exists before creating it */
162
- if ( $wpdb->get_var( "SHOW TABLES LIKE '$field_table_name'" ) != $field_table_name )
163
- dbDelta( $field_sql );
164
-
165
- /* Check to see if the table already exists before creating it */
166
- if ( $wpdb->get_var( "SHOW TABLES LIKE '$form_table_name'" ) != $form_table_name )
167
- dbDelta( $form_sql );
 
 
 
 
 
168
 
169
- /* Add a database version to help with upgrades */
170
- if ( !get_option( 'vfb_db_version' ) )
171
- update_option( 'vfb_db_version', $vfb_db_version );
 
172
 
173
- if ( get_option( 'vfb_db_version' ) != $vfb_db_version )
174
- update_option( 'vfb_db_version', $vfb_db_version );
175
-
 
 
 
 
 
 
176
  }
177
 
178
  /**
@@ -286,6 +365,8 @@ class Visual_Form_Builder{
286
  $form_to = serialize( esc_html( $_REQUEST['form_email_to'] ) );
287
  $form_from = esc_html( $_REQUEST['form_email_from'] );
288
  $form_from_name = esc_html( $_REQUEST['form_email_from_name'] );
 
 
289
 
290
  check_admin_referer( 'update_form-' . $form_id );
291
 
@@ -295,7 +376,9 @@ class Visual_Form_Builder{
295
  'form_email_subject' => $form_subject,
296
  'form_email_to' => $form_to,
297
  'form_email_from' => $form_from,
298
- 'form_email_from_name' => $form_from_name
 
 
299
  );
300
 
301
  $where = array(
@@ -394,11 +477,9 @@ class Visual_Form_Builder{
394
  /**
395
  * The jQuery field sorting callback
396
  *
397
- *
398
  * @since 1.0
399
  */
400
  public function visual_form_builder_process_sort_callback() {
401
-
402
  global $wpdb;
403
 
404
  $order = explode( ',', $_REQUEST['order'] );
@@ -413,7 +494,7 @@ class Visual_Form_Builder{
413
 
414
  die(1);
415
  }
416
-
417
  /**
418
  * Builds the options settings page
419
  *
@@ -428,26 +509,43 @@ class Visual_Form_Builder{
428
 
429
  /* Query to get all forms */
430
  $order = sanitize_sql_orderby( 'form_id DESC' );
431
- $query = "SELECT * FROM $this->form_table_name ORDER BY $order";
432
 
433
  /* Build our forms as an object */
434
- $forms = $wpdb->get_results( $query );
435
 
436
  /* Loop through each form and assign a form id, if any */
437
  foreach ( $forms as $form ) {
438
  $form_id = ( $form_nav_selected_id == $form->form_id ) ? $form->form_id : '';
439
- //$form_name = ( $form_nav_selected_id == $form->form_id ) ? $form->form_title : '';
440
  if ( $form_nav_selected_id == $form->form_id )
441
- $form_name = stripslashes( $form->form_title );
442
  }
443
 
444
-
445
  ?>
446
 
447
  <div class="wrap">
448
  <?php screen_icon( 'options-general' ); ?>
449
- <h2><?php _e('Visual Form Builder', 'visual-form-builder'); ?></h2>
450
- <?php echo ( isset( $this->message ) ) ? $this->message : ''; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  <div id="nav-menus-frame">
452
  <div id="menu-settings-column" class="metabox-holder<?php echo ( empty( $form_nav_selected_id ) ) ? ' metabox-holder-disabled' : ''; ?>">
453
  <div id="side-sortables" class="metabox-holder">
@@ -528,7 +626,15 @@ class Visual_Form_Builder{
528
  $form_subject = stripslashes( $form->form_email_subject );
529
  $form_email_from_name = stripslashes( $form->form_email_from_name );
530
  $form_email_from = stripslashes( $form->form_email_from);
 
 
531
  $form_email_to = unserialize( stripslashes( $form->form_email_to ) );
 
 
 
 
 
 
532
  else :
533
  echo '<a href="' .
534
  esc_url( add_query_arg(
@@ -559,7 +665,7 @@ class Visual_Form_Builder{
559
  </div>
560
  <div class="nav-tabs-arrow nav-tabs-arrow-right"><a>&raquo;</a></div>
561
  </div>
562
-
563
  <div class="menu-edit">
564
  <form method="post" id="visual-form-builder-update" action="">
565
  <input name="action" type="hidden" value="<?php echo $action; ?>" />
@@ -586,13 +692,29 @@ class Visual_Form_Builder{
586
  <br class="clear" />
587
  <label for="form-email-sender-name" class="menu-name-label howto open-label">
588
  <span class="sender-labels">Sender Name</span>
589
- <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" />
590
  </label>
 
 
 
 
 
 
 
 
591
  <br class="clear" />
592
  <label for="form-email-sender" class="menu-name-label howto open-label">
593
  <span class="sender-labels">Sender E-mail</span>
594
- <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" />
595
  </label>
 
 
 
 
 
 
 
 
596
  <br class="clear" />
597
  <label for="form-email-to" class="menu-name-label howto open-label">
598
  <span class="sender-labels">E-mail(s) To</span>
@@ -689,7 +811,7 @@ class Visual_Form_Builder{
689
  <p class="description description-thin">
690
  <label for="edit-form-item-validation">
691
  Validation<br />
692
- <select name="field_validation-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-validation"<?php echo ( $field->field_type !== 'text' ) ? ' disabled="disabled"' : ''; ?>>
693
  <option value="" <?php selected( $field->field_validation, '' ); ?>>None</option>
694
  <option value="email" <?php selected( $field->field_validation, 'email' ); ?>>Email</option>
695
  <option value="url" <?php selected( $field->field_validation, 'url' ); ?>>URL</option>
@@ -750,6 +872,7 @@ class Visual_Form_Builder{
750
  </div>
751
  </div>
752
  <?php
 
753
  }
754
 
755
  /**
@@ -766,23 +889,28 @@ class Visual_Form_Builder{
766
  ), $atts )
767
  );
768
 
 
769
  $form_id = ( isset( $id ) && !empty( $id ) ) ? $id : $atts[0];
770
 
771
- $order = sanitize_sql_orderby( 'form_id DESC' );
772
- $query = "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order";
773
-
774
- $forms = $wpdb->get_results( $query );
775
-
776
- $query_fields = "SELECT * FROM $this->field_table_name WHERE form_id = " . $form_id . " ORDER BY field_sequence ASC";
777
-
778
- $fields = $wpdb->get_results( $query_fields );
779
-
780
  $open_fieldset = false;
781
 
782
- if ( isset( $_REQUEST['success'] ) && $_REQUEST['success'] == 1 && wp_verify_nonce( $_REQUEST['key'], 'visual-form-builder-success-nonce' ) ) {
 
783
  $output = '<p id="form_success">Your form was successfully submitted. Thank you for contacting us.</p>';
784
  }
785
  else {
 
 
 
 
 
 
 
 
 
 
 
 
786
  foreach ( $forms as $form ) :
787
 
788
  $output = '<form id="' . $form->form_key . '" class="visual-form-builder" method="post">
@@ -811,9 +939,9 @@ class Visual_Form_Builder{
811
  case 'text':
812
 
813
  if ( !empty( $field->field_description ) )
814
- $output .= '<span><input type="text" name="' . esc_html( $field->field_key ) . '" id="' . esc_html( $field->field_key ) . '" value="" class="text ' . $field->field_size . $required . '" /><label>' . $field->field_description . '</label></span>';
815
  else
816
- $output .= '<input type="text" name="' . esc_html( $field->field_key ) . '" id="' . esc_html( $field->field_key ) . '" value="" class="text ' . $field->field_size . $required . '" />';
817
  break;
818
 
819
  case 'textarea':
@@ -821,7 +949,7 @@ class Visual_Form_Builder{
821
  if ( !empty( $field->field_description ) )
822
  $output .= '<span><label>' . $field->field_description . '</label></span>';
823
 
824
- $output .= '<textarea name="'. $field->field_key. '" id="'. $field->field_key. '" class="textarea ' . $field->field_size . $required . '"></textarea>';
825
 
826
  break;
827
 
@@ -829,7 +957,7 @@ class Visual_Form_Builder{
829
  if ( !empty( $field->field_description ) )
830
  $output .= '<span><label>' . $field->field_description . '</label></span>';
831
 
832
- $output .= '<select name="'. $field->field_key. '" id="'. $field->field_key. '" class="select ' . $field->field_size . $required . '">';
833
 
834
  $options = explode( ',', unserialize( $field->field_options ) );
835
 
@@ -854,7 +982,7 @@ class Visual_Form_Builder{
854
  /* Loop through each option and output */
855
  foreach ( $options as $option => $value ) {
856
  $output .= '<span>
857
- <input type="radio" name="'. $field->field_key. '" value="'. $value . '" class="radio ' . $required . '" />'.
858
  ' <label for="' . $field->field_key . '" class="choice">' . $value . '</label>' .
859
  '</span>';
860
  }
@@ -874,7 +1002,7 @@ class Visual_Form_Builder{
874
 
875
  /* Loop through each option and output */
876
  foreach ( $options as $option => $value ) {
877
- $output .= '<span><input type="checkbox" name="'. $field->field_key. '[]" id="'. $field->field_key. '" value="'. trim( $value ) . '" class="checkbox ' . $required . '" />'.
878
  ' <label for="' . $field->field_key . '" class="choice">' . trim( $value ) . '</label></span>';
879
  }
880
 
@@ -890,29 +1018,29 @@ class Visual_Form_Builder{
890
  $output .= '<div>
891
  <span class="full">
892
 
893
- <input type="text" name="address" maxlength="150" id="address" class="text medium" />
894
  <label>Address</label>
895
  </span>
896
  <span class="full">
897
- <input type="text" name="address-2" maxlength="150" id="address-2" class="text medium" />
898
  <label>Address Line 2</label>
899
  </span>
900
  <span class="left">
901
 
902
- <input type="text" name="city" maxlength="150" id="city" class="text medium" />
903
  <label>City</label>
904
  </span>
905
  <span class="right">
906
- <input type="text" name="state" maxlength="150" id="state" class="text medium" />
907
  <label>State / Province / Region</label>
908
  </span>
909
  <span class="left">
910
 
911
- <input type="text" name="zip" maxlength="150" id="zip" class="text medium" />
912
  <label>Postal / Zip Code</label>
913
  </span>
914
  <span class="right">
915
- <select class="select" name="country" id="country">
916
  <option selected="selected" value=""></option>
917
  <option value="Afghanistan">Afghanistan</option>
918
  <option value="Albania">Albania</option>
@@ -1162,9 +1290,9 @@ class Visual_Form_Builder{
1162
  case 'date':
1163
 
1164
  if ( !empty( $field->field_description ) )
1165
- $output .= '<span><input type="text" name="' . esc_html( $field->field_key ) . '" id="' . esc_html( $field->field_key ) . '" value="" class="text vfb-date-picker ' . $field->field_size . $required . '" /><label>' . $field->field_description . '</label></span>';
1166
  else
1167
- $output .= '<input type="text" name="' . esc_html( $field->field_key ) . '" id="' . esc_html( $field->field_key ) . '" value="" class="text vfb-date-picker ' . $field->field_size . $required . '" />';
1168
 
1169
  break;
1170
  }
@@ -1182,14 +1310,14 @@ class Visual_Form_Builder{
1182
  <li>
1183
  <label class="desc">Please enter any two digits with <strong>no</strong> spaces (Example: 12) <span>*</span></label>
1184
  <div>
1185
- <input type="text" name="secret" id="secret" class="text medium required digits" />
1186
  </div>
1187
  </li>
1188
  <div style="display:none;">
1189
  <li>
1190
- <label for="spam">This box is for spam protection - <strong>please leave it blank</strong>:</label>
1191
  <div>
1192
- <input name="spam" id="spam" />
1193
  </div>
1194
  </li>
1195
  </div>
@@ -1215,7 +1343,7 @@ class Visual_Form_Builder{
1215
  global $wpdb, $post;
1216
 
1217
  /* Security check before moving any further */
1218
- if ( isset( $_REQUEST['visual-form-builder-submit'] ) && $_REQUEST['visual-form-builder-submit'] == 'Submit' && $_REQUEST['spam'] == '' && is_numeric( $_REQUEST['secret'] ) && strlen( $_REQUEST['secret'] ) == 2 ) {
1219
  $nonce = $_REQUEST['_wpnonce'];
1220
 
1221
  /* Security check to verify the nonce */
@@ -1230,10 +1358,10 @@ class Visual_Form_Builder{
1230
 
1231
  /* Query to get all forms */
1232
  $order = sanitize_sql_orderby( 'form_id DESC' );
1233
- $query = "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order";
1234
 
1235
  /* Build our forms as an object */
1236
- $forms = $wpdb->get_results( $query );
1237
 
1238
  /* Get sender and email details */
1239
  foreach ( $forms as $form ) {
@@ -1244,22 +1372,64 @@ class Visual_Form_Builder{
1244
  $form_from_name = $form->form_email_from_name;
1245
  }
1246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1247
  /* Prepare the beginning of the content */
1248
  $message = '<html><body><table rules="all" style="border-color: #666;" cellpadding="10">';
1249
-
1250
  /* Loop through each form field and build the body of the message */
1251
  foreach ( $_POST as $key => $value ) {
1252
- /* Remove dashes and lowercase */
 
1253
  $key = strtolower( str_replace( '-', ' ', $key ) );
1254
 
1255
  /* If there are multiple values, build the list, otherwise it's a single value */
1256
- $value = is_array( $value ) ? implode( ', ', $value ) : esc_html( $value );
1257
 
1258
  /* Hide fields that aren't necessary to the body of the message */
1259
- if ( !in_array( $key, array( 'spam', 'secret', 'visual form builder submit', '_wpnonce', 'form_id' ) ) )
1260
  $message .= '<tr><td><strong>' . ucwords( $key ) . ': </strong></td><td>' . $value . '</td></tr>';
 
 
1261
  }
1262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1263
  /* Close out the content */
1264
  $message .= '</table></body></html>';
1265
 
@@ -1272,17 +1442,6 @@ class Visual_Form_Builder{
1272
  foreach ( $form_to as $email ) {
1273
  $mail_sent = wp_mail( $email, esc_html( $form_subject ), $message, $headers );
1274
  }
1275
-
1276
- /* If a successful response, append a GET var to trigger the success message */
1277
- if ( $mail_sent ) {
1278
- $success_nonce = wp_create_nonce( 'visual-form-builder-success-nonce' );
1279
- $sent = '?success=1&key=' . $success_nonce;
1280
- }
1281
-
1282
- /* Redirect to the same page with the appended success message */
1283
- wp_redirect( get_permalink( $post->ID ) . $sent );
1284
-
1285
- exit();
1286
  }
1287
  }
1288
  }
1
  <?php
2
  /*
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
  /* 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;
35
  /* Setup global database table names */
36
  $this->field_table_name = $wpdb->prefix . 'visual_form_builder_fields';
37
  $this->form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
38
+ $this->entries_table_name = $wpdb->prefix . 'visual_form_builder_entries';
39
 
40
  /* Make sure we are in the admin before proceeding. */
41
  if ( is_admin() ) {
45
  add_action( 'wp_ajax_visual_form_builder_process_sort', array( &$this, 'visual_form_builder_process_sort_callback' ) );
46
  add_action( 'admin_init', array( &$this, 'add_visual_form_builder_contextual_help' ) );
47
 
48
+ /* Load the includes files */
49
+ add_action( 'plugins_loaded', array( &$this, 'includes' ) );
50
+
51
+ /* Adds a Screen Options tab to the Entries screen */
52
+ add_action( 'admin_init', array( &$this, 'save_screen_options' ) );
53
+ add_filter( 'screen_settings', array( &$this, 'add_visual_form_builder_screen_options' ) );
54
+
55
  /* Adds a Settings link to the Plugins page */
56
  add_filter( 'plugin_action_links', array( &$this, 'visual_form_builder_plugin_action_links' ), 10, 2 );
57
 
59
  if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'visual-form-builder' )
60
  wp_admin_css( 'nav-menu' );
61
 
62
+ /* Add a database version to help with upgrades and run SQL install */
63
+ if ( !get_option( 'vfb_db_version' ) ) {
64
+ update_option( 'vfb_db_version', $this->vfb_db_version );
65
+ add_action( 'plugins_loaded', array( &$this, 'install_db' ) );
66
+ }
67
+
68
+ /* If database version doesn't match, update and run SQL install */
69
+ if ( get_option( 'vfb_db_version' ) != $this->vfb_db_version ) {
70
+ update_option( 'vfb_db_version', $this->vfb_db_version );
71
+ add_action( 'plugins_loaded', array( &$this, 'install_db' ) );
72
+ }
73
+
74
  /* Load the jQuery and CSS we need if we're on our plugin page */
75
  add_action( 'load-settings_page_visual-form-builder', array( &$this, 'form_admin_scripts' ) );
76
  add_action( 'load-settings_page_visual-form-builder', array( &$this, 'form_admin_css' ) );
85
  }
86
 
87
  /**
88
+ * Adds extra include files
89
  *
90
+ * @since 1.2
91
  */
92
+ public function includes(){
93
+ require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-entries-list.php' );
94
  }
95
 
96
  /**
97
  * Register contextual help. This is for the Help tab dropdown
98
  *
99
+ * @since 1.0
100
  */
101
  public function add_visual_form_builder_contextual_help(){
102
  $text = "<p><strong>Getting Started</strong></p>
135
  add_contextual_help( 'settings_page_visual-form-builder', $text );
136
  }
137
 
138
+ /**
139
+ * Adds the Screen Options tab to the Entries screen
140
+ *
141
+ * @since 1.2
142
+ */
143
+ public function add_visual_form_builder_screen_options($current){
144
+ global $current_screen;
145
+
146
+ $options = get_option( 'visual-form-builder-screen-options' );
147
+
148
+ if ( $current_screen->id == 'settings_page_visual-form-builder' && isset( $_REQUEST['view'] ) && in_array( $_REQUEST['view'], array( 'entries' ) ) ){
149
+ $current = '<h5>Show on screen</h5>
150
+ <input type="text" value="' . $options['per_page'] . '" maxlength="3" id="visual-form-builder-per-page" name="visual-form-builder-screen-options[per_page]" class="screen-per-page"> <label for="visual-form-builder-per-page">Entries</label>
151
+ <input type="submit" value="Apply" class="button" id="visual-form-builder-screen-options-apply" name="visual-form-builder-screen-options-apply">';
152
+ }
153
+
154
+ return $current;
155
+ }
156
+
157
+ /**
158
+ * Saves the Screen Options
159
+ *
160
+ * @since 1.2
161
+ */
162
+ public function save_screen_options(){
163
+ $options = get_option( 'visual-form-builder-screen-options' );
164
+
165
+ /* Default is 20 per page */
166
+ $defaults = array(
167
+ 'per_page' => 20
168
+ );
169
+
170
+ /* If the option doesn't exist, add it with defaults */
171
+ if ( !$options )
172
+ update_option( 'visual-form-builder-screen-options', $defaults );
173
+
174
+ /* If the user has saved the Screen Options, update */
175
+ if ( isset( $_REQUEST['visual-form-builder-screen-options-apply'] ) && in_array( $_REQUEST['visual-form-builder-screen-options-apply'], array( 'Apply', 'apply' ) ) ) {
176
+ $per_page = absint( $_REQUEST['visual-form-builder-screen-options']['per_page'] );
177
+ $updated_options = array(
178
+ 'per_page' => $per_page
179
+ );
180
+ update_option( 'visual-form-builder-screen-options', $updated_options );
181
+ }
182
+ }
183
+
184
+
185
  /**
186
  * Install database tables
187
  *
190
  static function install_db() {
191
  global $wpdb;
192
 
 
 
 
193
  $field_table_name = $wpdb->prefix . 'visual_form_builder_fields';
194
  $form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
195
+ $entries_table_name = $wpdb->prefix . 'visual_form_builder_entries';
196
 
197
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
198
 
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
 
228
+ $entries_sql = "CREATE TABLE $entries_table_name (
229
+ entries_id BIGINT(20) NOT NULL AUTO_INCREMENT,
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
 
241
+ /* Create or Update database tables */
242
+ dbDelta( $field_sql );
243
+ dbDelta( $form_sql );
244
+ dbDelta( $entries_sql );
245
 
246
+ }
247
+
248
+ /**
249
+ * Queue plugin CSS for admin styles
250
+ *
251
+ * @since 1.0
252
+ */
253
+ public function form_admin_css(){
254
+ wp_enqueue_style( 'visual-form-builder-style', plugins_url( 'visual-form-builder' ) . '/css/visual-form-builder-admin.css' );
255
  }
256
 
257
  /**
365
  $form_to = serialize( esc_html( $_REQUEST['form_email_to'] ) );
366
  $form_from = esc_html( $_REQUEST['form_email_from'] );
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
 
376
  'form_email_subject' => $form_subject,
377
  'form_email_to' => $form_to,
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(
477
  /**
478
  * The jQuery field sorting callback
479
  *
 
480
  * @since 1.0
481
  */
482
  public function visual_form_builder_process_sort_callback() {
 
483
  global $wpdb;
484
 
485
  $order = explode( ',', $_REQUEST['order'] );
494
 
495
  die(1);
496
  }
497
+
498
  /**
499
  * Builds the options settings page
500
  *
509
 
510
  /* Query to get all forms */
511
  $order = sanitize_sql_orderby( 'form_id DESC' );
512
+ $query = "SELECT * FROM $this->form_table_name ORDER BY $order";
513
 
514
  /* Build our forms as an object */
515
+ $forms = $wpdb->get_results( $query );
516
 
517
  /* Loop through each form and assign a form id, if any */
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
  }
524
 
 
525
  ?>
526
 
527
  <div class="wrap">
528
  <?php screen_icon( 'options-general' ); ?>
529
+ <h2><?php _e('Visual Form Builder', 'visual-form-builder'); ?></h2>
530
+ <ul class="subsubsub">
531
+ <li><a<?php echo ( !isset( $_REQUEST['view'] ) ) ? ' class="current"' : ''; ?> href="<?php echo admin_url( 'options-general.php?page=visual-form-builder' ); ?>">Forms</a> |</li>
532
+ <li><a<?php echo ( isset( $_REQUEST['view'] ) && in_array( $_REQUEST['view'], array( 'entries' ) ) ) ? ' class="current"' : ''; ?> href="<?php echo add_query_arg( 'view', 'entries', admin_url( 'options-general.php?page=visual-form-builder' ) ); ?>">Entries</a></li>
533
+ </ul>
534
+
535
+ <?php
536
+ /* Display the Entries */
537
+ if ( isset( $_REQUEST['view'] ) && in_array( $_REQUEST['view'], array( 'entries' ) ) ) :
538
+
539
+ $entries_list = new VisualFormBuilder_Entries_List();
540
+ $entries_list->prepare_items();
541
+ ?>
542
+ <form id="entries-filter" method="post" action="">
543
+ <?php $entries_list->display(); ?>
544
+ </form>
545
+ <?php
546
+ /* Display the Forms */
547
+ else:
548
+ echo ( isset( $this->message ) ) ? $this->message : ''; ?>
549
  <div id="nav-menus-frame">
550
  <div id="menu-settings-column" class="metabox-holder<?php echo ( empty( $form_nav_selected_id ) ) ? ' metabox-holder-disabled' : ''; ?>">
551
  <div id="side-sortables" class="metabox-holder">
626
  $form_subject = stripslashes( $form->form_email_subject );
627
  $form_email_from_name = stripslashes( $form->form_email_from_name );
628
  $form_email_from = stripslashes( $form->form_email_from);
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(
665
  </div>
666
  <div class="nav-tabs-arrow nav-tabs-arrow-right"><a>&raquo;</a></div>
667
  </div>
668
+
669
  <div class="menu-edit">
670
  <form method="post" id="visual-form-builder-update" action="">
671
  <input name="action" type="hidden" value="<?php echo $action; ?>" />
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>
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>
872
  </div>
873
  </div>
874
  <?php
875
+ endif;
876
  }
877
 
878
  /**
889
  ), $atts )
890
  );
891
 
892
+ /* Get form id. Allows use of [vfb id=1] or [vfb 1] */
893
  $form_id = ( isset( $id ) && !empty( $id ) ) ? $id : $atts[0];
894
 
 
 
 
 
 
 
 
 
 
895
  $open_fieldset = false;
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 */
903
+ $order = sanitize_sql_orderby( 'form_id DESC' );
904
+ $query = "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order";
905
+
906
+ $forms = $wpdb->get_results( $query );
907
+
908
+ /* Get fields */
909
+ $order_fields = sanitize_sql_orderby( 'field_sequence ASC' );
910
+ $query_fields = "SELECT * FROM $this->field_table_name WHERE form_id = $form_id ORDER BY $order_fields";
911
+
912
+ $fields = $wpdb->get_results( $query_fields );
913
+
914
  foreach ( $forms as $form ) :
915
 
916
  $output = '<form id="' . $form->form_key . '" class="visual-form-builder" method="post">
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':
949
  if ( !empty( $field->field_description ) )
950
  $output .= '<span><label>' . $field->field_description . '</label></span>';
951
 
952
+ $output .= '<textarea name="vfb-'. $field->field_key . '" id="vfb-'. $field->field_key . '" class="textarea ' . $field->field_size . $required . '"></textarea>';
953
 
954
  break;
955
 
957
  if ( !empty( $field->field_description ) )
958
  $output .= '<span><label>' . $field->field_description . '</label></span>';
959
 
960
+ $output .= '<select name="vfb-'. $field->field_key . '" id="vfb-'. $field->field_key . '" class="select ' . $field->field_size . $required . '">';
961
 
962
  $options = explode( ',', unserialize( $field->field_options ) );
963
 
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
  }
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
 
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">
1025
+ <input type="text" name="vfb-address-2" maxlength="150" id="vfb-address-2" class="text medium" />
1026
  <label>Address Line 2</label>
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>
1290
  case 'date':
1291
 
1292
  if ( !empty( $field->field_description ) )
1293
+ $output .= '<span><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 . '" /><label>' . $field->field_description . '</label></span>';
1294
  else
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
  }
1310
  <li>
1311
  <label class="desc">Please enter any two digits with <strong>no</strong> spaces (Example: 12) <span>*</span></label>
1312
  <div>
1313
+ <input type="text" name="vfb-secret" id="vfb-secret" class="text medium required digits" />
1314
  </div>
1315
  </li>
1316
  <div style="display:none;">
1317
  <li>
1318
+ <label for="vfb-spam">This box is for spam protection - <strong>please leave it blank</strong>:</label>
1319
  <div>
1320
+ <input name="vfb-spam" id="vfb-spam" />
1321
  </div>
1322
  </li>
1323
  </div>
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 */
1358
 
1359
  /* Query to get all forms */
1360
  $order = sanitize_sql_orderby( 'form_id DESC' );
1361
+ $query = "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order";
1362
 
1363
  /* Build our forms as an object */
1364
+ $forms = $wpdb->get_results( $query );
1365
 
1366
  /* Get sender and email details */
1367
  foreach ( $forms as $form ) {
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">';
1397
+
1398
  /* Loop through each form field and build the body of the message */
1399
  foreach ( $_POST as $key => $value ) {
1400
+ /* Remove prefix, dashes and lowercase */
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>';
1410
+ $fields[ $key ] = $value;
1411
+ }
1412
  }
1413
 
1414
+ /* Get the date/time format that is saved in the options table */
1415
+ $date_format = get_option('date_format');
1416
+ $time_format = get_option('time_format');
1417
+
1418
+ /* Setup our entries data */
1419
+ $entry = array(
1420
+ 'form_id' => $form_id,
1421
+ 'data' => serialize( $fields ),
1422
+ 'subject' => $form_subject,
1423
+ 'sender_name' => $form_from_name,
1424
+ 'sender_email' => $form_from,
1425
+ 'emails_to' => serialize( $form_to ),
1426
+ 'date_submitted' => date( $date_format . ' ' . $time_format),
1427
+ 'ip_address' => $_SERVER['REMOTE_ADDR']
1428
+ );
1429
+
1430
+ /* Insert this data into the entries table */
1431
+ $wpdb->insert( $this->entries_table_name, $entry );
1432
+
1433
  /* Close out the content */
1434
  $message .= '</table></body></html>';
1435
 
1442
  foreach ( $form_to as $email ) {
1443
  $mail_sent = wp_mail( $email, esc_html( $form_subject ), $message, $headers );
1444
  }
 
 
 
 
 
 
 
 
 
 
 
1445
  }
1446
  }
1447
  }