Visual Form Builder - Version 2.5

Version Description

Improved Export entries page, improved server side validation

Download this release

Release Info

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

Code changes from version 2.4.1 to 2.5

class-entries-list.php CHANGED
@@ -58,8 +58,8 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
58
 
59
  /* Build row actions */
60
  $actions = array(
61
- 'view' => sprintf( '<a href="?page=%s&view=%s&action=%s&entry=%s" id="%4$s" class="view-entry">View</a>', $_REQUEST['page'], $_REQUEST['view'], 'view', $item['entry_id'] ),
62
- 'delete' => sprintf( '<a href="?page=%s&view=%s&action=%s&entry=%s">Delete</a>', $_REQUEST['page'], $_REQUEST['view'], 'delete', $item['entry_id'] ),
63
  );
64
 
65
  return sprintf( '%1$s %2$s', $item['form'], $this->row_actions( $actions ) );
@@ -81,14 +81,14 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
81
  */
82
  function get_columns(){
83
  $columns = array(
84
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
85
- 'form' => __( 'Form' , 'visual-form-builder'),
86
- 'subject' => __( 'Email Subject' , 'visual-form-builder'),
87
- 'sender_name' => __( 'Sender Name' , 'visual-form-builder'),
88
- 'sender_email' => __( 'Sender Email' , 'visual-form-builder'),
89
- 'emails_to' => __( 'Emailed To' , 'visual-form-builder'),
90
- 'ip_address' => __( 'IP Address' , 'visual-form-builder'),
91
- 'date' => __( 'Date Submitted' , 'visual-form-builder')
92
  );
93
 
94
  return $columns;
@@ -154,11 +154,11 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
154
  */
155
  function get_sortable_columns() {
156
  $sortable_columns = array(
157
- 'form' => array( 'form', false ),
158
- 'subject' => array( 'subject', false ),
159
- 'sender_name' => array( 'sender_name', false ),
160
- 'sender_email' => array( 'sender_email', false ),
161
- 'date' => array( 'date', true )
162
  );
163
 
164
  return $sortable_columns;
@@ -172,9 +172,8 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
172
  */
173
  function get_bulk_actions() {
174
  $actions = array(
175
- 'delete' => __( 'Delete' , 'visual-form-builder'),
176
- 'export-all' => __( 'Export All' , 'visual-form-builder'),
177
- 'export-selected' => __( 'Export Selected' , 'visual-form-builder')
178
  );
179
 
180
  return $actions;
@@ -187,10 +186,6 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
187
  */
188
  function process_bulk_action() {
189
  switch( $this->current_action() ) {
190
- case 'export-all' :
191
- $this->export_entries();
192
- break;
193
-
194
  case 'export-selected' :
195
  $entry_id = ( isset( $_REQUEST['entry'] ) && is_array( $_REQUEST['entry'] ) ) ? $_REQUEST['entry'] : array( $_REQUEST['entry'] );
196
  $this->export_entries( $entry_id );
@@ -203,7 +198,7 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
203
 
204
  foreach ( $entry_id as $id ) {
205
  $id = absint( $id );
206
- $wpdb->query( "DELETE FROM $this->entries_table_name WHERE entries_id = $id" );
207
  }
208
  break;
209
  }
@@ -217,59 +212,47 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
217
  function export_entries( $selected = NULL ) {
218
  global $wpdb;
219
 
220
- /* Setup our query to accept selected entry IDs */
 
 
 
 
221
  if ( is_array( $selected ) && !empty( $selected ) )
222
  $selected = " WHERE entries.entries_id IN (" . implode( ',', $selected ) . ")";
223
 
224
  $entries = $wpdb->get_results( "SELECT entries.*, forms.form_title FROM $this->entries_table_name AS entries JOIN $this->form_table_name AS forms USING(form_id) $selected ORDER BY entries_id DESC" );
225
 
226
- /* If there's entries returned, do our CSV stuff */
 
 
 
 
 
 
 
 
227
  if ( $entries ) :
228
 
229
- /* Setup our default columns */
230
  $cols = array(
231
- 'entries_id' => array(
232
- 'header' => __( 'Entries ID' , 'visual-form-builder'),
233
- 'data' => array()
234
- ),
235
- 'form_title' => array(
236
- 'header' => __( 'Form' , 'visual-form-builder'),
237
- 'data' => array()
238
- ),
239
- 'date_submitted' => array(
240
- 'header' => __( 'Date Submitted' , 'visual-form-builder'),
241
- 'data' => array()
242
- ),
243
- 'ip_address' => array(
244
- 'header' => __( 'IP Address' , 'visual-form-builder'),
245
- 'data' => array()
246
- ),
247
- 'subject' => array(
248
- 'header' => __( 'Email Subject' , 'visual-form-builder'),
249
- 'data' => array()
250
- ),
251
- 'sender_name' => array(
252
- 'header' => __( 'Sender Name' , 'visual-form-builder'),
253
- 'data' => array()
254
- ),
255
- 'sender_email' => array(
256
- 'header' => __( 'Sender Email' , 'visual-form-builder'),
257
- 'data' => array()
258
- ),
259
- 'emails_to' => array(
260
- 'header' => __( 'Emailed To' , 'visual-form-builder'),
261
- 'data' => array()
262
- )
263
  );
264
 
265
- /* Initialize row index at 0 */
266
  $row = 0;
267
 
268
- /* Loop through all entries */
269
  foreach ( $entries as $entry ) {
270
- /* Loop through each entry and its fields */
271
  foreach ( $entry as $key => $value ) {
272
- /* Handle each column in the entries table */
273
  switch ( $key ) {
274
  case 'entries_id':
275
  case 'form_title':
@@ -286,37 +269,33 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
286
  break;
287
 
288
  case 'data':
289
- /* Unserialize value only if it was serialized */
290
  $fields = maybe_unserialize( $value );
291
 
292
- /* Loop through our submitted data */
293
- foreach ( $fields as $field_key => $field_value ) {
294
  if ( !is_array( $field_value ) ) {
295
 
296
- /* Replace quotes for the header */
297
  $header = str_replace( '"', '""', ucwords( $field_key ) );
298
 
299
- /* Replace all spaces for each form field name */
300
  $field_key = preg_replace( '/(\s)/i', '', $field_key );
301
 
302
- /* Find new field names and make a new column with a header */
303
- if ( !array_key_exists( $field_key, $cols ) ) {
304
- $cols[ $field_key ] = array(
305
- 'header' => $header,
306
- 'data' => array()
307
- );
308
- }
309
 
310
- /* Get rid of single quote entity */
311
  $field_value = str_replace( '&#039;', "'", $field_value );
312
 
313
- /* Load data, row by row */
314
  $cols[ $field_key ][ 'data' ][ $row ] = str_replace( '"', '""', stripslashes( html_entity_decode( $field_value ) ) );
315
  }
316
  else {
317
- /* Cast each array as an object */
318
  $obj = (object) $field_value;
319
-
320
  switch ( $obj->type ) {
321
  case 'fieldset' :
322
  case 'section' :
@@ -327,86 +306,75 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
327
  break;
328
 
329
  default :
330
- /* Replace quotes for the header */
331
  $header = str_replace( '"', '""', $obj->name );
332
-
333
- /* Find new field names and make a new column with a header */
334
- if ( !array_key_exists( $obj->name, $cols ) ) {
335
-
336
- $cols[$obj->name] = array(
337
- 'header' => $header,
338
- 'data' => array()
339
- );
340
- }
341
 
342
- /* Get rid of single quote entity */
 
 
 
 
 
 
 
343
  $obj->value = str_replace( '&#039;', "'", $obj->value );
344
 
345
- /* Load data, row by row */
346
- $cols[ $obj->name ][ 'data' ][ $row ] = str_replace( '"', '""', stripslashes( html_entity_decode( $obj->value ) ) );
347
 
348
  break;
349
- }
350
- }
351
- }
352
- break;
353
- }
354
-
355
- }
356
 
357
  $row++;
358
- }
359
 
360
- /* Setup our CSV vars */
361
  $csv_headers = NULL;
362
  $csv_rows = array();
363
 
364
- /* Loop through each column */
365
  foreach ( $cols as $data ) {
366
- /* End our header row, if needed */
367
  if ( $csv_headers )
368
  $csv_headers .= ',';
369
 
370
- /* Build our headers */
371
  $csv_headers .= "{$data['header']}";
372
 
373
- /* Loop through each row of data and add to our CSV */
374
  for ( $i = 0; $i < $row; $i++ ) {
375
- /* End our row of data, if needed */
376
  if ( array_key_exists( $i, $csv_rows ) && !empty( $csv_rows[ $i ] ) )
377
  $csv_rows[ $i ] .= ',';
378
  elseif ( !array_key_exists( $i, $csv_rows ) )
379
  $csv_rows[ $i ] = '';
380
 
381
- /* Add a starting quote for this row's data */
382
  $csv_rows[ $i ] .= '"';
383
 
384
- /* If there's data at this point, add it to the row */
385
  if ( array_key_exists( $i, $data[ 'data' ] ) )
386
  $csv_rows[ $i ] .= $data[ 'data' ][ $i ];
387
 
388
- /* Add a closing quote for this row's data */
389
  $csv_rows[ $i ] .= '"';
390
  }
391
  }
392
 
393
- /* Change our header so the browser spits out a CSV file to download */
394
- ob_start();
395
- header('Content-type: text/csv');
396
- header('Content-Disposition: attachment; filename="' . date( 'Y-m-d' ) . '-entries.csv"');
397
- ob_clean();
398
 
399
- /* Print headers for the CSV */
400
- echo $csv_headers . "\n";
401
-
402
- /* Print each row of data for the CSV */
403
  foreach ( $csv_rows as $row ) {
404
- echo $row . "\n";
405
  }
406
-
407
- die();
408
 
409
- endif;
410
  }
411
 
412
  /**
@@ -417,7 +385,7 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
417
  function extra_tablenav( $which ) {
418
  global $wpdb;
419
 
420
- $cols = $wpdb->get_results( "SELECT DISTINCT forms.form_title, forms.form_id FROM $this->form_table_name AS forms ORDER BY forms.form_title ASC" );
421
 
422
  /* Only display the dropdown on the top of the table */
423
  if ( 'top' == $which ) {
@@ -561,14 +529,14 @@ class VisualFormBuilder_Entries_List extends WP_List_Table {
561
  foreach ( $entries as $entry ) {
562
  $data[] =
563
  array(
564
- 'entry_id' => $entry->entries_id,
565
- 'form' => stripslashes( $entry->form_title ),
566
- 'subject' => stripslashes( $entry->subject ),
567
- 'sender_name' => stripslashes( $entry->sender_name ),
568
- 'sender_email' => stripslashes( $entry->sender_email ),
569
- 'emails_to' => implode( ',', unserialize( stripslashes( $entry->emails_to ) ) ),
570
- 'date' => date( "$date_format $time_format", strtotime( $entry->date_submitted ) ),
571
- 'ip_address' => $entry->ip_address
572
  );
573
  }
574
 
58
 
59
  /* Build row actions */
60
  $actions = array(
61
+ 'view' => sprintf( '<a href="?page=%s&view=%s&action=%s&entry=%s" id="%4$s" class="view-entry">View</a>', $_REQUEST['page'], $_REQUEST['view'], 'view', $item['entry_id'] ),
62
+ 'delete' => sprintf( '<a href="?page=%s&view=%s&action=%s&entry=%s">Delete</a>', $_REQUEST['page'], $_REQUEST['view'], 'delete', $item['entry_id'] ),
63
  );
64
 
65
  return sprintf( '%1$s %2$s', $item['form'], $this->row_actions( $actions ) );
81
  */
82
  function get_columns(){
83
  $columns = array(
84
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
85
+ 'form' => __( 'Form' , 'visual-form-builder'),
86
+ 'subject' => __( 'Email Subject' , 'visual-form-builder'),
87
+ 'sender_name' => __( 'Sender Name' , 'visual-form-builder'),
88
+ 'sender_email' => __( 'Sender Email' , 'visual-form-builder'),
89
+ 'emails_to' => __( 'Emailed To' , 'visual-form-builder'),
90
+ 'ip_address' => __( 'IP Address' , 'visual-form-builder'),
91
+ 'date' => __( 'Date Submitted' , 'visual-form-builder')
92
  );
93
 
94
  return $columns;
154
  */
155
  function get_sortable_columns() {
156
  $sortable_columns = array(
157
+ 'form' => array( 'form', false ),
158
+ 'subject' => array( 'subject', false ),
159
+ 'sender_name' => array( 'sender_name', false ),
160
+ 'sender_email' => array( 'sender_email', false ),
161
+ 'date' => array( 'date', true )
162
  );
163
 
164
  return $sortable_columns;
172
  */
173
  function get_bulk_actions() {
174
  $actions = array(
175
+ 'delete' => __( 'Delete' , 'visual-form-builder'),
176
+ 'export-selected' => __( 'Export Selected' , 'visual-form-builder')
 
177
  );
178
 
179
  return $actions;
186
  */
187
  function process_bulk_action() {
188
  switch( $this->current_action() ) {
 
 
 
 
189
  case 'export-selected' :
190
  $entry_id = ( isset( $_REQUEST['entry'] ) && is_array( $_REQUEST['entry'] ) ) ? $_REQUEST['entry'] : array( $_REQUEST['entry'] );
191
  $this->export_entries( $entry_id );
198
 
199
  foreach ( $entry_id as $id ) {
200
  $id = absint( $id );
201
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $this->entries_table_name WHERE entries_id = %d", $id ) );
202
  }
203
  break;
204
  }
212
  function export_entries( $selected = NULL ) {
213
  global $wpdb;
214
 
215
+ // If no entry has been checked, return an error
216
+ if ( empty( $selected ) )
217
+ return new WP_Error( 'VFB_selected_entries_error', __( 'You must select at least one entry to export.', 'visual-form-builder' ) );
218
+
219
+ // Setup our query to accept selected entry IDs
220
  if ( is_array( $selected ) && !empty( $selected ) )
221
  $selected = " WHERE entries.entries_id IN (" . implode( ',', $selected ) . ")";
222
 
223
  $entries = $wpdb->get_results( "SELECT entries.*, forms.form_title FROM $this->entries_table_name AS entries JOIN $this->form_table_name AS forms USING(form_id) $selected ORDER BY entries_id DESC" );
224
 
225
+ $sitename = sanitize_key( get_bloginfo( 'name' ) );
226
+ if ( ! empty($sitename) ) $sitename .= '.';
227
+ $filename = $sitename . 'vfb.selected-entries.' . date( 'Y-m-d' ) . '.csv';
228
+
229
+ header( 'Content-Description: File Transfer' );
230
+ header( 'Content-Disposition: attachment; filename=' . $filename );
231
+ header( 'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ), true );
232
+
233
+ // If there's entries returned, do our CSV stuff
234
  if ( $entries ) :
235
 
236
+ // Setup our default columns
237
  $cols = array(
238
+ 'entries_id' => array( 'header' => __( 'Entries ID' , 'visual-form-builder'), 'data' => array() ),
239
+ 'form_title' => array( 'header' => __( 'Form' , 'visual-form-builder'), 'data' => array() ),
240
+ 'date_submitted' => array( 'header' => __( 'Date Submitted' , 'visual-form-builder'), 'data' => array() ),
241
+ 'ip_address' => array( 'header' => __( 'IP Address' , 'visual-form-builder'), 'data' => array() ),
242
+ 'subject' => array( 'header' => __( 'Email Subject' , 'visual-form-builder'), 'data' => array() ),
243
+ 'sender_name' => array( 'header' => __( 'Sender Name' , 'visual-form-builder'), 'data' => array() ),
244
+ 'sender_email' => array( 'header' => __( 'Sender Email' , 'visual-form-builder'), 'data' => array() ),
245
+ 'emails_to' => array( 'header' => __( 'Emailed To' , 'visual-form-builder'), 'data' => array() )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  );
247
 
248
+ // Initialize row index at 0
249
  $row = 0;
250
 
251
+ // Loop through all entries
252
  foreach ( $entries as $entry ) {
253
+ // Loop through each entry and its fields
254
  foreach ( $entry as $key => $value ) {
255
+ // Handle each column in the entries table
256
  switch ( $key ) {
257
  case 'entries_id':
258
  case 'form_title':
269
  break;
270
 
271
  case 'data':
272
+ // Unserialize value only if it was serialized
273
  $fields = maybe_unserialize( $value );
274
 
275
+ // Loop through our submitted data
276
+ foreach ( $fields as $field_key => $field_value ) :
277
  if ( !is_array( $field_value ) ) {
278
 
279
+ // Replace quotes for the header
280
  $header = str_replace( '"', '""', ucwords( $field_key ) );
281
 
282
+ // Replace all spaces for each form field name
283
  $field_key = preg_replace( '/(\s)/i', '', $field_key );
284
 
285
+ // Find new field names and make a new column with a header
286
+ if ( !array_key_exists( $field_key, $cols ) )
287
+ $cols[ $field_key ] = array( 'header' => $header, 'data' => array() );
 
 
 
 
288
 
289
+ // Get rid of single quote entity
290
  $field_value = str_replace( '&#039;', "'", $field_value );
291
 
292
+ // Load data, row by row
293
  $cols[ $field_key ][ 'data' ][ $row ] = str_replace( '"', '""', stripslashes( html_entity_decode( $field_value ) ) );
294
  }
295
  else {
296
+ // Cast each array as an object
297
  $obj = (object) $field_value;
298
+
299
  switch ( $obj->type ) {
300
  case 'fieldset' :
301
  case 'section' :
306
  break;
307
 
308
  default :
309
+ // Replace quotes for the header
310
  $header = str_replace( '"', '""', $obj->name );
 
 
 
 
 
 
 
 
 
311
 
312
+ // Replace all spaces for each form field name
313
+ $field_key = preg_replace( '/(\s)/i', '', strtolower( $obj->name ) );
314
+
315
+ // Find new field names and make a new column with a header
316
+ if ( !array_key_exists( $field_key, $cols ) )
317
+ $cols[ $field_key ] = array( 'header' => $header, 'data' => array() );
318
+
319
+ // Get rid of single quote entity
320
  $obj->value = str_replace( '&#039;', "'", $obj->value );
321
 
322
+ // Load data, row by row
323
+ $cols[ $field_key ][ 'data' ][ $row ] = str_replace( '"', '""', stripslashes( html_entity_decode( $obj->value ) ) );
324
 
325
  break;
326
+ } //end switch
327
+ } //end if is_array check
328
+ endforeach; //end fields loop
329
+ break; //end entries switch
330
+ } //end entries data loop
331
+ } //end loop through entries
 
332
 
333
  $row++;
334
+ }//end if entries exists check
335
 
336
+ // Setup our CSV vars
337
  $csv_headers = NULL;
338
  $csv_rows = array();
339
 
340
+ // Loop through each column
341
  foreach ( $cols as $data ) {
342
+ // End our header row, if needed
343
  if ( $csv_headers )
344
  $csv_headers .= ',';
345
 
346
+ // Build our headers
347
  $csv_headers .= "{$data['header']}";
348
 
349
+ // Loop through each row of data and add to our CSV
350
  for ( $i = 0; $i < $row; $i++ ) {
351
+ // End our row of data, if needed
352
  if ( array_key_exists( $i, $csv_rows ) && !empty( $csv_rows[ $i ] ) )
353
  $csv_rows[ $i ] .= ',';
354
  elseif ( !array_key_exists( $i, $csv_rows ) )
355
  $csv_rows[ $i ] = '';
356
 
357
+ // Add a starting quote for this row's data
358
  $csv_rows[ $i ] .= '"';
359
 
360
+ // If there's data at this point, add it to the row
361
  if ( array_key_exists( $i, $data[ 'data' ] ) )
362
  $csv_rows[ $i ] .= $data[ 'data' ][ $i ];
363
 
364
+ // Add a closing quote for this row's data
365
  $csv_rows[ $i ] .= '"';
366
  }
367
  }
368
 
369
+ // Print headers for the CSV
370
+ echo "$csv_headers\n";
 
 
 
371
 
372
+ // Print each row of data for the CSV
 
 
 
373
  foreach ( $csv_rows as $row ) {
374
+ echo "$row\n";
375
  }
 
 
376
 
377
+ endif;
378
  }
379
 
380
  /**
385
  function extra_tablenav( $which ) {
386
  global $wpdb;
387
 
388
+ $cols = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT forms.form_title, forms.form_id FROM $this->form_table_name AS forms ORDER BY forms.form_title ASC" ) );
389
 
390
  /* Only display the dropdown on the top of the table */
391
  if ( 'top' == $which ) {
529
  foreach ( $entries as $entry ) {
530
  $data[] =
531
  array(
532
+ 'entry_id' => $entry->entries_id,
533
+ 'form' => stripslashes( $entry->form_title ),
534
+ 'subject' => stripslashes( $entry->subject ),
535
+ 'sender_name' => stripslashes( $entry->sender_name ),
536
+ 'sender_email' => stripslashes( $entry->sender_email ),
537
+ 'emails_to' => implode( ',', unserialize( stripslashes( $entry->emails_to ) ) ),
538
+ 'date' => date( "$date_format $time_format", strtotime( $entry->date_submitted ) ),
539
+ 'ip_address' => $entry->ip_address
540
  );
541
  }
542
 
class-export.php ADDED
@@ -0,0 +1,399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class that builds our Entries table
4
+ *
5
+ * @since 1.2
6
+ */
7
+ class VisualFormBuilder_Export {
8
+
9
+ protected $export_version = 2.5;
10
+
11
+ public function __construct(){
12
+ global $wpdb;
13
+
14
+ // Setup global database table names
15
+ $this->field_table_name = $wpdb->prefix . 'visual_form_builder_fields';
16
+ $this->form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
17
+ $this->entries_table_name = $wpdb->prefix . 'visual_form_builder_entries';
18
+
19
+ add_action( 'admin_init', array( &$this, 'display' ) );
20
+
21
+ $this->process_export_action();
22
+ }
23
+
24
+ /**
25
+ * Display the export form
26
+ *
27
+ * @since 1.7
28
+ *
29
+ */
30
+ public function display(){
31
+ global $wpdb;
32
+
33
+ // Query to get all forms
34
+ $order = sanitize_sql_orderby( 'form_id ASC' );
35
+ $where = apply_filters( 'vfb_pre_get_forms_export', '' );
36
+ $forms = $wpdb->get_results( "SELECT * FROM $this->form_table_name WHERE 1=1 $where ORDER BY $order" );
37
+
38
+ ?>
39
+ <form method="post" id="vfb-export">
40
+ <p>Backup and save some or all of your Visual Form Builder Pro data.</p>
41
+ <p>Once you've saved the file, you will be able to import Visual Form Builder data from this site into another site.</p>
42
+ <h3>Choose what to export</h3>
43
+
44
+ <p><label><input type="radio" name="content" value="all" disabled="disabled" /> <?php _e( 'All data', 'visual-form-builder-pro' ); ?></label></p>
45
+ <p class="description">This will contain all of your forms, fields, entries, and email design settings.<br><strong>*Only available in Visual Form Builder Pro*</strong></p>
46
+
47
+ <p><label><input type="radio" name="content" value="forms" disabled="disabled" /> <?php _e( 'Forms', 'visual-form-builder-pro' ); ?></label></p>
48
+ <p class="description">This will contain all of your forms, fields, and email design settings.<br><strong>*Only available in Visual Form Builder Pro*</strong></p>
49
+
50
+ <p><label><input type="radio" name="content" value="entries" checked="checked" /> <?php _e( 'Entries', 'visual-form-builder-pro' ); ?></label></p>
51
+
52
+ <ul id="entries-filters" class="vfb-export-filters">
53
+ <li><p class="description">This will export entries in either a .csv or .xls and cannot be used with the Import. If you need to import entries on another site, please use the All data option above.</p></li>
54
+ <li>
55
+ <label for="format">Format:</label>
56
+ <select name="format">
57
+ <option value="csv" selected="selected"><?php _e( 'Comma Separated (.csv)', 'visual-form-builder-pro' ); ?></option>
58
+ <option value="xls" disabled="disabled"><?php _e( 'Excel (.xls) - Pro only', 'visual-form-builder-pro' ); ?></option>
59
+ </select>
60
+ </li>
61
+ <li>
62
+ <label for="form_id">Form:</label>
63
+ <select name="form_id">
64
+ <!--<option value="0">All</option>-->
65
+ <?php
66
+ foreach ( $forms as $form ) {
67
+ echo '<option value="' . $form->form_id . '" id="' . $form->form_key . '">' . stripslashes( $form->form_title ) . '</option>';
68
+ }
69
+ ?>
70
+ </select>
71
+ </li>
72
+ <li>
73
+ <label>Date Range:</label>
74
+ <select name="entries_start_date">
75
+ <option value="0">Start Date</option>
76
+ <?php $this->months_dropdown(); ?>
77
+ </select>
78
+ <select name="entries_end_date">
79
+ <option value="0">End Date</option>
80
+ <?php $this->months_dropdown(); ?>
81
+ </select>
82
+ </li>
83
+ </ul>
84
+
85
+ <input type="submit" value="Download Export File" class="button" id="Submit" name="Submit">
86
+ </form>
87
+ <?php
88
+ }
89
+
90
+
91
+ /**
92
+ * Build the entries export array
93
+ *
94
+ * @since 1.7
95
+ *
96
+ * @param array $args Filters defining what should be included in the export
97
+ */
98
+ public function export_entries( $args = array() ) {
99
+ global $wpdb;
100
+
101
+ $defaults = array(
102
+ 'content' => 'entries',
103
+ 'format' => 'csv',
104
+ 'form_id' => 0,
105
+ 'start_date' => false,
106
+ 'end_date' => false,
107
+ );
108
+ $args = wp_parse_args( $args, $defaults );
109
+
110
+ $where = '';
111
+
112
+ if ( 'entries' == $args['content'] ) {
113
+ if ( 0 !== $args['form_id'] )
114
+ $where .= $wpdb->prepare( " AND form_id = %d", $args['form_id'] );
115
+
116
+ if ( $args['start_date'] )
117
+ $where .= $wpdb->prepare( " AND date_submitted >= %s", date( 'Y-m-d', strtotime( $args['start_date'] ) ) );
118
+
119
+ if ( $args['end_date'] )
120
+ $where .= $wpdb->prepare( " AND date_submitted < %s", date( 'Y-m-d', strtotime('+1 month', strtotime( $args['end_date'] ) ) ) );
121
+ }
122
+
123
+ $entries = $wpdb->get_results( "SELECT * FROM $this->entries_table_name WHERE 1=1 $where" );
124
+ $form_key = $wpdb->get_var( $wpdb->prepare( "SELECT form_key, form_title FROM $this->form_table_name WHERE form_id = %d", $args['form_id'] ) );
125
+ $form_title = $wpdb->get_var( null, 1 );
126
+
127
+ $sitename = sanitize_key( get_bloginfo( 'name' ) );
128
+ if ( ! empty($sitename) ) $sitename .= '.';
129
+ $filename = $sitename . 'vfb.' . "$form_key." . date( 'Y-m-d' ) . ".{$args['format']}";
130
+
131
+ $content_type = ( 'csv' == $args['format'] ) ? 'text/csv' : 'application/vnd.ms-excel';
132
+
133
+ header( 'Content-Description: File Transfer' );
134
+ header( 'Content-Disposition: attachment; filename=' . $filename );
135
+ header( "Content-Type: $content_type; charset=" . get_option( 'blog_charset' ), true );
136
+
137
+ // If there's entries returned, do our CSV stuff
138
+ if ( $entries ) :
139
+
140
+ // Setup our default columns
141
+ $cols = array(
142
+ 'entries_id' => array( 'header' => __( 'Entries ID' , 'visual-form-builder'), 'data' => array() ),
143
+ 'date_submitted' => array( 'header' => __( 'Date Submitted' , 'visual-form-builder'), 'data' => array() ),
144
+ 'ip_address' => array( 'header' => __( 'IP Address' , 'visual-form-builder'), 'data' => array() ),
145
+ 'subject' => array( 'header' => __( 'Email Subject' , 'visual-form-builder'), 'data' => array() ),
146
+ 'sender_name' => array( 'header' => __( 'Sender Name' , 'visual-form-builder'), 'data' => array() ),
147
+ 'sender_email' => array( 'header' => __( 'Sender Email' , 'visual-form-builder'), 'data' => array() ),
148
+ 'emails_to' => array( 'header' => __( 'Emailed To' , 'visual-form-builder'), 'data' => array() )
149
+ );
150
+
151
+ // Initialize row index at 0
152
+ $row = 0;
153
+
154
+ // Loop through all entries
155
+ foreach ( $entries as $entry ) {
156
+ // Loop through each entry and its fields
157
+ foreach ( $entry as $key => $value ) {
158
+ // Handle each column in the entries table
159
+ switch ( $key ) {
160
+ case 'entries_id':
161
+ case 'date_submitted':
162
+ case 'ip_address':
163
+ case 'subject':
164
+ case 'sender_name':
165
+ case 'sender_email':
166
+ $cols[ $key ][ 'data' ][ $row ] = $value;
167
+ break;
168
+
169
+ case 'emails_to':
170
+ $cols[ $key ][ 'data' ][ $row ] = implode( ',', maybe_unserialize( $value ) );
171
+ break;
172
+
173
+ case 'data':
174
+ // Unserialize value only if it was serialized
175
+ $fields = maybe_unserialize( $value );
176
+
177
+ // Loop through our submitted data
178
+ foreach ( $fields as $field_key => $field_value ) :
179
+ if ( !is_array( $field_value ) ) {
180
+
181
+ // Replace quotes for the header
182
+ $header = str_replace( '"', '""', ucwords( $field_key ) );
183
+
184
+ // Replace all spaces for each form field name
185
+ $field_key = preg_replace( '/(\s)/i', '', $field_key );
186
+
187
+ // Find new field names and make a new column with a header
188
+ if ( !array_key_exists( $field_key, $cols ) )
189
+ $cols[ $field_key ] = array( 'header' => $header, 'data' => array() );
190
+
191
+ // Get rid of single quote entity
192
+ $field_value = str_replace( '&#039;', "'", $field_value );
193
+
194
+ // Load data, row by row
195
+ $cols[ $field_key ][ 'data' ][ $row ] = str_replace( '"', '""', stripslashes( html_entity_decode( $field_value ) ) );
196
+ }
197
+ else {
198
+ // Cast each array as an object
199
+ $obj = (object) $field_value;
200
+
201
+ switch ( $obj->type ) {
202
+ case 'fieldset' :
203
+ case 'section' :
204
+ case 'instructions' :
205
+ case 'page-break' :
206
+ case 'verification' :
207
+ case 'secret' :
208
+ case 'submit' :
209
+ break;
210
+
211
+ default :
212
+ // Replace quotes for the header
213
+ $header = str_replace( '"', '""', $obj->name );
214
+
215
+ // Replace all spaces for each form field name
216
+ $field_key = preg_replace( '/(\s)/i', '', strtolower( $obj->name ) );
217
+
218
+ // Find new field names and make a new column with a header
219
+ if ( !array_key_exists( $field_key, $cols ) )
220
+ $cols[ $field_key ] = array( 'header' => $header, 'data' => array() );
221
+
222
+ // Get rid of single quote entity
223
+ $obj->value = str_replace( '&#039;', "'", $obj->value );
224
+
225
+ // Load data, row by row
226
+ $cols[ $field_key ][ 'data' ][ $row ] = str_replace( '"', '""', stripslashes( html_entity_decode( $obj->value ) ) );
227
+
228
+ break;
229
+ } //end switch
230
+ } //end if is_array check
231
+ endforeach; //end fields loop
232
+ break; //end entries switch
233
+ } //end entries data loop
234
+ } //end loop through entries
235
+
236
+ $row++;
237
+ }//end if entries exists check
238
+
239
+ $this->csv( $cols, $row );
240
+
241
+ endif;
242
+ }
243
+
244
+ /**
245
+ * Return the entries data formatted for CSV
246
+ *
247
+ * @since 1.7
248
+ *
249
+ * @param array $cols The multidimensional array of entries data
250
+ * @param int $row The row index
251
+ */
252
+ public function csv( $cols, $row ) {
253
+ // Setup our CSV vars
254
+ $csv_headers = NULL;
255
+ $csv_rows = array();
256
+
257
+ // Loop through each column
258
+ foreach ( $cols as $data ) {
259
+ // End our header row, if needed
260
+ if ( $csv_headers )
261
+ $csv_headers .= ',';
262
+
263
+ // Build our headers
264
+ $csv_headers .= "{$data['header']}";
265
+
266
+ // Loop through each row of data and add to our CSV
267
+ for ( $i = 0; $i < $row; $i++ ) {
268
+ // End our row of data, if needed
269
+ if ( array_key_exists( $i, $csv_rows ) && !empty( $csv_rows[ $i ] ) )
270
+ $csv_rows[ $i ] .= ',';
271
+ elseif ( !array_key_exists( $i, $csv_rows ) )
272
+ $csv_rows[ $i ] = '';
273
+
274
+ // Add a starting quote for this row's data
275
+ $csv_rows[ $i ] .= '"';
276
+
277
+ // If there's data at this point, add it to the row
278
+ if ( array_key_exists( $i, $data[ 'data' ] ) )
279
+ $csv_rows[ $i ] .= $data[ 'data' ][ $i ];
280
+
281
+ // Add a closing quote for this row's data
282
+ $csv_rows[ $i ] .= '"';
283
+ }
284
+ }
285
+
286
+ // Print headers for the CSV
287
+ echo "$csv_headers\n";
288
+
289
+ // Print each row of data for the CSV
290
+ foreach ( $csv_rows as $row ) {
291
+ echo "$row\n";
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Return the selected export type
297
+ *
298
+ * @since 1.7
299
+ *
300
+ * @return string|bool The type of export
301
+ */
302
+ public function export_action() {
303
+ if ( isset( $_REQUEST['content'] ) )
304
+ return $_REQUEST['content'];
305
+
306
+ return false;
307
+ }
308
+
309
+ /**
310
+ * Determine which export process to run
311
+ *
312
+ * @since 1.7
313
+ *
314
+ */
315
+ public function process_export_action() {
316
+
317
+ $args = array();
318
+
319
+ if ( !isset( $_REQUEST['content'] ) || 'entries' == $_REQUEST['content'] ) {
320
+ $args['content'] = 'entries';
321
+
322
+ $args['format'] = 'csv';
323
+
324
+ if ( isset( $_REQUEST['form_id'] ) )
325
+ $args['form_id'] = (int) $_REQUEST['form_id'];
326
+
327
+ if ( isset( $_REQUEST['entries_start_date'] ) || isset( $_REQUEST['entries_end_date'] ) ) {
328
+ $args['start_date'] = $_REQUEST['entries_start_date'];
329
+ $args['end_date'] = $_REQUEST['entries_end_date'];
330
+ }
331
+ }
332
+
333
+ switch( $this->export_action() ) {
334
+ case 'entries' :
335
+ $this->export_entries( $args );
336
+ die();
337
+ break;
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Wrap given string in XML CDATA tag.
343
+ *
344
+ * @since 1.7
345
+ *
346
+ * @param string $str String to wrap in XML CDATA tag.
347
+ * @return string
348
+ */
349
+ function cdata( $str ) {
350
+ if ( seems_utf8( $str ) == false )
351
+ $str = utf8_encode( $str );
352
+
353
+ $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
354
+
355
+ return $str;
356
+ }
357
+
358
+ /**
359
+ * Display Year/Month filter
360
+ *
361
+ * @since 1.7
362
+ */
363
+ public function months_dropdown() {
364
+ global $wpdb, $wp_locale;
365
+
366
+ $where = apply_filters( 'vfb_pre_get_entries', '' );
367
+
368
+ $months = $wpdb->get_results( $wpdb->prepare( "
369
+ SELECT DISTINCT YEAR( forms.date_submitted ) AS year, MONTH( forms.date_submitted ) AS month
370
+ FROM $this->entries_table_name AS forms
371
+ WHERE 1=1 $where
372
+ ORDER BY forms.date_submitted DESC
373
+ " ) );
374
+
375
+ $month_count = count( $months );
376
+
377
+ if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
378
+ return;
379
+
380
+ $m = isset( $_REQUEST['m'] ) ? (int) $_REQUEST['m'] : 0;
381
+ ?>
382
+ <?php
383
+ foreach ( $months as $arc_row ) {
384
+ if ( 0 == $arc_row->year )
385
+ continue;
386
+
387
+ $month = zeroise( $arc_row->month, 2 );
388
+ $year = $arc_row->year;
389
+
390
+ printf( "<option value='%s'>%s</option>\n",
391
+ esc_attr( $arc_row->year . '-' . $month ),
392
+ sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
393
+ );
394
+ }
395
+ ?>
396
+ <?php
397
+ }
398
+ }
399
+ ?>
css/nav-menu.css CHANGED
@@ -1 +1 @@
1
- html,body{min-width:950px}#nav-menus-frame{margin-left:300px}#wpbody-content #menu-settings-column{display:inline;width:281px;margin-left:-300px;clear:both;float:left;padding-top:24px}.no-js #wpbody-content #menu-settings-column{padding-top:31px}#menu-settings-column .inside{clear:both}.metabox-holder-disabled .postbox{opacity:.5;filter:alpha(opacity=50)}.metabox-holder-disabled .button-controls .select-all{display:none}#wpbody{position:relative}#menu-management-liquid{float:left;min-width:100%}#menu-management{position:relative;margin-right:20px;margin-top:-3px;width:100%}#menu-management .menu-edit{border:1px solid;-moz-border-radius:3px;-webkit-border-radius:3px;-khtml-border-radius:3px;border-radius:3px;margin-bottom:20px}#post-body{padding:10px;border-width:1px 0;border-style:solid}#nav-menu-header,#nav-menu-footer{padding:0 10px}#nav-menu-header{border-bottom:1px solid}#nav-menu-footer{border-top:1px solid}#post-body div.updated,#post-body div.error{margin:0}#vfb-entries-body-content{position:relative;float:none}#menu-management .menu-add-new abbr{font-weight:bold}#menu-management .nav-tabs-nav{margin:0 20px}#menu-management .nav-tabs-arrow{width:10px;padding:0 5px 4px;cursor:pointer;position:absolute;top:0;line-height:22px;font-size:18px;text-shadow:0 1px 0 #fff}#menu-management .nav-tabs-arrow-left{left:0}#menu-management .nav-tabs-arrow-right{right:0;text-align:right}#menu-management .nav-tabs-wrapper{width:100%;height:28px;margin-bottom:-1px;overflow:hidden}#menu-management .nav-tabs{padding-left:20px;padding-right:10px}.js #menu-management .nav-tabs{float:left;margin-left:0;margin-right:-400px}#menu-management .nav-tab{margin-bottom:0;font-size:14px;font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif}#select-nav-menu-container{text-align:right;padding:0 10px 3px 10px;margin-bottom:5px}#select-nav-menu{width:100px;display:inline}#menu-name-label{margin-top:-2px}#wpbody .open-label{display:block;float:left}#wpbody .open-label span{padding-right:10px}.js .input-with-default-title{font-style:italic}#menu-management .inside{padding:0 10px}.postbox .howto input{width:180px;float:right}.customlinkdiv .howto input{width:200px}#nav-menu-theme-locations .howto select{width:100%}#nav-menu-theme-locations .button-controls{text-align:right}.add-menu-item-view-all{height:400px}#menu-container .submit{margin:0 0 10px;padding:0}.meta-sep,.submitdelete,.submitcancel{display:block;float:left;font-size:12px;margin:4px 0;line-height:15px}.meta-sep{padding:0 2px}#cancel-save{text-decoration:underline;font-size:12px;margin-left:20px;margin-top:5px}.list-controls{float:left;margin-top:5px}.add-to-menu{float:right}.postbox img.waiting{display:none;vertical-align:middle}.button-controls{clear:both;margin:10px 0}.show-all,.hide-all{cursor:pointer}.hide-all{display:none}#menu-name{width:270px}#manage-menu .inside{padding:0}#available-links dt{display:block}#add-custom-link .howto{font-size:12px}#add-custom-link label span{display:block;float:left;margin-top:5px;padding-right:5px}.menu-item-textbox{width:180px}.howto span{margin-top:4px;display:block;float:left}.quick-search{width:190px}.list-wrap{display:none;clear:both;margin-bottom:10px}.list-container{max-height:200px;overflow-y:auto;padding:10px 10px 5px;border:1px solid;-moz-border-radius:3px}.postbox p.submit{margin-bottom:0}.list li{display:none;margin:0;margin-bottom:5px}.list li .menu-item-title{cursor:pointer;display:block}.list li .menu-item-title input{margin-right:3px;margin-top:-3px}#menu-container .inside{padding-bottom:10px}.menu{padding-top:1em}#menu-to-edit{padding:1em 0;width:465px}.menu ul{width:100%}.menu li{margin-bottom:0;position:relative;opacity:1.0}.menu-item-bar{clear:both;line-height:1.5em;position:relative;margin-top:13px}.menu-item-handle{border:1px solid #dfdfdf;position:relative;padding-left:10px;height:auto;width:400px;line-height:35px;text-shadow:0 1px 0 #fff;overflow:hidden;word-wrap:break-word;border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px}#menu-to-edit .menu-item-invalid .menu-item-handle{background-color:#f6c9cc;background-image:-ms-linear-gradient(bottom,#f6c9cc,#fdf8ff);background-image:-moz-linear-gradient(bottom,#f6c9cc,#fdf8ff);background-image:-o-linear-gradient(bottom,#f6c9cc,#fdf8ff);background-image:-webkit-gradient(linear,left bottom,left top,from(#f6c9cc),to(#fdf8ff));background-image:-webkit-linear-gradient(bottom,#f6c9cc,#fdf8ff);background-image:linear-gradient(bottom,#f6c9cc,#fdf8ff)}.menu-item-edit-active .menu-item-handle{-moz-border-radius:3px 3px 0 0;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-khtml-border-bottom-right-radius:0;-khtml-border-bottom-left-radius:0;border-bottom-right-radius:0;border-bottom-left-radius:0}.no-js .menu-item-edit-active .item-edit{display:none}.js .menu-item-handle{cursor:move}.menu li.deleting .menu-item-handle{background-image:none;text-shadow:0}.menu-item-handle .item-title{font-size:12px;font-weight:bold;padding:7px 0;line-height:20px;display:block;margin-right:13em}li.menu-item.ui-sortable-helper dl{margin-top:0}li.menu-item.ui-sortable-helper .menu-item-transport dl{margin-top:13px}.menu .sortable-placeholder{height:35px;min-height:35px;width:410px;margin-top:13px}.menu-item-depth-0{margin-left:0}.menu-item-depth-1{margin-left:30px}.menu-item-depth-2{margin-left:60px}.menu-item-depth-3{margin-left:90px}.menu-item-depth-4{margin-left:120px}.menu-item-depth-5{margin-left:150px}.menu-item-depth-6{margin-left:180px}.menu-item-depth-7{margin-left:210px}.menu-item-depth-8{margin-left:240px}.menu-item-depth-9{margin-left:270px}.menu-item-depth-10{margin-left:300px}.menu-item-depth-11{margin-left:330px}.menu-item-depth-0 .menu-item-transport{margin-left:0}.menu-item-depth-1 .menu-item-transport{margin-left:-30px}.menu-item-depth-2 .menu-item-transport{margin-left:-60px}.menu-item-depth-3 .menu-item-transport{margin-left:-90px}.menu-item-depth-4 .menu-item-transport{margin-left:-120px}.menu-item-depth-5 .menu-item-transport{margin-left:-150px}.menu-item-depth-6 .menu-item-transport{margin-left:-180px}.menu-item-depth-7 .menu-item-transport{margin-left:-210px}.menu-item-depth-8 .menu-item-transport{margin-left:-240px}.menu-item-depth-9 .menu-item-transport{margin-left:-270px}.menu-item-depth-10 .menu-item-transport{margin-left:-300px}.menu-item-depth-11 .menu-item-transport{margin-left:-330px}body.menu-max-depth-0{min-width:950px!important}body.menu-max-depth-1{min-width:980px!important}body.menu-max-depth-2{min-width:1010px!important}body.menu-max-depth-3{min-width:1040px!important}body.menu-max-depth-4{min-width:1070px!important}body.menu-max-depth-5{min-width:1100px!important}body.menu-max-depth-6{min-width:1130px!important}body.menu-max-depth-7{min-width:1160px!important}body.menu-max-depth-8{min-width:1190px!important}body.menu-max-depth-9{min-width:1220px!important}body.menu-max-depth-10{min-width:1250px!important}body.menu-max-depth-11{min-width:1280px!important}.item-type{font-size:12px;padding-right:10px}.item-controls{font-size:12px;position:absolute;right:20px;top:0}.item-controls a{text-decoration:none}.item-controls a:hover{cursor:pointer}.item-controls .item-order{padding-right:10px}.item-controls .item-order a{font-weight:bold}body.js .item-order{display:none}.item-edit{position:absolute;right:-20px;top:0;display:block;width:30px;height:36px;overflow:hidden;text-indent:-999em;background:url("arrows.png") no-repeat scroll 8px 10px transparent}.item-edit:hover{background:url("arrows.png") no-repeat scroll 8px 10px transparent}.item-edit.opened{background:url("arrows.png") no-repeat scroll 8px -25px transparent}.item-edit.opened:hover{background:url("arrows.png") no-repeat scroll 8px -149px transparent}.menu-instructions-inactive{display:none}.menu-item-settings{display:block;width:400px;padding:10px 0 10px 10px;border:solid;border-width:0 1px 1px 1px;-moz-border-radius:0 0 3px 3px;-webkit-border-bottom-right-radius:3px;-webkit-border-bottom-left-radius:3px;-khtml-border-bottom-right-radius:3px;-khtml-border-bottom-left-radius:3px}.menu-item-edit-active .menu-item-settings{display:block}.menu-item-edit-inactive .menu-item-settings{display:none}.add-menu-item-pagelinks{margin:.5em auto;text-align:center}.link-to-original{display:block;margin:0 0 10px;padding:3px 5px 5px;font-size:12px;font-style:italic;border:1px solid;border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px}.link-to-original a{padding-left:4px;font-style:normal}.hidden-field{display:none}#form-settings .description-thin{margin:12px 10px 12px 0}.description-thin,.description-wide{margin-right:10px;float:left}.description-thin{width:190px;height:40px}.description-wide{width:390px}.menu-item-actions{padding-top:15px}#cancel-save{cursor:pointer}.major-publishing-actions{clear:both;padding:3px 0 5px}.major-publishing-actions .publishing-action{text-align:right;float:right;line-height:23px;margin:10px 0 1px}.major-publishing-actions .delete-action{vertical-align:middle;text-align:left;float:left;padding-right:15px;margin-top:5px}.menu-name-label span,.auto-add-pages label{font-size:12px;font-style:normal}.menu-name-label{margin-right:15px}.auto-add-pages input{margin-top:0}.auto-add-pages{margin-top:4px;float:left}.submitbox .submitcancel{border-bottom:1px solid;padding:1px 2px;text-decoration:none}.major-publishing-actions .form-invalid{padding-left:4px;margin-left:-4px;border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px}.has-right-sidebar .inner-sidebar{display:block}.inner-sidebar{clear:right;float:right;position:relative;width:281px}.has-right-sidebar #vfb-entries-body-content{margin-right:300px}.inner-side #side-sortables{min-height:300px;padding:0;width:280px}#menu-item-name-wrap:after,#menu-item-url-wrap:after,#menu-name-label:after,#menu-settings-column .inside:after,#nav-menus-frame:after,#vfb-entries-body-content:after,.button-controls:after,.major-publishing-actions:after,.menu-item-settings:after{clear:both;content:".";display:block;height:0;visibility:hidden}#nav-menus-frame,.button-controls,#menu-item-url-wrap,#menu-item-name-wrap{display:block}.option .widefat{width:325px;margin:0 6px 7px 0}.addOption,.deleteOption,.addEmail,.deleteEmail{background:url('sprite.png') -12px -650px no-repeat transparent;text-indent:-9999px;width:16px;height:16px;display:inline-block}.deleteOption,.deleteEmail{background-position:-12px -677px}.addEmail,.deleteEmail{margin-top:5px}.ui-state-disabled .menu-item-handle{cursor:default}.ui-state-disabled .menu-item-handle{background-image:-moz-linear-gradient(top,#fff 0,#bbb 100%);background-image:-o-linear-gradient(top,#fff 0,#bbb 100%);background-image:-webkit-gradient(linear,left top,left bottom,color-stop(0,#fff),color-stop(1,#bbb));background-image:linear-gradient(top,#fff 0,#bbb 100%)}
1
+ html,body{min-width:950px}#nav-menus-frame{margin-left:300px}#wpbody-content #menu-settings-column{display:inline;width:281px;margin-left:-300px;clear:both;float:left;padding-top:24px}.no-js #wpbody-content #menu-settings-column{padding-top:31px}#menu-settings-column .inside{clear:both}.metabox-holder-disabled .postbox{opacity:.5;filter:alpha(opacity=50)}.metabox-holder-disabled .button-controls .select-all{display:none}#wpbody{position:relative}.sub-navigation{float:none;font-size:12px;list-style:none;margin:8px 0 5px;padding:0;white-space:nowrap}.sub-navigation li{display:inline;margin:0;padding:0}.sub-navigation a{line-height:2;padding:.2em;text-decoration:none}.sub-navigation a.current{background:0;border:medium none;font-weight:bold;color:black}.sub-navigation a:hover{color:#d54e21}#menu-management-liquid{float:left;min-width:100%}#menu-management{position:relative;margin-right:20px;margin-top:-3px;width:100%}#menu-management .menu-edit{border:1px solid;-moz-border-radius:3px;-webkit-border-radius:3px;-khtml-border-radius:3px;border-radius:3px;margin-bottom:20px}#post-body{padding:10px;border-width:1px 0;border-style:solid}#nav-menu-header,#nav-menu-footer{padding:0 10px}#nav-menu-header{border-bottom:1px solid}#nav-menu-footer{border-top:1px solid}#post-body div.updated,#post-body div.error{margin:0}#vfb-entries-body-content{position:relative;float:none}#menu-management .menu-add-new abbr{font-weight:bold}#menu-management .nav-tabs-nav{margin:0 20px}#menu-management .nav-tabs-arrow{width:10px;padding:0 5px 4px;cursor:pointer;position:absolute;top:0;line-height:22px;font-size:18px;text-shadow:0 1px 0 #fff}#menu-management .nav-tabs-arrow-left{left:0}#menu-management .nav-tabs-arrow-right{right:0;text-align:right}#menu-management .nav-tabs-wrapper{width:100%;height:28px;margin-bottom:-1px;overflow:hidden}#menu-management .nav-tabs{padding-left:20px;padding-right:10px}.js #menu-management .nav-tabs{float:left;margin-left:0;margin-right:-400px}#menu-management .nav-tab{margin-bottom:0;font-size:14px;font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif}#select-nav-menu-container{text-align:right;padding:0 10px 3px 10px;margin-bottom:5px}#select-nav-menu{width:100px;display:inline}#menu-name-label{margin-top:-2px}#wpbody .open-label{display:block;float:left}#wpbody .open-label span{padding-right:10px}.js .input-with-default-title{font-style:italic}#menu-management .inside{padding:0 10px}.postbox .howto input{width:180px;float:right}.customlinkdiv .howto input{width:200px}#nav-menu-theme-locations .howto select{width:100%}#nav-menu-theme-locations .button-controls{text-align:right}.add-menu-item-view-all{height:400px}#menu-container .submit{margin:0 0 10px;padding:0}.meta-sep,.submitdelete,.submitcancel{display:block;float:left;font-size:12px;margin:4px 0;line-height:15px}.meta-sep{padding:0 2px}#cancel-save{text-decoration:underline;font-size:12px;margin-left:20px;margin-top:5px}.list-controls{float:left;margin-top:5px}.add-to-menu{float:right}.postbox img.waiting{display:none;vertical-align:middle}.button-controls{clear:both;margin:10px 0}.show-all,.hide-all{cursor:pointer}.hide-all{display:none}#menu-name{width:270px}#manage-menu .inside{padding:0}#available-links dt{display:block}#add-custom-link .howto{font-size:12px}#add-custom-link label span{display:block;float:left;margin-top:5px;padding-right:5px}.menu-item-textbox{width:180px}.howto span{margin-top:4px;display:block;float:left}.quick-search{width:190px}.list-wrap{display:none;clear:both;margin-bottom:10px}.list-container{max-height:200px;overflow-y:auto;padding:10px 10px 5px;border:1px solid;-moz-border-radius:3px}.postbox p.submit{margin-bottom:0}.list li{display:none;margin:0;margin-bottom:5px}.list li .menu-item-title{cursor:pointer;display:block}.list li .menu-item-title input{margin-right:3px;margin-top:-3px}#menu-container .inside{padding-bottom:10px}.menu{padding-top:1em}#menu-to-edit{padding:1em 0;width:465px}.menu ul{width:100%}.menu li{margin-bottom:0;position:relative;opacity:1.0}.menu-item-bar{clear:both;line-height:1.5em;position:relative;margin-top:13px}.menu-item-handle{border:1px solid #dfdfdf;position:relative;padding-left:10px;height:auto;width:400px;line-height:35px;text-shadow:0 1px 0 #fff;overflow:hidden;word-wrap:break-word;border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px}#menu-to-edit .menu-item-invalid .menu-item-handle{background-color:#f6c9cc;background-image:-ms-linear-gradient(bottom,#f6c9cc,#fdf8ff);background-image:-moz-linear-gradient(bottom,#f6c9cc,#fdf8ff);background-image:-o-linear-gradient(bottom,#f6c9cc,#fdf8ff);background-image:-webkit-gradient(linear,left bottom,left top,from(#f6c9cc),to(#fdf8ff));background-image:-webkit-linear-gradient(bottom,#f6c9cc,#fdf8ff);background-image:linear-gradient(bottom,#f6c9cc,#fdf8ff)}.menu-item-edit-active .menu-item-handle{-moz-border-radius:3px 3px 0 0;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-khtml-border-bottom-right-radius:0;-khtml-border-bottom-left-radius:0;border-bottom-right-radius:0;border-bottom-left-radius:0}.no-js .menu-item-edit-active .item-edit{display:none}.js .menu-item-handle{cursor:move}.menu li.deleting .menu-item-handle{background-image:none;text-shadow:0}.menu-item-handle .item-title{font-size:12px;font-weight:bold;padding:7px 0;line-height:20px;display:block;margin-right:13em}li.menu-item.ui-sortable-helper dl{margin-top:0}li.menu-item.ui-sortable-helper .menu-item-transport dl{margin-top:13px}.menu .sortable-placeholder{height:35px;min-height:35px;width:410px;margin-top:13px}.menu-item-depth-0{margin-left:0}.menu-item-depth-1{margin-left:30px}.menu-item-depth-2{margin-left:60px}.menu-item-depth-3{margin-left:90px}.menu-item-depth-4{margin-left:120px}.menu-item-depth-5{margin-left:150px}.menu-item-depth-6{margin-left:180px}.menu-item-depth-7{margin-left:210px}.menu-item-depth-8{margin-left:240px}.menu-item-depth-9{margin-left:270px}.menu-item-depth-10{margin-left:300px}.menu-item-depth-11{margin-left:330px}.menu-item-depth-0 .menu-item-transport{margin-left:0}.menu-item-depth-1 .menu-item-transport{margin-left:-30px}.menu-item-depth-2 .menu-item-transport{margin-left:-60px}.menu-item-depth-3 .menu-item-transport{margin-left:-90px}.menu-item-depth-4 .menu-item-transport{margin-left:-120px}.menu-item-depth-5 .menu-item-transport{margin-left:-150px}.menu-item-depth-6 .menu-item-transport{margin-left:-180px}.menu-item-depth-7 .menu-item-transport{margin-left:-210px}.menu-item-depth-8 .menu-item-transport{margin-left:-240px}.menu-item-depth-9 .menu-item-transport{margin-left:-270px}.menu-item-depth-10 .menu-item-transport{margin-left:-300px}.menu-item-depth-11 .menu-item-transport{margin-left:-330px}body.menu-max-depth-0{min-width:950px!important}body.menu-max-depth-1{min-width:980px!important}body.menu-max-depth-2{min-width:1010px!important}body.menu-max-depth-3{min-width:1040px!important}body.menu-max-depth-4{min-width:1070px!important}body.menu-max-depth-5{min-width:1100px!important}body.menu-max-depth-6{min-width:1130px!important}body.menu-max-depth-7{min-width:1160px!important}body.menu-max-depth-8{min-width:1190px!important}body.menu-max-depth-9{min-width:1220px!important}body.menu-max-depth-10{min-width:1250px!important}body.menu-max-depth-11{min-width:1280px!important}.item-type{font-size:12px;padding-right:10px}.item-controls{font-size:12px;position:absolute;right:20px;top:0}.item-controls a{text-decoration:none}.item-controls a:hover{cursor:pointer}.item-controls .item-order{padding-right:10px}.item-controls .item-order a{font-weight:bold}body.js .item-order{display:none}.item-edit{position:absolute;right:-20px;top:0;display:block;width:30px;height:36px;overflow:hidden;text-indent:-999em;background:url("arrows.png") no-repeat scroll 8px 10px transparent}.item-edit:hover{background:url("arrows.png") no-repeat scroll 8px 10px transparent}.item-edit.opened{background:url("arrows.png") no-repeat scroll 8px -25px transparent}.item-edit.opened:hover{background:url("arrows.png") no-repeat scroll 8px -149px transparent}.menu-instructions-inactive{display:none}.menu-item-settings{display:block;width:400px;padding:10px 0 10px 10px;border:solid;border-width:0 1px 1px 1px;-moz-border-radius:0 0 3px 3px;-webkit-border-bottom-right-radius:3px;-webkit-border-bottom-left-radius:3px;-khtml-border-bottom-right-radius:3px;-khtml-border-bottom-left-radius:3px}.menu-item-edit-active .menu-item-settings{display:block}.menu-item-edit-inactive .menu-item-settings{display:none}.add-menu-item-pagelinks{margin:.5em auto;text-align:center}.link-to-original{display:block;margin:0 0 10px;padding:3px 5px 5px;font-size:12px;font-style:italic;border:1px solid;border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px}.link-to-original a{padding-left:4px;font-style:normal}.hidden-field{display:none}#form-settings .description-thin{margin:12px 10px 12px 0}.description-thin,.description-wide{margin-right:10px;float:left}.description-thin{width:190px;height:40px}.description-wide{width:390px}.menu-item-actions{padding-top:15px}#cancel-save{cursor:pointer}.major-publishing-actions{clear:both;padding:3px 0 5px}.major-publishing-actions .publishing-action{text-align:right;float:right;line-height:23px;margin:10px 0 1px}.major-publishing-actions .delete-action{vertical-align:middle;text-align:left;float:left;padding-right:15px;margin-top:5px}.menu-name-label span,.auto-add-pages label{font-size:12px;font-style:normal}.menu-name-label{margin-right:15px}.auto-add-pages input{margin-top:0}.auto-add-pages{margin-top:4px;float:left}.submitbox .submitcancel{border-bottom:1px solid;padding:1px 2px;text-decoration:none}.major-publishing-actions .form-invalid{padding-left:4px;margin-left:-4px;border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px}.has-right-sidebar .inner-sidebar{display:block}.inner-sidebar{clear:right;float:right;position:relative;width:281px}.has-right-sidebar #vfb-entries-body-content{margin-right:300px}.inner-side #side-sortables{min-height:300px;padding:0;width:280px}#menu-item-name-wrap:after,#menu-item-url-wrap:after,#menu-name-label:after,#menu-settings-column .inside:after,#nav-menus-frame:after,#vfb-entries-body-content:after,.button-controls:after,.major-publishing-actions:after,.menu-item-settings:after{clear:both;content:".";display:block;height:0;visibility:hidden}#nav-menus-frame,.button-controls,#menu-item-url-wrap,#menu-item-name-wrap{display:block}.option .widefat{width:325px;margin:0 6px 7px 0}.addOption,.deleteOption,.addEmail,.deleteEmail{background:url('sprite.png') -12px -650px no-repeat transparent;text-indent:-9999px;width:16px;height:16px;display:inline-block}.deleteOption,.deleteEmail{background-position:-12px -677px}.addEmail,.deleteEmail{margin-top:5px}.ui-state-disabled .menu-item-handle{cursor:default}.ui-state-disabled .menu-item-handle{background-image:-moz-linear-gradient(top,#fff 0,#bbb 100%);background-image:-o-linear-gradient(top,#fff 0,#bbb 100%);background-image:-webkit-gradient(linear,left top,left bottom,color-stop(0,#fff),color-stop(1,#bbb));background-image:linear-gradient(top,#fff 0,#bbb 100%)}
readme.txt CHANGED
@@ -3,10 +3,11 @@ Contributors: mmuro
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=G87A9UN9CLPH4&lc=US&item_name=Visual%20Form%20Builder&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted
4
  Tags: form, forms, contact form, form to email, email form, email, input, validation, jquery, shortcode
5
  Requires at least: 3.3
6
- Tested up to: 3.4
7
- Stable tag: 2.4.1
 
8
 
9
- Build contact forms using a simple, clean interface. Forms include jQuery validation, a basic logic-based verification system, and entry tracking.
10
 
11
  == Description ==
12
 
@@ -108,7 +109,7 @@ Fieldsets, a way to group form fields, are an essential piece of this plugin's H
108
 
109
  = Can I use my own verification system such as a CAPTCHA? =
110
 
111
- At this time, there is no alternative to the built-in anti-spam system.
112
 
113
  = I'm not getting any emails! What's wrong? =
114
 
@@ -116,6 +117,39 @@ Some people have reported that after the form is submitted, no email is received
116
 
117
  Try using a plugin such as [WP Mail SMTP](http://wordpress.org/extend/plugins/wp-mail-smtp/) to correct the issue.
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  = How do I customize the CSS? =
120
 
121
  If you want to customize the appearance of the forms using your own CSS, here's how to do it:
@@ -139,9 +173,17 @@ To use the more complex features of the Date Picker plugin, [follow this tutoria
139
 
140
  The validation messages (ex: 'This field is required' or 'Please enter a valid email address') are generated by the jQuery Form Validation plugin.
141
 
142
- By default, these messages are in English. To translate them, you must create a JavaScript file that contains your translations and insert it into your theme.
 
 
 
 
 
 
143
 
144
- For instructions, [please go here](http://wordpress.org/support/topic/visual-form-builder-localization-problem?replies=8#post-2296212).
 
 
145
 
146
  = How do I export my entries to a CSV? =
147
 
@@ -149,9 +191,9 @@ There are two ways to export your entries to a CSV: Export All or Export Selecte
149
 
150
  To Export All:
151
 
152
- 1. Go to the Entries screen
153
- 1. Select the `Export All` option under the `Bulk Actions` dropdown
154
- 1. Click Apply and save the file
155
 
156
  To Export Selected:
157
 
@@ -169,6 +211,19 @@ To Export Selected:
169
 
170
  == Changelog ==
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  **Version 2.4.1**
173
 
174
  * Fix bug where misspelled variable caused email to not send
@@ -336,6 +391,9 @@ To Export Selected:
336
 
337
  == Upgrade Notice ==
338
 
 
 
 
339
  = 2.4.1 =
340
  Update spam bot check, fixed bug where label alignment option was not being saved
341
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=G87A9UN9CLPH4&lc=US&item_name=Visual%20Form%20Builder&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted
4
  Tags: form, forms, contact form, form to email, email form, email, input, validation, jquery, shortcode
5
  Requires at least: 3.3
6
+ Tested up to: 3.4.1
7
+ Stable tag: 2.5
8
+ License: GPLv2 or later
9
 
10
+ Build beautiful, fully functional forms in only a few minutes without writing PHP, CSS, or HTML.
11
 
12
  == Description ==
13
 
109
 
110
  = Can I use my own verification system such as a CAPTCHA? =
111
 
112
+ Because of the accessibility and usability problems inherent with a CAPTCHA system, Visual Form Builder will not be using such a system. Other methods of SPAM prevention will be explored to further enhance protection of your forms.
113
 
114
  = I'm not getting any emails! What's wrong? =
115
 
117
 
118
  Try using a plugin such as [WP Mail SMTP](http://wordpress.org/extend/plugins/wp-mail-smtp/) to correct the issue.
119
 
120
+ = Something in my theme isn't working anymore. What's wrong? =
121
+
122
+ Visual Form Builder is built using preferred WordPress coding standards. In many cases, some theme authors or plugin developers do not follow these standards and it causes conflicts with those that do follow the standards. The two most common issues have to do with either jQuery or CSS.
123
+
124
+ **jQuery conflicts**
125
+
126
+ Visual Form Builder requires at least jQuery version 1.7. Please make sure your theme is updated to use the latest version of jQuery.
127
+
128
+ **CSS conflicts**
129
+
130
+ If your forms do not look as expected, chances are there's some CSS in your theme conflicting with the built-in CSS of Visual Form Builder. Please follow the instructions on how to customize the CSS.
131
+
132
+ **Theme conflicts**
133
+
134
+ If you have confirmed that you are using the latest version of jQuery and can rule out CSS conflicts, there's probably something in your theme still causing problems.
135
+
136
+ 1. Activate the default Twenty Eleven theme
137
+ 1. Test your site to see if the issue still occurs
138
+
139
+ Still having problems even with Twenty Eleven running? If not, it's a conflict with your theme. Otherwise, it's probably a plugin conflict.
140
+
141
+ **Plugin conflicts**
142
+
143
+ Before following this process, make sure you have updated all plugins to their latest version (yes, even Visual Form Builder).
144
+
145
+ 1. Deactivate ALL plugins
146
+ 1. Activate Visual Form Builder
147
+ 1. Test your site to see if the issue still occurs
148
+
149
+ If everything works with only Visual Form Builder activated, you have a plugin conflict. Re-activate the plugins one by one until you find the problematic plugin(s).
150
+
151
+ If, after following the above procedures, you are still having problems please report this issue on the [Support Forum](http://wordpress.org/support/plugin/visual-form-builder).
152
+
153
  = How do I customize the CSS? =
154
 
155
  If you want to customize the appearance of the forms using your own CSS, here's how to do it:
173
 
174
  The validation messages (ex: 'This field is required' or 'Please enter a valid email address') are generated by the jQuery Form Validation plugin.
175
 
176
+ By default, these messages are in English. To translate them, you must create a JavaScript file that contains your translations and insert it into your theme.
177
+
178
+ Follow these instructions:
179
+
180
+ In your theme folder, create a JavaScript file. In this example, I'm using `myjs.js`. Add the following code to it and customize the language to what you need:
181
+
182
+ `jQuery(document).ready(function($) { $.extend($.validator.messages, { required: "Eingabe nötig", email: "Bitte eine gültige E-Mail-Adresse eingeben" }); });`
183
 
184
+ Now, in your functions.php file, add the following piece of code:
185
+
186
+ `wp_enqueue_script( 'my-visual-form-builder-validation', get_bloginfo( 'template_url' ) . '/myjs.js' , array( 'jquery', 'jquery-form-validation' ), '', true );`
187
 
188
  = How do I export my entries to a CSV? =
189
 
191
 
192
  To Export All:
193
 
194
+ 1. Go to the Export screen
195
+ 1. Select the form you would like to export and a date range, if needed
196
+ 1. Click Download Export File and save the file
197
 
198
  To Export Selected:
199
 
211
 
212
  == Changelog ==
213
 
214
+ **Version 2.5**
215
+
216
+ * Add new Export page for exporting all entries
217
+ * Add IDs to each form item on output
218
+ * Fix bug where extra quote was outputting on radio buttons
219
+ * Fix bug where form name override was not being updated when copying a form
220
+ * Fix bug where address formatting broke in the email
221
+ * Deprecate Export All from Entries Bulk Actions (to export, see new Export page)
222
+ * Update name attribute to remove field key in attempts to prevent POST limit from reaching max memory
223
+ * Update server side validation to check for required fields
224
+ * Update server side validation to denote which field is failing
225
+ * Minor admin CSS update
226
+
227
  **Version 2.4.1**
228
 
229
  * Fix bug where misspelled variable caused email to not send
391
 
392
  == Upgrade Notice ==
393
 
394
+ = 2.5 =
395
+ Improved Export entries page, improved server side validation
396
+
397
  = 2.4.1 =
398
  Update spam bot check, fixed bug where label alignment option was not being saved
399
 
screenshot-1.png DELETED
Binary file
screenshot-2.png DELETED
Binary file
screenshot-3.png DELETED
Binary file
screenshot-4.png DELETED
Binary file
visual-form-builder.php CHANGED
@@ -4,7 +4,7 @@ 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
  Author URI: http://matthewmuro.com
7
- Version: 2.4.1
8
  */
9
 
10
  /*
@@ -22,13 +22,17 @@ along with this program; if not, write to the Free Software
22
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
  */
24
 
 
 
 
25
  /* Instantiate new class */
26
  $visual_form_builder = new Visual_Form_Builder();
27
 
28
  /* Restrict Categories class */
29
  class Visual_Form_Builder{
30
 
31
- protected $vfb_db_version = '2.4.1';
 
32
 
33
  public $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" );
34
 
@@ -40,6 +44,9 @@ class Visual_Form_Builder{
40
  $this->form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
41
  $this->entries_table_name = $wpdb->prefix . 'visual_form_builder_entries';
42
 
 
 
 
43
  /* Make sure we are in the admin before proceeding. */
44
  if ( is_admin() ) {
45
  /* Build options and settings pages. */
@@ -51,7 +58,7 @@ class Visual_Form_Builder{
51
  add_action( 'wp_ajax_visual_form_builder_delete_field', array( &$this, 'delete_field_callback' ) );
52
  add_action( 'wp_ajax_visual_form_builder_form_settings', array( &$this, 'form_settings_callback' ) );
53
 
54
- add_action( 'load-settings_page_visual-form-builder', array( &$this, 'add_contextual_help' ) );
55
 
56
  /* Adds additional media button to insert form shortcode */
57
  add_action( 'media_buttons_context', array( &$this, 'add_media_button' ) );
@@ -62,10 +69,10 @@ class Visual_Form_Builder{
62
 
63
  /* Adds a Screen Options tab to the Entries screen */
64
  add_action( 'admin_init', array( &$this, 'save_screen_options' ) );
65
- add_filter( 'screen_settings', array( &$this, 'add_visual_form_builder_screen_options' ) );
66
 
67
  /* Adds a Settings link to the Plugins page */
68
- add_filter( 'plugin_action_links', array( &$this, 'visual_form_builder_plugin_action_links' ), 10, 2 );
69
 
70
  /* Add a database version to help with upgrades and run SQL install */
71
  if ( !get_option( 'vfb_db_version' ) ) {
@@ -80,8 +87,8 @@ class Visual_Form_Builder{
80
  }
81
 
82
  /* Load the jQuery and CSS we need if we're on our plugin page */
83
- add_action( 'load-settings_page_visual-form-builder', array( &$this, 'form_admin_scripts' ) );
84
- add_action( 'load-settings_page_visual-form-builder', array( &$this, 'form_admin_css' ) );
85
 
86
  /* Display update messages */
87
  add_action('admin_notices', array( &$this, 'admin_notices' ) );
@@ -94,9 +101,8 @@ class Visual_Form_Builder{
94
  add_action( 'init', array( &$this, 'email' ), 10 );
95
  add_action( 'init', array( &$this, 'confirmation' ), 12 );
96
 
97
- /* Add jQuery and CSS to the front-end */
98
- add_action( 'wp_head', array( &$this, 'form_css' ) );
99
- add_action( 'template_redirect', array( &$this, 'form_validation' ) );
100
  }
101
 
102
  /**
@@ -105,7 +111,7 @@ class Visual_Form_Builder{
105
  * @since 1.2
106
  */
107
  public function includes(){
108
- global $entries_list, $entries_detail;
109
 
110
  /* Load the Entries List class */
111
  require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-entries-list.php' );
@@ -114,7 +120,24 @@ class Visual_Form_Builder{
114
  /* Load the Entries Details class */
115
  require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-entries-detail.php' );
116
  $entries_detail = new VisualFormBuilder_Entries_Detail();
 
 
 
 
117
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  /**
120
  * Adds the media button image
@@ -122,9 +145,10 @@ class Visual_Form_Builder{
122
  * @since 2.3
123
  */
124
  public function add_media_button( $context ){
125
- $out = '<a href="#TB_inline?width=450&inlineId=vfb_form" class="thickbox" title="Add Visual Form Builder form"><img src="'. plugins_url( 'visual-form-builder/css/vfb_icon.png' ) . '" alt="Add Visual Form Builder form" /></a>';
 
126
 
127
- return $context . $out;
128
  }
129
 
130
  /**
@@ -141,7 +165,7 @@ class Visual_Form_Builder{
141
  $order = sanitize_sql_orderby( 'form_id ASC' );
142
 
143
  /* Build our forms as an object */
144
- $forms = $wpdb->get_results( "SELECT form_id, form_title FROM $this->form_table_name ORDER BY $order" );
145
  ?>
146
  <script type="text/javascript">
147
  jQuery(document).ready(function($) {
@@ -166,38 +190,13 @@ class Visual_Form_Builder{
166
  </div>
167
  <?php
168
  }
169
-
170
- /**
171
- * Display admin notices
172
- *
173
- * @since 1.0
174
- */
175
- public function admin_notices(){
176
- if ( isset( $_REQUEST['action'] ) ) {
177
- switch( $_REQUEST['action'] ) {
178
- case 'create_form' :
179
- echo __( '<div id="message" class="updated"><p>The form has been successfully created.</p></div>' , 'visual-form-builder');
180
- break;
181
- case 'update_form' :
182
- echo sprintf( __( '<div id="message" class="updated"><p>The <strong>%s</strong> form has been updated.</p></div>' , 'visual-form-builder'), stripslashes( $_REQUEST['form_title'] ) );
183
- break;
184
- case 'deleted' :
185
- echo __( '<div id="message" class="updated"><p>The form has been successfully deleted.</p></div>' , 'visual-form-builder');
186
- break;
187
- case 'copy_form' :
188
- echo __( '<div id="message" class="updated"><p>The form has been successfully duplicated.</p></div>' , 'visual-form-builder');
189
- break;
190
- }
191
-
192
- }
193
- }
194
-
195
  /**
196
  * Register contextual help. This is for the Help tab dropdown
197
  *
198
  * @since 1.0
199
  */
200
- public function add_contextual_help(){
201
  $screen = get_current_screen();
202
 
203
  $screen->add_help_tab( array(
@@ -284,7 +283,7 @@ class Visual_Form_Builder{
284
  *
285
  * @since 1.2
286
  */
287
- public function add_visual_form_builder_screen_options($current){
288
  global $current_screen;
289
 
290
  $options = get_option( 'visual-form-builder-screen-options' );
@@ -409,9 +408,9 @@ class Visual_Form_Builder{
409
  *
410
  * @since 1.0
411
  */
412
- public function form_admin_css() {
413
- wp_enqueue_style( 'visual-form-builder-style', plugins_url( 'visual-form-builder' ) . '/css/visual-form-builder-admin.css' );
414
- wp_enqueue_style( 'visual-form-builder-main', plugins_url( 'visual-form-builder' ) . '/css/nav-menu.css' );
415
  }
416
 
417
  /**
@@ -419,11 +418,11 @@ class Visual_Form_Builder{
419
  *
420
  * @since 1.0
421
  */
422
- public function form_admin_scripts() {
423
  wp_enqueue_script( 'jquery-ui-sortable' );
424
  wp_enqueue_script( 'jquery-form-validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js', array( 'jquery' ), '', true );
425
- wp_enqueue_script( 'form-elements-add', plugins_url( 'visual-form-builder' ) . '/js/visual-form-builder.js' , array( 'jquery', 'jquery-form-validation' ), '', true );
426
- wp_enqueue_script( 'nested-sortable', plugins_url( 'visual-form-builder' ) . '/js/jquery.ui.nestedSortable.js' , array( 'jquery', 'jquery-ui-sortable' ), '', true );
427
  }
428
 
429
  /**
@@ -431,12 +430,14 @@ class Visual_Form_Builder{
431
  *
432
  * @since 1.0
433
  */
434
- public function form_validation() {
 
 
 
435
  wp_enqueue_script( 'jquery-form-validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js', array( 'jquery' ), '', true );
436
- wp_enqueue_script( 'jquery-ui-core ', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js', array( 'jquery' ), '', true );
437
- wp_enqueue_script( 'visual-form-builder-validation', plugins_url( 'visual-form-builder' ) . '/js/visual-form-builder-validate.js' , array( 'jquery', 'jquery-form-validation' ), '', true );
438
- wp_enqueue_script( 'visual-form-builder-quicktags', plugins_url( 'visual-form-builder' ) . '/js/js_quicktags.js' );
439
- wp_enqueue_script( 'visual-form-builder-metadata', plugins_url( 'visual-form-builder' ) . '/js/jquery.metadata.js' , array( 'jquery', 'jquery-form-validation' ), '', true );
440
  }
441
 
442
  /**
@@ -444,36 +445,13 @@ class Visual_Form_Builder{
444
  *
445
  * @since 1.0
446
  */
447
- public function form_css() {
448
- echo apply_filters( 'visual-form-builder-css', '<link rel="stylesheet" href="' . plugins_url( 'css/visual-form-builder.css', __FILE__ ) . '" type="text/css" />' );
449
- echo apply_filters( 'vfb-date-picker-css', '<link media="all" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css" rel="stylesheet" />' );
450
- }
451
-
452
- /**
453
- * Add Settings link to Plugins page
454
- *
455
- * @since 1.8
456
- * @return $links array Links to add to plugin name
457
- */
458
- public function visual_form_builder_plugin_action_links( $links, $file ) {
459
- if ( $file == plugin_basename( __FILE__ ) )
460
- $links[] = '<a href="options-general.php?page=visual-form-builder">' . __( 'Settings' , 'visual-form-builder') . '</a>';
461
-
462
- return $links;
463
- }
464
-
465
- /**
466
- * Add options page to Settings menu
467
- *
468
- *
469
- * @since 1.0
470
- * @uses add_options_page() Creates a menu item under the Settings menu.
471
- */
472
- public function add_admin() {
473
- add_options_page( __( 'Visual Form Builder', 'visual-form-builder' ), __( 'Visual Form Builder', 'visual-form-builder' ), 'create_users', 'visual-form-builder', array( &$this, 'admin' ) );
474
  }
475
-
476
-
477
  /**
478
  * Actions to save, update, and delete forms/form fields
479
  *
@@ -569,24 +547,24 @@ class Visual_Form_Builder{
569
 
570
  case 'update_form' :
571
 
572
- $form_id = absint( $_REQUEST['form_id'] );
573
- $form_key = sanitize_title( $_REQUEST['form_title'], $form_id );
574
- $form_title = esc_html( $_REQUEST['form_title'] );
575
- $form_subject = esc_html( $_REQUEST['form_email_subject'] );
576
- $form_to = serialize( array_map( 'esc_html', $_REQUEST['form_email_to'] ) );
577
- $form_from = esc_html( $_REQUEST['form_email_from'] );
578
- $form_from_name = esc_html( $_REQUEST['form_email_from_name'] );
579
- $form_from_override = esc_html( $_REQUEST['form_email_from_override'] );
580
- $form_from_name_override = esc_html( $_REQUEST['form_email_from_name_override'] );
581
- $form_success_type = esc_html( $_REQUEST['form_success_type'] );
582
- $form_notification_setting = esc_html( $_REQUEST['form_notification_setting'] );
583
- $form_notification_email_name = esc_html( $_REQUEST['form_notification_email_name'] );
584
- $form_notification_email_from = esc_html( $_REQUEST['form_notification_email_from'] );
585
- $form_notification_email = esc_html( $_REQUEST['form_notification_email'] );
586
- $form_notification_subject = esc_html( $_REQUEST['form_notification_subject'] );
587
- $form_notification_message = wp_richedit_pre( $_REQUEST['form_notification_message'] );
588
- $form_notification_entry = esc_html( $_REQUEST['form_notification_entry'] );
589
- $form_label_alignment = esc_html( $_REQUEST['form_label_alignment'] );
590
 
591
  /* Add confirmation based on which type was selected */
592
  switch ( $form_success_type ) {
@@ -673,14 +651,16 @@ class Visual_Form_Builder{
673
  $field_sequence++;
674
  }
675
 
676
- /* Check if a submit field type exists for backwards compatibility upgrades */
677
- $is_verification = $wpdb->get_var( "SELECT field_id FROM $this->field_table_name WHERE field_type = 'verification' AND form_id = $form_id" );
678
- $is_secret = $wpdb->get_var( "SELECT field_id FROM $this->field_table_name WHERE field_type = 'secret' AND form_id = $form_id" );
679
- $is_submit = $wpdb->get_var( "SELECT field_id FROM $this->field_table_name WHERE field_type = 'submit' AND form_id = $form_id" );
680
 
681
  /* Decrement sequence */
682
  $field_sequence--;
683
 
 
 
684
  /* If this form doesn't have a verification field, add one */
685
  if ( $is_verification == NULL ) {
686
  /* Adjust the sequence */
@@ -756,7 +736,7 @@ class Visual_Form_Builder{
756
 
757
  check_admin_referer( 'delete-form-' . $id );
758
 
759
- /* Delete form and all fields */
760
  $wpdb->query( $wpdb->prepare( "DELETE FROM $this->form_table_name WHERE form_id = %d", $id ) );
761
  $wpdb->query( $wpdb->prepare( "DELETE FROM $this->field_table_name WHERE form_id = %d", $id ) );
762
 
@@ -771,37 +751,34 @@ class Visual_Form_Builder{
771
 
772
  check_admin_referer( 'copy-form-' . $id );
773
 
774
- /* Get all fields and data for the request form */
775
- $fields_query = "SELECT * FROM $this->field_table_name WHERE form_id = $id";
776
- $forms_query = "SELECT * FROM $this->form_table_name WHERE form_id = $id";
777
- $emails = "SELECT form_email_from_override, form_notification_email FROM $this->form_table_name WHERE form_id = $id";
778
-
779
- $fields = $wpdb->get_results( $fields_query );
780
- $forms = $wpdb->get_results( $forms_query );
781
- $override = $wpdb->get_var( $emails );
782
- $notify = $wpdb->get_var( $emails, 1 );
783
 
784
  /* Copy this form and force the initial title to denote a copy */
785
  foreach ( $forms as $form ) {
786
  $data = array(
787
- 'form_key' => sanitize_title( $form->form_key . ' copy' ),
788
- 'form_title' => $form->form_title . ' Copy',
789
- 'form_email_subject' => $form->form_email_subject,
790
- 'form_email_to' => $form->form_email_to,
791
- 'form_email_from' => $form->form_email_from,
792
- 'form_email_from_name' => $form->form_email_from_name,
793
- 'form_email_from_override' => $form->form_email_from_override,
794
  'form_email_from_name_override' => $form->form_email_from_name_override,
795
- 'form_success_type' => $form->form_success_type,
796
- 'form_success_message' => $form->form_success_message,
797
- 'form_notification_setting' => $form->form_notification_setting,
798
- 'form_notification_email_name' => $form->form_notification_email_name,
799
- 'form_notification_email_from' => $form->form_notification_email_from,
800
- 'form_notification_email' => $form->form_notification_email,
801
- 'form_notification_subject' => $form->form_notification_subject,
802
- 'form_notification_message' => $form->form_notification_message,
803
- 'form_notification_entry' => $form->form_notification_entry,
804
- 'form_label_alignment' => $form->form_label_alignment
805
  );
806
 
807
  $wpdb->insert( $this->form_table_name, $data );
@@ -837,6 +814,9 @@ class Visual_Form_Builder{
837
  if ( $override == $field->field_id )
838
  $wpdb->update( $this->form_table_name, array( 'form_email_from_override' => $wpdb->insert_id ), array( 'form_id' => $new_form_selected ) );
839
 
 
 
 
840
  if ( $notify == $field->field_id )
841
  $wpdb->update( $this->form_table_name, array( 'form_notification_email' => $wpdb->insert_id ), array( 'form_id' => $new_form_selected ) );
842
  }
@@ -887,7 +867,7 @@ class Visual_Form_Builder{
887
  global $wpdb;
888
 
889
  $data = array();
890
- $field_options = '';
891
 
892
  foreach ( $_REQUEST['data'] as $k ) {
893
  $data[ $k['name'] ] = $k['value'];
@@ -901,20 +881,30 @@ class Visual_Form_Builder{
901
 
902
  /* Set defaults for validation */
903
  switch ( $field_type ) {
 
 
 
 
 
 
904
  case 'email' :
905
  case 'url' :
906
  case 'phone' :
907
  $field_validation = $field_type;
908
  break;
 
909
  case 'currency' :
910
  $field_validation = 'number';
911
  break;
 
912
  case 'number' :
913
  $field_validation = 'digits';
914
  break;
 
915
  case 'time' :
916
  $field_validation = 'time-12';
917
  break;
 
918
  case 'file-upload' :
919
  $field_options = serialize( array( 'png|jpe?g|gif' ) );
920
  break;
@@ -923,7 +913,7 @@ class Visual_Form_Builder{
923
  check_ajax_referer( 'create-field-' . $data['form_id'], 'nonce' );
924
 
925
  /* Get the last row's sequence that isn't a Verification */
926
- $sequence_last_row = $wpdb->get_row( "SELECT field_sequence FROM $this->field_table_name WHERE form_id = $form_id AND field_type = 'verification' ORDER BY field_sequence DESC LIMIT 1" );
927
 
928
  /* If it's not the first for this form, add 1 */
929
  $field_sequence = ( !empty( $sequence_last_row ) ) ? $sequence_last_row->field_sequence : 0;
@@ -1038,7 +1028,7 @@ class Visual_Form_Builder{
1038
 
1039
  $field_where = ( isset( $field_id ) && !is_null( $field_id ) ) ? "AND field_id = $field_id" : '';
1040
  /* Display all fields for the selected form */
1041
- $fields = $wpdb->get_results( "SELECT * FROM $this->field_table_name WHERE form_id = $form_nav_selected_id $field_where ORDER BY field_sequence ASC" );
1042
 
1043
  $depth = 1;
1044
  $parent = $last = 0;
@@ -1125,14 +1115,6 @@ class Visual_Form_Builder{
1125
  <textarea name="field_description-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-description-<?php echo $field->field_id; ?>" /><?php echo stripslashes( $field->field_description ); ?></textarea>
1126
  </label>
1127
  </p>
1128
- <p class="description description-wide">
1129
- <label for="edit-form-item-css-<?php echo $field->field_id; ?>">
1130
- <?php _e( 'CSS Classes' , 'visual-form-builder'); ?>
1131
- <span class="vfb-tooltip" title="About CSS Classes" rel="For each field, you can insert your own CSS class names which can be used in your own stylesheets.">(?)</span>
1132
- <br />
1133
- <input type="text" value="<?php echo stripslashes( htmlspecialchars_decode( $field->field_css ) ); ?>" name="field_css-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-css-<?php echo $field->field_id; ?>" maxlength="255" />
1134
- </label>
1135
- </p>
1136
 
1137
  <?php else: ?>
1138
 
@@ -1387,13 +1369,49 @@ class Visual_Form_Builder{
1387
  echo '</li>';
1388
  }
1389
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1390
  /**
1391
  * Builds the options settings page
1392
  *
1393
  * @since 1.0
1394
  */
1395
  public function admin() {
1396
- global $wpdb, $entries_list, $entries_detail;
1397
 
1398
  /* Set variables depending on which tab is selected */
1399
  $form_nav_selected_id = ( isset( $_REQUEST['form'] ) ) ? $_REQUEST['form'] : '0';
@@ -1402,7 +1420,7 @@ class Visual_Form_Builder{
1402
 
1403
  /* Query to get all forms */
1404
  $order = sanitize_sql_orderby( 'form_id DESC' );
1405
- $forms = $wpdb->get_results( "SELECT * FROM $this->form_table_name ORDER BY $order" );
1406
 
1407
  /* Loop through each form and assign a form id, if any */
1408
  foreach ( $forms as $form ) {
@@ -1423,9 +1441,10 @@ class Visual_Form_Builder{
1423
  echo ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) && in_array( $_REQUEST['page'], array( 'visual-form-builder' ) ) ) ? '<span class="subtitle">' . sprintf( __( 'Search results for "%s"' , 'visual-form-builder'), $_REQUEST['s'] ) : '';
1424
  ?>
1425
  </h2>
1426
- <ul class="subsubsub">
1427
  <li><a<?php echo ( !isset( $_REQUEST['view'] ) ) ? ' class="current"' : ''; ?> href="<?php echo admin_url( 'options-general.php?page=visual-form-builder' ); ?>"><?php _e( 'Forms' , 'visual-form-builder'); ?></a> |</li>
1428
- <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' ) ); ?>"><?php _e( 'Entries' , 'visual-form-builder'); ?></a></li>
 
1429
  </ul>
1430
 
1431
  <?php
@@ -1444,8 +1463,9 @@ class Visual_Form_Builder{
1444
  ?>
1445
  </form>
1446
  <?php
1447
- endif;
1448
-
 
1449
  /* Display the Forms */
1450
  else:
1451
  echo ( isset( $this->message ) ) ? $this->message : ''; ?>
@@ -1463,7 +1483,7 @@ class Visual_Form_Builder{
1463
  /* Disable the left box if there's no active form selected */
1464
  $disabled = ( empty( $form_nav_selected_id ) ) ? ' disabled="disabled"' : '';
1465
  ?>
1466
- <div class="postbox"><!-- !Form Items -->
1467
  <h3 class="hndle"><span><?php _e( 'Form Items' , 'visual-form-builder'); ?></span></h3>
1468
  <div class="inside" >
1469
  <div class="taxonomydiv">
@@ -1492,7 +1512,7 @@ class Visual_Form_Builder{
1492
  </div>
1493
  </div>
1494
  </form>
1495
- <div class="postbox"><!-- !Form Output -->
1496
  <h3 class="hndle"><span><?php _e( 'Form Output' , 'visual-form-builder'); ?></span></h3>
1497
  <div class="inside">
1498
  <div id="customlinkdiv" class="customlinkdiv">
@@ -1514,9 +1534,9 @@ class Visual_Form_Builder{
1514
  <div id="menu-management-liquid">
1515
  <div id="menu-management">
1516
  <div class="nav-tabs-nav">
1517
- <div class="nav-tabs-arrow nav-tabs-arrow-left"><a>&laquo;</a></div><!-- !Form Tab Nav - Left Arrow -->
1518
  <div class="nav-tabs-wrapper">
1519
- <div class="nav-tabs"><!-- !Form Tabs -->
1520
  <?php
1521
  /* Loop through each for and build the tabs */
1522
  foreach ( $forms as $form ) {
@@ -1545,10 +1565,10 @@ class Visual_Form_Builder{
1545
  $form_label_alignment = stripslashes( $form->form_label_alignment );
1546
 
1547
  /* Only show required text fields for the sender name override */
1548
- $senders = $wpdb->get_results( "SELECT * FROM $this->field_table_name WHERE form_id = $form_nav_selected_id AND field_type='text' AND field_validation = '' AND field_required = 'yes'" );
1549
 
1550
  /* Only show required email fields for the email override */
1551
- $emails = $wpdb->get_results( "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')" );
1552
 
1553
  else :
1554
  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>';
@@ -1565,7 +1585,7 @@ class Visual_Form_Builder{
1565
  <?php endif; ?>
1566
  </div>
1567
  </div>
1568
- <div class="nav-tabs-arrow nav-tabs-arrow-right"><a>&raquo;</a></div><!-- !Form Tab Nav - Right Arrow -->
1569
  </div>
1570
 
1571
  <div class="menu-edit">
@@ -1621,10 +1641,10 @@ class Visual_Form_Builder{
1621
  </div>
1622
 
1623
  <div id="form-settings" class="<?php echo $opened_tab; ?>">
1624
- <!-- !General settings section -->
1625
  <a href="#general-settings" class="settings-links<?php echo ( $settings_accordion == 'general-settings' ) ? ' on' : ''; ?>">1. General<span class="arrow"></span></a>
1626
  <div id="general-settings" class="form-details<?php echo ( $settings_accordion == 'general-settings' ) ? ' on' : ''; ?>">
1627
- <!-- !Label Alignment -->
1628
  <p class="description description-wide">
1629
  <label for="form-label-alignment">
1630
  <?php _e( 'Label Alignment' , 'visual-form-builder'); ?>
@@ -1641,13 +1661,13 @@ class Visual_Form_Builder{
1641
  </div>
1642
 
1643
 
1644
- <!-- !Email section -->
1645
  <a href="#email-details" class="settings-links<?php echo ( $settings_accordion == 'email-details' ) ? ' on' : ''; ?>">2. Email<span class="arrow"></span></a>
1646
  <div id="email-details" class="form-details<?php echo ( $settings_accordion == 'email-details' ) ? ' on' : ''; ?>">
1647
 
1648
  <p><em><?php _e( '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.' , 'visual-form-builder'); ?></em></p>
1649
 
1650
- <!-- !E-mail Subject -->
1651
  <p class="description description-wide">
1652
  <label for="form-email-subject">
1653
  <?php _e( 'E-mail Subject' , 'visual-form-builder'); ?>
@@ -1658,7 +1678,7 @@ class Visual_Form_Builder{
1658
  </p>
1659
  <br class="clear" />
1660
 
1661
- <!-- !Sender Name -->
1662
  <p class="description description-thin">
1663
  <label for="form-email-sender-name">
1664
  <?php _e( 'Your Name or Company' , 'visual-form-builder'); ?>
@@ -1684,7 +1704,7 @@ class Visual_Form_Builder{
1684
  </p>
1685
  <br class="clear" />
1686
 
1687
- <!-- !Sender E-mail -->
1688
  <p class="description description-thin">
1689
  <label for="form-email-sender">
1690
  <?php _e( 'Reply-To E-mail' , 'visual-form-builder'); ?>
@@ -1710,7 +1730,7 @@ class Visual_Form_Builder{
1710
  </p>
1711
  <br class="clear" />
1712
 
1713
- <!-- !E-mail(s) To -->
1714
  <?php
1715
  /* Basic count to keep track of multiple options */
1716
  $count = 1;
@@ -1757,6 +1777,8 @@ class Visual_Form_Builder{
1757
  <br class="clear" />
1758
  <p class="description description-wide">
1759
  <?php
 
 
1760
  /* If there's no text message, make sure there is something displayed by setting a default */
1761
  if ( $form_success_message === '' )
1762
  $default_text = sprintf( '<p id="form_success">%s</p>', __( 'Your form was successfully submitted. Thank you for contacting us.' , 'visual-form-builder') );
@@ -1884,7 +1906,7 @@ class Visual_Form_Builder{
1884
  </li>
1885
  </ul>
1886
  </div>
1887
- <div class="vfb-pro-upgrade"><!-- !VFB Pro Upgrade -->
1888
  <h3>Upgrade to <a href="http://vfb.matthewmuro.com">Visual Form Builder Pro</a> for only $10</h3>
1889
  <p>Attention Visual Form Builder users! I am happy to announce <a href="http://vfb.matthewmuro.com">Visual Form Builder Pro</a>, available now for only <strong>$10</strong>.</p>
1890
  <h3><?php _e( 'New Features of Visual Form Builder Pro' , 'visual-form-builder'); ?></h3>
@@ -1893,6 +1915,7 @@ class Visual_Form_Builder{
1893
  <li><?php _e( 'Drag and Drop to add new form fields' , 'visual-form-builder'); ?></li>
1894
  <li><?php _e( '10 new Form Fields (Username, Password, Color Picker, Autocomplete, Hidden, and more)' , 'visual-form-builder'); ?></li>
1895
  <li><?php _e( 'Edit and Update Entries' , 'visual-form-builder'); ?></li>
 
1896
  <li><?php _e( 'Quality HTML Email Template' , 'visual-form-builder'); ?></li>
1897
  <li><?php _e( 'Plain Text Email Option' , 'visual-form-builder'); ?></li>
1898
  <li><?php _e( 'Email Designer' , 'visual-form-builder'); ?></li>
@@ -1959,7 +1982,7 @@ class Visual_Form_Builder{
1959
  if ( isset( $_REQUEST['visual-form-builder-submit'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'visual-form-builder-nonce' ) ) {
1960
  /* Get forms */
1961
  $order = sanitize_sql_orderby( 'form_id DESC' );
1962
- $forms = $wpdb->get_results( "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order" );
1963
 
1964
  foreach ( $forms as $form ) {
1965
  /* If text, return output and format the HTML for display */
@@ -1994,10 +2017,15 @@ class Visual_Form_Builder{
1994
  ), $atts )
1995
  );
1996
 
 
 
 
 
1997
  /* Get form id. Allows use of [vfb id=1] or [vfb 1] */
1998
  $form_id = ( isset( $id ) && !empty( $id ) ) ? $id : $atts[0];
1999
 
2000
  $open_fieldset = $open_section = false;
 
2001
 
2002
  /* Default the submit value */
2003
  $submit = 'Submit';
@@ -2007,19 +2035,19 @@ class Visual_Form_Builder{
2007
  $output = $this->confirmation();
2008
  }
2009
  else {
2010
- /* Get forms */
2011
- $order = sanitize_sql_orderby( 'form_id DESC' );
2012
- $forms = $wpdb->get_results( "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order" );
2013
 
2014
- /* Get fields */
2015
  $order_fields = sanitize_sql_orderby( 'field_sequence ASC' );
2016
- $fields = $wpdb->get_results( "SELECT * FROM $this->field_table_name WHERE form_id = $form_id ORDER BY $order_fields" );
2017
 
2018
  /* Setup count for fieldset and ul/section class names */
2019
  $count = 1;
2020
 
2021
  $verification = '';
2022
-
2023
  foreach ( $forms as $form ) :
2024
  $label_alignment = ( $form->form_label_alignment !== '' ) ? " $form->form_label_alignment" : '';
2025
  $output = '<form id="' . $form->form_key . '" class="visual-form-builder' . $label_alignment . '" method="post" enctype="multipart/form-data">
@@ -2028,12 +2056,13 @@ class Visual_Form_Builder{
2028
 
2029
  foreach ( $fields as $field ) {
2030
  /* If field is required, build the span and add setup the 'required' class */
2031
- $required_span = ( !empty( $field->field_required ) && $field->field_required === 'yes' ) ? ' <span>*</span>' : '';
2032
- $required = ( !empty( $field->field_required ) && $field->field_required === 'yes' ) ? ' required' : '';
2033
- $validation = ( !empty( $field->field_validation ) ) ? " $field->field_validation" : '';
2034
- $css = ( !empty( $field->field_css ) ) ? " $field->field_css" : '';
2035
- $layout = ( !empty( $field->field_layout ) ) ? " $field->field_layout" : '';
2036
- $default = ( !empty( $field->field_default ) ) ? html_entity_decode( stripslashes( $field->field_default ) ) : '';
 
2037
 
2038
  /* Close each section */
2039
  if ( $open_section == true ) {
@@ -2056,7 +2085,7 @@ class Visual_Form_Builder{
2056
  if ( $open_fieldset == true )
2057
  $output .= '</ul><br /></fieldset>';
2058
 
2059
- $output .= '<fieldset class="fieldset fieldset-' . $count . ' ' . $field->field_key . $css . '"><div class="legend"><h3>' . stripslashes( $field->field_name ) . '</h3></div><ul class="section section-' . $count . '">';
2060
  $open_fieldset = true;
2061
  $count++;
2062
  }
@@ -2072,7 +2101,7 @@ class Visual_Form_Builder{
2072
  $columns_choice = ( in_array( $field->field_type, array( 'radio', 'checkbox' ) ) ) ? " $field->field_size" : '';
2073
 
2074
  if ( $field->field_type !== 'hidden' ) {
2075
- $output .= '<li class="item item-' . $field->field_type . $columns_choice . $layout . '"><label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" class="desc">'. stripslashes( $field->field_name ) . $required_span . '</label>';
2076
  }
2077
  }
2078
  elseif ( in_array( $field->field_type, array( 'verification', 'secret' ) ) ) {
@@ -2100,18 +2129,18 @@ class Visual_Form_Builder{
2100
  }
2101
 
2102
  $validation = ' {digits:true,maxlength:2,minlength:2}';
2103
- $verification .= '<li class="item item-' . $field->field_type . '"' . $logged_in_display . '><label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" class="desc">'. stripslashes( $field->field_name ) . $required_span . '</label>';
2104
 
2105
  /* Set variable for testing if required is Yes/No */
2106
  if ( $required == '' )
2107
  $verification .= '<input type="hidden" name="_vfb-required-secret" value="0" />';
2108
 
2109
- $verification .= '<input type="hidden" name="_vfb-secret" value="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" />';
2110
 
2111
  if ( !empty( $field->field_description ) )
2112
- $verification .= '<span><input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" value="' . $logged_in_value . '" class="text ' . $field->field_size . $required . $validation . $css . '" /><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2113
  else
2114
- $verification .= '<input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" value="' . $logged_in_value . '" class="text ' . $field->field_size . $required . $validation . $css . '" />';
2115
  }
2116
  }
2117
 
@@ -2126,9 +2155,9 @@ class Visual_Form_Builder{
2126
  case 'phone' :
2127
 
2128
  if ( !empty( $field->field_description ) )
2129
- $output .= '<span><input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" value="' . $default . '" class="text ' . $field->field_size . $required . $validation . $css . '" /><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2130
  else
2131
- $output .= '<input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" value="' . $default . '" class="text ' . $field->field_size . $required . $validation . $css . '" />';
2132
 
2133
  break;
2134
 
@@ -2137,7 +2166,7 @@ class Visual_Form_Builder{
2137
  if ( !empty( $field->field_description ) )
2138
  $output .= '<span><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2139
 
2140
- $output .= '<textarea name="vfb-'. esc_html( $field->field_key ) . '-' . $field->field_id . '" id="vfb-'. esc_html( $field->field_key ) . '-' . $field->field_id . '" class="textarea ' . $field->field_size . $required . $css . '">' . $default . '</textarea>';
2141
 
2142
  break;
2143
 
@@ -2145,13 +2174,13 @@ class Visual_Form_Builder{
2145
  if ( !empty( $field->field_description ) )
2146
  $output .= '<span><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2147
 
2148
- $output .= '<select name="vfb-'. esc_html( $field->field_key ) . '-' . $field->field_id . '" id="vfb-'. esc_html( $field->field_key ) . '-' . $field->field_id . '" class="select ' . $field->field_size . $required . $css . '">';
2149
 
2150
  $options = ( is_array( unserialize( $field->field_options ) ) ) ? unserialize( $field->field_options ) : explode( ',', unserialize( $field->field_options ) );
2151
 
2152
  /* Loop through each option and output */
2153
  foreach ( $options as $option => $value ) {
2154
- $output .= '<option value="' . trim( stripslashes( $value ) ) . '"' . selected( $default, ++$option, 0 ) . '">'. trim( stripslashes( $value ) ) . '</option>';
2155
  }
2156
 
2157
  $output .= '</select>';
@@ -2169,9 +2198,12 @@ class Visual_Form_Builder{
2169
 
2170
  /* Loop through each option and output */
2171
  foreach ( $options as $option => $value ) {
 
 
 
2172
  $output .= '<span>
2173
- <input type="radio" name="vfb-'. $field->field_key . '-' . $field->field_id . '" id="vfb-'. $field->field_key . '-' . $field->field_id . '-' . $option . '" value="'. trim( stripslashes( $value ) ) . '" class="radio' . $required . $css . '"' . checked( $default, ++$option, 0 ) . ' " />'.
2174
- ' <label for="vfb-' . $field->field_key . '-' . $field->field_id . '-' . $option . '" class="choice">' . trim( stripslashes( $value ) ) . '</label>' .
2175
  '</span>';
2176
  }
2177
 
@@ -2190,9 +2222,11 @@ class Visual_Form_Builder{
2190
 
2191
  /* Loop through each option and output */
2192
  foreach ( $options as $option => $value ) {
 
 
2193
 
2194
- $output .= '<span><input type="checkbox" name="vfb-'. $field->field_key . '-' . $field->field_id . '[]" id="vfb-'. $field->field_key . '-' . $field->field_id . '-' . $option . '" value="'. trim( stripslashes( $value ) ) . '" class="checkbox' . $required . $css . '"' . checked( $default, ++$option, 0 ) . ' />'.
2195
- ' <label for="vfb-' . $field->field_key . '-' . $field->field_id . '-' . $option . '" class="choice">' . trim( stripslashes( $value ) ) . '</label></span>';
2196
  }
2197
 
2198
  $output .= '<div style="clear:both"></div></div>';
@@ -2207,29 +2241,28 @@ class Visual_Form_Builder{
2207
  $output .= '<div>
2208
  <span class="full">
2209
 
2210
- <input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '[address]" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-address" maxlength="150" class="text medium' . $required . $css . '" />
2211
- <label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-address">Address</label>
2212
  </span>
2213
  <span class="full">
2214
- <input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '[address-2]" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . 'address-2" maxlength="150" class="text medium' . $css . '" />
2215
- <label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-address-2">Address Line 2</label>
2216
  </span>
2217
  <span class="left">
2218
 
2219
- <input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '[city]" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-city" maxlength="150" class="text medium' . $required . $css . '" />
2220
- <label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-city">City</label>
2221
  </span>
2222
  <span class="right">
2223
- <input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '[state]" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-state" maxlength="150" class="text medium' . $required . $css . '" />
2224
- <label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-state">State / Province / Region</label>
2225
  </span>
2226
  <span class="left">
2227
-
2228
- <input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '[zip]" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-zip" maxlength="150" class="text medium' . $required . $css . '" />
2229
- <label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-zip">Postal / Zip Code</label>
2230
  </span>
2231
  <span class="right">
2232
- <select class="select' . $required . $css . '" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '[country]" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-country">
2233
  <option selected="selected" value=""></option>';
2234
 
2235
  foreach ( $this->countries as $country ) {
@@ -2237,7 +2270,7 @@ class Visual_Form_Builder{
2237
  }
2238
 
2239
  $output .= '</select>
2240
- <label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-country">Country</label>
2241
  </span>
2242
  </div>';
2243
 
@@ -2246,9 +2279,9 @@ class Visual_Form_Builder{
2246
  case 'date' :
2247
 
2248
  if ( !empty( $field->field_description ) )
2249
- $output .= '<span><input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" value="' . $default . '" class="text vfb-date-picker ' . $field->field_size . $required . $css . '" /><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2250
  else
2251
- $output .= '<input type="text" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" value="" class="text vfb-date-picker ' . $field->field_size . $required . $css . '" />';
2252
 
2253
  break;
2254
 
@@ -2265,16 +2298,16 @@ class Visual_Form_Builder{
2265
  $hour_total = ( $time_format == '12' ) ? 12 : 23;
2266
 
2267
  /* Hour */
2268
- $output .= '<span class="time"><select name="vfb-'. $field->field_key . '-' . $field->field_id . '[hour]" id="vfb-'. $field->field_key . '-' . $field->field_id . '-hour" class="select' . $required . $css . '">';
2269
  for ( $i = $hour_start; $i <= $hour_total; $i++ ) {
2270
  /* Add the leading zero */
2271
  $hour = ( $i < 10 ) ? "0$i" : $i;
2272
  $output .= "<option value='$hour'>$hour</option>";
2273
  }
2274
- $output .= '</select><label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-hour">HH</label></span>';
2275
 
2276
  /* Minute */
2277
- $output .= '<span class="time"><select name="vfb-'. $field->field_key . '-' . $field->field_id . '[min]" id="vfb-'. $field->field_key . '-' . $field->field_id . '-min" class="select' . $required . $css . '">';
2278
 
2279
  $total_mins = apply_filters( 'vfb_time_min_total', 55 );
2280
  $min_interval = apply_filters( 'vfb_time_min_interval', 5 );
@@ -2284,11 +2317,11 @@ class Visual_Form_Builder{
2284
  $min = ( $i < 10 ) ? "0$i" : $i;
2285
  $output .= "<option value='$min'>$min</option>";
2286
  }
2287
- $output .= '</select><label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-min">MM</label></span>';
2288
 
2289
  /* AM/PM */
2290
  if ( $time_format == '12' )
2291
- $output .= '<span class="time"><select name="vfb-'. $field->field_key . '-' . $field->field_id . '[ampm]" id="vfb-'. $field->field_key . '-' . $field->field_id . '-ampm" class="select' . $required . $css . '"><option value="AM">AM</option><option value="PM">PM</option></select><label for="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '-ampm">AM/PM</label></span>';
2292
  $output .= '<div class="clear"></div>';
2293
  break;
2294
 
@@ -2297,8 +2330,8 @@ class Visual_Form_Builder{
2297
  if ( !empty( $field->field_description ) )
2298
  $output .= '<span><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2299
 
2300
- $output .= '<script type="text/javascript">edToolbar("vfb-' . $field->field_key . '-' . $field->field_id . '");</script>';
2301
- $output .= '<textarea name="vfb-'. $field->field_key . '-' . $field->field_id . '" id="vfb-'. $field->field_key . '-' . $field->field_id . '" class="textarea vfbEditor ' . $field->field_size . $required . $css . '"></textarea>';
2302
 
2303
  break;
2304
 
@@ -2308,9 +2341,9 @@ class Visual_Form_Builder{
2308
  $accept = ( !empty( $options[0] ) ) ? " {accept:'$options[0]'}" : '';
2309
 
2310
  if ( !empty( $field->field_description ) )
2311
- $output .= '<span><input type="file" size="35" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" value="' . $default . '" class="text ' . $field->field_size . $required . $validation . $accept . $css . '" /><label>' . stripslashes( $field->field_description ) . '</label></span>';
2312
  else
2313
- $output .= '<input type="file" size="35" name="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" id="vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id . '" value="' . $default . '" class="text ' . $field->field_size . $required . $validation . $accept . $css . '" />';
2314
 
2315
 
2316
  break;
@@ -2363,7 +2396,7 @@ class Visual_Form_Builder{
2363
  </li>
2364
 
2365
  <li class="item item-submit">
2366
- <input type="submit" name="visual-form-builder-submit" value="' . $submit . '" class="submit" id="sendmail" />' . $total_page . '
2367
  </li>
2368
  </ul>
2369
  </fieldset></form>';
@@ -2385,100 +2418,100 @@ class Visual_Form_Builder{
2385
 
2386
  $required = ( isset( $_REQUEST['_vfb-required-secret'] ) && $_REQUEST['_vfb-required-secret'] == '0' ) ? false : true;
2387
  $secret_field = ( isset( $_REQUEST['_vfb-secret'] ) ) ? $_REQUEST['_vfb-secret'] : '';
 
2388
 
2389
- /* If the verification is set to required, run validation check */
2390
- if ( true == $required && !empty( $secret_field ) )
2391
- if ( !is_numeric( $_REQUEST[ $secret_field ] ) && strlen( $_REQUEST[ $secret_field ] ) !== 2 )
2392
- wp_die( __( 'Security check: failed secret question. Please try again!' , 'visual-form-builder') );
2393
-
2394
- /* Basic security check before moving any further */
2395
- if ( isset( $_REQUEST['visual-form-builder-submit'] ) && $_REQUEST['vfb-spam'] == '' ) :
 
 
 
2396
  $nonce = $_REQUEST['_wpnonce'];
2397
 
2398
- /* Security check to verify the nonce */
2399
  if ( ! wp_verify_nonce( $nonce, 'visual-form-builder-nonce' ) )
2400
  wp_die( __( 'Security check: unable to verify nonce value.' , 'visual-form-builder') );
2401
 
2402
- /* Test if it's a known SPAM bot */
2403
  if ( $this->isBot() )
2404
  wp_die( __( 'Security check: looks like you are a SPAM bot. If you think this is an error, please email the site owner.' , 'visual-form-builder') );
2405
 
2406
- /* Set submitted action to display success message */
2407
  $this->submitted = true;
2408
 
2409
- /* Tells us which form to get from the database */
2410
  $form_id = absint( $_REQUEST['form_id'] );
2411
 
2412
- /* Query to get all forms */
2413
  $order = sanitize_sql_orderby( 'form_id DESC' );
 
2414
 
2415
- /* Build our forms as an object */
2416
- $forms = $wpdb->get_results( "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order" );
2417
-
2418
- /* Get sender and email details */
2419
  foreach ( $forms as $form ) {
2420
  $form_settings = (object) array(
2421
- 'form_title' => stripslashes( html_entity_decode( $form->form_title, ENT_QUOTES, 'UTF-8' ) ),
2422
- 'form_subject' => stripslashes( html_entity_decode( $form->form_email_subject, ENT_QUOTES, 'UTF-8' ) ),
2423
- 'form_to' => ( is_array( unserialize( $form->form_email_to ) ) ) ? unserialize( $form->form_email_to ) : explode( ',', unserialize( $form->form_email_to ) ),
2424
- 'form_from' => stripslashes( $form->form_email_from ),
2425
- 'form_from_name' => stripslashes( $form->form_email_from_name ),
2426
- 'form_notification_setting' => stripslashes( $form->form_notification_setting ),
2427
- 'form_notification_email_name' => stripslashes( $form->form_notification_email_name ),
2428
- 'form_notification_email_from' => stripslashes( $form->form_notification_email_from ),
2429
- 'form_notification_subject' => stripslashes( html_entity_decode( $form->form_notification_subject, ENT_QUOTES, 'UTF-8' ) ),
2430
- 'form_notification_message' => stripslashes( $form->form_notification_message ),
2431
- 'form_notification_entry' => stripslashes( $form->form_notification_entry )
2432
  );
2433
-
2434
- /* Allow the form settings to be filtered (ex: return $form_settings->'form_title' = 'Hello World';) */
2435
  $form_settings = (object) apply_filters_ref_array( 'vfb_email_form_settings', array( $form_settings, $form_id ) );
2436
  }
2437
 
2438
- /* Sender name override query */
2439
- $senders = $wpdb->get_results( "SELECT fields.field_id, 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" );
2440
 
2441
- /* Sender email override query */
2442
- $emails = $wpdb->get_results( "SELECT fields.field_id, 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" );
2443
 
2444
- /* Notification send to email override query */
2445
- $notification = $wpdb->get_results( "SELECT fields.field_id, fields.field_key FROM $this->form_table_name AS forms LEFT JOIN $this->field_table_name AS fields ON forms.form_notification_email = fields.field_id WHERE forms.form_id = $form_id" );
2446
 
2447
- /* Load initial Reply-To settings */
2448
- $reply_to_name = stripslashes( $form_settings->form_from_name );
2449
  $reply_to_email = $form_settings->form_from;
2450
 
2451
- /* Loop through name results and assign sender name to override, if needed */
2452
  foreach( $senders as $sender ) {
2453
- if ( !empty( $sender->field_key ) )
2454
- $form_settings->form_from_name = $_POST[ 'vfb-' . $sender->field_key . '-' . $sender->field_id ];
2455
  $reply_to_name = $form_settings->form_from_name;
 
2456
  }
2457
 
2458
- /* Loop through email results and assign sender email to override, if needed */
2459
  foreach ( $emails as $email ) {
2460
- if ( !empty( $email->field_key ) )
2461
- $form_settings->form_from = $_POST[ 'vfb-' . $email->field_key . '-' . $email->field_id ];
2462
  $reply_to_email = $form_settings->form_from;
 
2463
  }
2464
 
2465
- /* Loop through email results and assign as blind carbon copy, if needed */
2466
  foreach ( $notification as $notify ) {
2467
  if ( !empty( $notify->field_key ) )
2468
- $copy_email = $_POST[ 'vfb-' . $notify->field_key . '-' . $notify->field_id ];
2469
  }
2470
 
2471
  /* Query to get all forms */
2472
  $order = sanitize_sql_orderby( 'field_sequence ASC' );
2473
-
2474
- /* Build our forms as an object */
2475
- $fields = $wpdb->get_results( "SELECT field_id, field_key, field_name, field_type, field_options, field_parent FROM $this->field_table_name WHERE form_id = $form_id ORDER BY $order" );
2476
 
2477
  /* Setup counter for alt rows */
2478
  $i = $points = 0;
2479
 
2480
  /* Setup HTML email vars */
2481
- $header = $body = $message = $footer = $html_email = $auto_response_email = '';
2482
 
2483
  /* Prepare the beginning of the content */
2484
  $header = '<html>
@@ -2492,7 +2525,7 @@ class Visual_Form_Builder{
2492
  foreach ( $fields as $field ) {
2493
  /* Handle attachments */
2494
  if ( $field->field_type == 'file-upload' ) {
2495
- $value = $_FILES[ 'vfb-' . $field->field_key . '-' . $field->field_id ];
2496
 
2497
  if ( $value['size'] > 0 ) {
2498
  /* 25MB is the max size allowed */
@@ -2540,7 +2573,7 @@ class Visual_Form_Builder{
2540
  /* Update the attachment metadata */
2541
  wp_update_attachment_metadata( $attach_id, $attach_data );
2542
 
2543
- $attachments[ 'vfb-' . $field->field_key . '-' . $field->field_id ] = $uploaded_file['file'];
2544
 
2545
  $data[] = array(
2546
  'id' => $field->field_id,
@@ -2556,13 +2589,13 @@ class Visual_Form_Builder{
2556
  }
2557
  }
2558
  else {
2559
- $value = $_POST[ 'vfb-' . $field->field_key . '-' . $field->field_id ];
2560
  $body .= '<tr><td><strong>' . stripslashes( $field->field_name ) . ': </strong></td><td>' . $value . '</td></tr>' . "\n";
2561
  }
2562
  }
2563
  /* Everything else */
2564
  else {
2565
- $value = $_POST[ 'vfb-' . $field->field_key . '-' . $field->field_id ];
2566
 
2567
  /* If time field, build proper output */
2568
  if ( is_array( $value ) && array_key_exists( 'hour', $value ) && array_key_exists( 'min', $value ) )
@@ -2605,7 +2638,7 @@ class Visual_Form_Builder{
2605
  $address .= $value['country'];
2606
  }
2607
 
2608
- $value = $address;
2609
  }
2610
  /* If multiple values, build the list */
2611
  elseif ( is_array( $value ) )
@@ -2627,8 +2660,8 @@ class Visual_Form_Builder{
2627
  elseif ( preg_match( $spamwords, $value ) )
2628
  $points += 1;
2629
 
2630
- /* Validate input */
2631
- $this->validate_input( $value, $field->field_type );
2632
 
2633
  //if ( $field->field_type !== 'submit' ) {
2634
  if ( !in_array( $field->field_type , array( 'verification', 'secret', 'submit' ) ) ) {
@@ -2713,6 +2746,8 @@ class Visual_Form_Builder{
2713
  add_filter( 'wp_mail_from_name', array( &$this, 'mail_header_from_name' ) );
2714
  add_filter( 'wp_mail_from', array( &$this, 'mail_header_from' ) );
2715
 
 
 
2716
  /* Decode HTML for message so it outputs properly */
2717
  $notify_message = ( $form_settings->form_notification_message !== '' ) ? html_entity_decode( $form_settings->form_notification_message ) : '';
2718
 
@@ -2722,16 +2757,16 @@ class Visual_Form_Builder{
2722
  else
2723
  $auto_response_email = $header . '<table cellspacing="0" border="0" cellpadding="0" width="100%"><tr><td colspan="2" class="mainbar" align="left" valign="top" width="600"><p style="font-size: 12px; font-weight: normal; margin: 14px 0 14px 0; color: black; padding: 0;">' . $notify_message . '</p></td></tr>' . $footer;
2724
 
2725
- $attachments = ( $form_settings->form_notification_entry !== '' ) ? $attachments : '';
 
 
 
 
2726
 
2727
  /* Send the mail */
2728
- wp_mail( $copy_email, esc_html( $form_settings->form_notification_subject ), $auto_response_email, '', $attachments );
2729
  endif;
2730
 
2731
- elseif ( isset( $_REQUEST['visual-form-builder-submit'] ) ) :
2732
- /* If any of the security checks fail, provide some user feedback */
2733
- if ( $_REQUEST['vfb-spam'] !== '' || !is_numeric( $_REQUEST['vfb-secret'] ) || strlen( $_REQUEST['vfb-secret'] ) !== 2 )
2734
- wp_die( __( 'Ooops! Looks like you have failed the security validation for this form. Please go back and try again.' , 'visual-form-builder') );
2735
  endif;
2736
  }
2737
 
@@ -2740,31 +2775,35 @@ class Visual_Form_Builder{
2740
  *
2741
  * @since 2.2
2742
  */
2743
- public function validate_input( $data, $type ) {
 
 
 
 
2744
  if ( strlen( $data ) > 0 ) :
2745
  switch( $type ) {
2746
 
2747
  case 'email' :
2748
  if ( !is_email( $data ) )
2749
- wp_die( __( 'Not a valid email address', 'visual-form-builder' ), '', array( 'back_link' => true ) );
2750
  break;
2751
 
2752
  case 'number' :
2753
  case 'currency' :
2754
  if ( !is_numeric( $data ) )
2755
- wp_die( __( 'Not a valid number.', 'visual-form-builder' ), '', array( 'back_link' => true ) );
2756
  break;
2757
 
2758
  case 'phone' :
2759
  if ( strlen( $data ) > 9 && preg_match( '/^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/', $data ) )
2760
  return true;
2761
  else
2762
- wp_die( __( 'Not a valid phone number. Most US/Canada and International formats accepted.', 'visual-form-builder' ), '', array( 'back_link' => true ) );
2763
  break;
2764
 
2765
  case 'url' :
2766
  if ( !preg_match( '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $data ) )
2767
- wp_die( __( 'Not a valid URL.', 'visual-form-builder' ), '', array( 'back_link' => true ) );
2768
  break;
2769
 
2770
  default :
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
  Author URI: http://matthewmuro.com
7
+ Version: 2.5
8
  */
9
 
10
  /*
22
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
  */
24
 
25
+ // Set to true to load uncompressed and unminified scripts and stylesheets
26
+ define( 'VFB_SCRIPT_DEBUG', false );
27
+
28
  /* Instantiate new class */
29
  $visual_form_builder = new Visual_Form_Builder();
30
 
31
  /* Restrict Categories class */
32
  class Visual_Form_Builder{
33
 
34
+ protected $vfb_db_version = '2.5',
35
+ $add_scripts = false;
36
 
37
  public $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" );
38
 
44
  $this->form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
45
  $this->entries_table_name = $wpdb->prefix . 'visual_form_builder_entries';
46
 
47
+ // Add suffix to load dev files
48
+ $this->load_dev_files = ( defined( 'VFB_SCRIPT_DEBUG' ) && VFB_SCRIPT_DEBUG ) ? '.dev' : '';
49
+
50
  /* Make sure we are in the admin before proceeding. */
51
  if ( is_admin() ) {
52
  /* Build options and settings pages. */
58
  add_action( 'wp_ajax_visual_form_builder_delete_field', array( &$this, 'delete_field_callback' ) );
59
  add_action( 'wp_ajax_visual_form_builder_form_settings', array( &$this, 'form_settings_callback' ) );
60
 
61
+ add_action( 'load-settings_page_visual-form-builder', array( &$this, 'help' ) );
62
 
63
  /* Adds additional media button to insert form shortcode */
64
  add_action( 'media_buttons_context', array( &$this, 'add_media_button' ) );
69
 
70
  /* Adds a Screen Options tab to the Entries screen */
71
  add_action( 'admin_init', array( &$this, 'save_screen_options' ) );
72
+ add_filter( 'screen_settings', array( &$this, 'entries_screen_options' ) );
73
 
74
  /* Adds a Settings link to the Plugins page */
75
+ add_filter( 'plugin_action_links', array( &$this, 'plugin_action_links' ), 10, 2 );
76
 
77
  /* Add a database version to help with upgrades and run SQL install */
78
  if ( !get_option( 'vfb_db_version' ) ) {
87
  }
88
 
89
  /* Load the jQuery and CSS we need if we're on our plugin page */
90
+ add_action( 'load-settings_page_visual-form-builder', array( &$this, 'admin_scripts' ) );
91
+ add_action( 'load-settings_page_visual-form-builder', array( &$this, 'admin_css' ) );
92
 
93
  /* Display update messages */
94
  add_action('admin_notices', array( &$this, 'admin_notices' ) );
101
  add_action( 'init', array( &$this, 'email' ), 10 );
102
  add_action( 'init', array( &$this, 'confirmation' ), 12 );
103
 
104
+ // Add CSS to the front-end
105
+ add_action( 'wp_enqueue_scripts', array( &$this, 'css' ) );
 
106
  }
107
 
108
  /**
111
  * @since 1.2
112
  */
113
  public function includes(){
114
+ global $entries_list, $entries_detail, $export;
115
 
116
  /* Load the Entries List class */
117
  require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-entries-list.php' );
120
  /* Load the Entries Details class */
121
  require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-entries-detail.php' );
122
  $entries_detail = new VisualFormBuilder_Entries_Detail();
123
+
124
+ /* Load the Entries Details class */
125
+ require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-export.php' );
126
+ $export = new VisualFormBuilder_Export();
127
  }
128
+
129
+ /**
130
+ * Add Settings link to Plugins page
131
+ *
132
+ * @since 1.8
133
+ * @return $links array Links to add to plugin name
134
+ */
135
+ public function plugin_action_links( $links, $file ) {
136
+ if ( $file == plugin_basename( __FILE__ ) )
137
+ $links[] = '<a href="options-general.php?page=visual-form-builder">' . __( 'Settings' , 'visual-form-builder') . '</a>';
138
+
139
+ return $links;
140
+ }
141
 
142
  /**
143
  * Adds the media button image
145
  * @since 2.3
146
  */
147
  public function add_media_button( $context ){
148
+ if ( current_user_can( 'manage_options' ) )
149
+ $context .= '<a href="#TB_inline?width=450&inlineId=vfb_form" class="thickbox" title="Add Visual Form Builder form"><img src="'. plugins_url( 'visual-form-builder/css/vfb_icon.png' ) . '" alt="Add Visual Form Builder form" /></a>';
150
 
151
+ return $context;
152
  }
153
 
154
  /**
165
  $order = sanitize_sql_orderby( 'form_id ASC' );
166
 
167
  /* Build our forms as an object */
168
+ $forms = $wpdb->get_results( $wpdb->prepare( "SELECT form_id, form_title FROM $this->form_table_name ORDER BY $order" ) );
169
  ?>
170
  <script type="text/javascript">
171
  jQuery(document).ready(function($) {
190
  </div>
191
  <?php
192
  }
193
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  /**
195
  * Register contextual help. This is for the Help tab dropdown
196
  *
197
  * @since 1.0
198
  */
199
+ public function help(){
200
  $screen = get_current_screen();
201
 
202
  $screen->add_help_tab( array(
283
  *
284
  * @since 1.2
285
  */
286
+ public function entries_screen_options( $current ){
287
  global $current_screen;
288
 
289
  $options = get_option( 'visual-form-builder-screen-options' );
408
  *
409
  * @since 1.0
410
  */
411
+ public function admin_css() {
412
+ wp_enqueue_style( 'visual-form-builder-style', plugins_url( "visual-form-builder/css/visual-form-builder-admin$this->load_dev_files.css" ) );
413
+ wp_enqueue_style( 'visual-form-builder-main', plugins_url( "visual-form-builder/css/nav-menu$this->load_dev_files.css" ) );
414
  }
415
 
416
  /**
418
  *
419
  * @since 1.0
420
  */
421
+ public function admin_scripts() {
422
  wp_enqueue_script( 'jquery-ui-sortable' );
423
  wp_enqueue_script( 'jquery-form-validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js', array( 'jquery' ), '', true );
424
+ wp_enqueue_script( 'form-elements-add', plugins_url( "visual-form-builder/js/visual-form-builder$this->load_dev_files.js" ) , array( 'jquery', 'jquery-form-validation' ), '', true );
425
+ wp_enqueue_script( 'nested-sortable', plugins_url( 'visual-form-builder/js/jquery.ui.nestedSortable.js' ) , array( 'jquery', 'jquery-ui-sortable' ), '', true );
426
  }
427
 
428
  /**
430
  *
431
  * @since 1.0
432
  */
433
+ public function scripts() {
434
+ // Make sure scripts are only added once via shortcode
435
+ $this->add_scripts = true;
436
+
437
  wp_enqueue_script( 'jquery-form-validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js', array( 'jquery' ), '', true );
438
+ wp_enqueue_script( 'jquery-ui-datepicker' );
439
+ wp_enqueue_script( 'visual-form-builder-validation', plugins_url( "visual-form-builder/js/visual-form-builder-validate$this->load_dev_files.js" ) , array( 'jquery', 'jquery-form-validation' ), '', true );
440
+ wp_enqueue_script( 'visual-form-builder-metadata', plugins_url( 'visual-form-builder/js/jquery.metadata.js' ) , array( 'jquery', 'jquery-form-validation' ), '', true );
 
441
  }
442
 
443
  /**
445
  *
446
  * @since 1.0
447
  */
448
+ public function css() {
449
+ wp_enqueue_style( 'visual-form-builder-css', apply_filters( 'visual-form-builder-css', plugins_url( 'visual-form-builder/css/visual-form-builder.css' ) ) );
450
+ wp_enqueue_style( 'vfb-date-picker-css', apply_filters( 'vfb-date-picker-css','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css' ) );
451
+
452
+ wp_enqueue_script( 'visual-form-builder-quicktags', plugins_url( 'visual-form-builder/js/js_quicktags.js' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
453
  }
454
+
 
455
  /**
456
  * Actions to save, update, and delete forms/form fields
457
  *
547
 
548
  case 'update_form' :
549
 
550
+ $form_id = absint( $_REQUEST['form_id'] );
551
+ $form_key = sanitize_title( $_REQUEST['form_title'], $form_id );
552
+ $form_title = esc_html( $_REQUEST['form_title'] );
553
+ $form_subject = esc_html( $_REQUEST['form_email_subject'] );
554
+ $form_to = serialize( array_map( 'esc_html', $_REQUEST['form_email_to'] ) );
555
+ $form_from = esc_html( $_REQUEST['form_email_from'] );
556
+ $form_from_name = esc_html( $_REQUEST['form_email_from_name'] );
557
+ $form_from_override = esc_html( $_REQUEST['form_email_from_override'] );
558
+ $form_from_name_override = esc_html( $_REQUEST['form_email_from_name_override'] );
559
+ $form_success_type = esc_html( $_REQUEST['form_success_type'] );
560
+ $form_notification_setting = isset( $_REQUEST['form_notification_setting'] ) ? esc_html( $_REQUEST['form_notification_setting'] ) : '';
561
+ $form_notification_email_name = esc_html( $_REQUEST['form_notification_email_name'] );
562
+ $form_notification_email_from = esc_html( $_REQUEST['form_notification_email_from'] );
563
+ $form_notification_email = esc_html( $_REQUEST['form_notification_email'] );
564
+ $form_notification_subject = esc_html( $_REQUEST['form_notification_subject'] );
565
+ $form_notification_message = wp_richedit_pre( $_REQUEST['form_notification_message'] );
566
+ $form_notification_entry = isset( $_REQUEST['form_notification_entry'] ) ? esc_html( $_REQUEST['form_notification_entry'] ) : '';
567
+ $form_label_alignment = esc_html( $_REQUEST['form_label_alignment'] );
568
 
569
  /* Add confirmation based on which type was selected */
570
  switch ( $form_success_type ) {
651
  $field_sequence++;
652
  }
653
 
654
+ // Check if a submit field type exists for backwards compatibility upgrades
655
+ $is_verification = $wpdb->get_var( $wpdb->prepare( "SELECT field_id FROM $this->field_table_name WHERE field_type = 'verification' AND form_id = %d", $form_id ) );
656
+ $is_secret = $wpdb->get_var( $wpdb->prepare( "SELECT field_id FROM $this->field_table_name WHERE field_type = 'secret' AND form_id = %d", $form_id ) );
657
+ $is_submit = $wpdb->get_var( $wpdb->prepare( "SELECT field_id FROM $this->field_table_name WHERE field_type = 'submit' AND form_id = %d", $form_id ) );
658
 
659
  /* Decrement sequence */
660
  $field_sequence--;
661
 
662
+ $verification_id = '';
663
+
664
  /* If this form doesn't have a verification field, add one */
665
  if ( $is_verification == NULL ) {
666
  /* Adjust the sequence */
736
 
737
  check_admin_referer( 'delete-form-' . $id );
738
 
739
+ // Delete form and all fields
740
  $wpdb->query( $wpdb->prepare( "DELETE FROM $this->form_table_name WHERE form_id = %d", $id ) );
741
  $wpdb->query( $wpdb->prepare( "DELETE FROM $this->field_table_name WHERE form_id = %d", $id ) );
742
 
751
 
752
  check_admin_referer( 'copy-form-' . $id );
753
 
754
+ // Get all fields and data for the request form
755
+ $fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->field_table_name WHERE form_id = %d", $id ) );
756
+ $forms = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->form_table_name WHERE form_id = %d", $id ) );
757
+ $override = $wpdb->get_var( $wpdb->prepare( "SELECT form_email_from_override, form_email_from_name_override, form_notification_email FROM $this->form_table_name WHERE form_id = %d", $id ) );
758
+ $from_name = $wpdb->get_var( null, 1 );
759
+ $notify = $wpdb->get_var( null, 2 );
 
 
 
760
 
761
  /* Copy this form and force the initial title to denote a copy */
762
  foreach ( $forms as $form ) {
763
  $data = array(
764
+ 'form_key' => sanitize_title( $form->form_key . ' copy' ),
765
+ 'form_title' => $form->form_title . ' Copy',
766
+ 'form_email_subject' => $form->form_email_subject,
767
+ 'form_email_to' => $form->form_email_to,
768
+ 'form_email_from' => $form->form_email_from,
769
+ 'form_email_from_name' => $form->form_email_from_name,
770
+ 'form_email_from_override' => $form->form_email_from_override,
771
  'form_email_from_name_override' => $form->form_email_from_name_override,
772
+ 'form_success_type' => $form->form_success_type,
773
+ 'form_success_message' => $form->form_success_message,
774
+ 'form_notification_setting' => $form->form_notification_setting,
775
+ 'form_notification_email_name' => $form->form_notification_email_name,
776
+ 'form_notification_email_from' => $form->form_notification_email_from,
777
+ 'form_notification_email' => $form->form_notification_email,
778
+ 'form_notification_subject' => $form->form_notification_subject,
779
+ 'form_notification_message' => $form->form_notification_message,
780
+ 'form_notification_entry' => $form->form_notification_entry,
781
+ 'form_label_alignment' => $form->form_label_alignment
782
  );
783
 
784
  $wpdb->insert( $this->form_table_name, $data );
814
  if ( $override == $field->field_id )
815
  $wpdb->update( $this->form_table_name, array( 'form_email_from_override' => $wpdb->insert_id ), array( 'form_id' => $new_form_selected ) );
816
 
817
+ if ( $from_name == $field->field_id )
818
+ $wpdb->update( $this->form_table_name, array( 'form_email_from_name_override' => $wpdb->insert_id ), array( 'form_id' => $new_form_selected ) );
819
+
820
  if ( $notify == $field->field_id )
821
  $wpdb->update( $this->form_table_name, array( 'form_notification_email' => $wpdb->insert_id ), array( 'form_id' => $new_form_selected ) );
822
  }
867
  global $wpdb;
868
 
869
  $data = array();
870
+ $field_options = $field_validation = '';
871
 
872
  foreach ( $_REQUEST['data'] as $k ) {
873
  $data[ $k['name'] ] = $k['value'];
881
 
882
  /* Set defaults for validation */
883
  switch ( $field_type ) {
884
+ case 'select' :
885
+ case 'radio' :
886
+ case 'checkbox' :
887
+ $field_options = serialize( array( 'Option 1', 'Option 2', 'Option 3' ) );
888
+ break;
889
+
890
  case 'email' :
891
  case 'url' :
892
  case 'phone' :
893
  $field_validation = $field_type;
894
  break;
895
+
896
  case 'currency' :
897
  $field_validation = 'number';
898
  break;
899
+
900
  case 'number' :
901
  $field_validation = 'digits';
902
  break;
903
+
904
  case 'time' :
905
  $field_validation = 'time-12';
906
  break;
907
+
908
  case 'file-upload' :
909
  $field_options = serialize( array( 'png|jpe?g|gif' ) );
910
  break;
913
  check_ajax_referer( 'create-field-' . $data['form_id'], 'nonce' );
914
 
915
  /* Get the last row's sequence that isn't a Verification */
916
+ $sequence_last_row = $wpdb->get_row( $wpdb->prepare( "SELECT field_sequence FROM $this->field_table_name WHERE form_id = %d AND field_type = 'verification' ORDER BY field_sequence DESC LIMIT 1". $form_id ) );
917
 
918
  /* If it's not the first for this form, add 1 */
919
  $field_sequence = ( !empty( $sequence_last_row ) ) ? $sequence_last_row->field_sequence : 0;
1028
 
1029
  $field_where = ( isset( $field_id ) && !is_null( $field_id ) ) ? "AND field_id = $field_id" : '';
1030
  /* Display all fields for the selected form */
1031
+ $fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->field_table_name WHERE form_id = %d $field_where ORDER BY field_sequence ASC", $form_nav_selected_id ) );
1032
 
1033
  $depth = 1;
1034
  $parent = $last = 0;
1115
  <textarea name="field_description-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-description-<?php echo $field->field_id; ?>" /><?php echo stripslashes( $field->field_description ); ?></textarea>
1116
  </label>
1117
  </p>
 
 
 
 
 
 
 
 
1118
 
1119
  <?php else: ?>
1120
 
1369
  echo '</li>';
1370
  }
1371
 
1372
+ /**
1373
+ * Display admin notices
1374
+ *
1375
+ * @since 1.0
1376
+ */
1377
+ public function admin_notices(){
1378
+ if ( isset( $_REQUEST['action'] ) ) {
1379
+ switch( $_REQUEST['action'] ) {
1380
+ case 'create_form' :
1381
+ echo __( '<div id="message" class="updated"><p>The form has been successfully created.</p></div>' , 'visual-form-builder');
1382
+ break;
1383
+ case 'update_form' :
1384
+ echo sprintf( __( '<div id="message" class="updated"><p>The <strong>%s</strong> form has been updated.</p></div>' , 'visual-form-builder'), stripslashes( $_REQUEST['form_title'] ) );
1385
+ break;
1386
+ case 'deleted' :
1387
+ echo __( '<div id="message" class="updated"><p>The form has been successfully deleted.</p></div>' , 'visual-form-builder');
1388
+ break;
1389
+ case 'copy_form' :
1390
+ echo __( '<div id="message" class="updated"><p>The form has been successfully duplicated.</p></div>' , 'visual-form-builder');
1391
+ break;
1392
+ }
1393
+
1394
+ }
1395
+ }
1396
+
1397
+ /**
1398
+ * Add options page to Settings menu
1399
+ *
1400
+ *
1401
+ * @since 1.0
1402
+ * @uses add_options_page() Creates a menu item under the Settings menu.
1403
+ */
1404
+ public function add_admin() {
1405
+ add_options_page( __( 'Visual Form Builder', 'visual-form-builder' ), __( 'Visual Form Builder', 'visual-form-builder' ), 'manage_options', 'visual-form-builder', array( &$this, 'admin' ) );
1406
+ }
1407
+
1408
  /**
1409
  * Builds the options settings page
1410
  *
1411
  * @since 1.0
1412
  */
1413
  public function admin() {
1414
+ global $wpdb, $entries_list, $entries_detail, $export;
1415
 
1416
  /* Set variables depending on which tab is selected */
1417
  $form_nav_selected_id = ( isset( $_REQUEST['form'] ) ) ? $_REQUEST['form'] : '0';
1420
 
1421
  /* Query to get all forms */
1422
  $order = sanitize_sql_orderby( 'form_id DESC' );
1423
+ $forms = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->form_table_name ORDER BY $order" ) );
1424
 
1425
  /* Loop through each form and assign a form id, if any */
1426
  foreach ( $forms as $form ) {
1441
  echo ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) && in_array( $_REQUEST['page'], array( 'visual-form-builder' ) ) ) ? '<span class="subtitle">' . sprintf( __( 'Search results for "%s"' , 'visual-form-builder'), $_REQUEST['s'] ) : '';
1442
  ?>
1443
  </h2>
1444
+ <ul class="sub-navigation">
1445
  <li><a<?php echo ( !isset( $_REQUEST['view'] ) ) ? ' class="current"' : ''; ?> href="<?php echo admin_url( 'options-general.php?page=visual-form-builder' ); ?>"><?php _e( 'Forms' , 'visual-form-builder'); ?></a> |</li>
1446
+ <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' ) ); ?>"><?php _e( 'Entries' , 'visual-form-builder'); ?></a> |</li>
1447
+ <li><a<?php echo ( isset( $_REQUEST['view'] ) && in_array( $_REQUEST['view'], array( 'export' ) ) ) ? ' class="current"' : ''; ?> href="<?php echo add_query_arg( 'view', 'export', admin_url( 'options-general.php?page=visual-form-builder' ) ); ?>"><?php _e( 'Export' , 'visual-form-builder'); ?></a></li>
1448
  </ul>
1449
 
1450
  <?php
1463
  ?>
1464
  </form>
1465
  <?php
1466
+ endif;
1467
+ elseif ( isset( $_REQUEST['view'] ) && in_array( $_REQUEST['view'], array( 'export' ) ) ) :
1468
+ $export->display();
1469
  /* Display the Forms */
1470
  else:
1471
  echo ( isset( $this->message ) ) ? $this->message : ''; ?>
1483
  /* Disable the left box if there's no active form selected */
1484
  $disabled = ( empty( $form_nav_selected_id ) ) ? ' disabled="disabled"' : '';
1485
  ?>
1486
+ <div class="postbox"><!-- Form Items -->
1487
  <h3 class="hndle"><span><?php _e( 'Form Items' , 'visual-form-builder'); ?></span></h3>
1488
  <div class="inside" >
1489
  <div class="taxonomydiv">
1512
  </div>
1513
  </div>
1514
  </form>
1515
+ <div class="postbox"><!-- Form Output -->
1516
  <h3 class="hndle"><span><?php _e( 'Form Output' , 'visual-form-builder'); ?></span></h3>
1517
  <div class="inside">
1518
  <div id="customlinkdiv" class="customlinkdiv">
1534
  <div id="menu-management-liquid">
1535
  <div id="menu-management">
1536
  <div class="nav-tabs-nav">
1537
+ <div class="nav-tabs-arrow nav-tabs-arrow-left"><a>&laquo;</a></div><!-- Form Tab Nav - Left Arrow -->
1538
  <div class="nav-tabs-wrapper">
1539
+ <div class="nav-tabs"><!-- Form Tabs -->
1540
  <?php
1541
  /* Loop through each for and build the tabs */
1542
  foreach ( $forms as $form ) {
1565
  $form_label_alignment = stripslashes( $form->form_label_alignment );
1566
 
1567
  /* Only show required text fields for the sender name override */
1568
+ $senders = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->field_table_name WHERE form_id = %d AND field_type='text' AND field_validation = '' AND field_required = 'yes'", $form_nav_selected_id ) );
1569
 
1570
  /* Only show required email fields for the email override */
1571
+ $emails = $wpdb->get_results( $wpdb->prepare( "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')" ) );
1572
 
1573
  else :
1574
  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>';
1585
  <?php endif; ?>
1586
  </div>
1587
  </div>
1588
+ <div class="nav-tabs-arrow nav-tabs-arrow-right"><a>&raquo;</a></div><!-- Form Tab Nav - Right Arrow -->
1589
  </div>
1590
 
1591
  <div class="menu-edit">
1641
  </div>
1642
 
1643
  <div id="form-settings" class="<?php echo $opened_tab; ?>">
1644
+ <!-- General settings section -->
1645
  <a href="#general-settings" class="settings-links<?php echo ( $settings_accordion == 'general-settings' ) ? ' on' : ''; ?>">1. General<span class="arrow"></span></a>
1646
  <div id="general-settings" class="form-details<?php echo ( $settings_accordion == 'general-settings' ) ? ' on' : ''; ?>">
1647
+ <!-- Label Alignment -->
1648
  <p class="description description-wide">
1649
  <label for="form-label-alignment">
1650
  <?php _e( 'Label Alignment' , 'visual-form-builder'); ?>
1661
  </div>
1662
 
1663
 
1664
+ <!-- Email section -->
1665
  <a href="#email-details" class="settings-links<?php echo ( $settings_accordion == 'email-details' ) ? ' on' : ''; ?>">2. Email<span class="arrow"></span></a>
1666
  <div id="email-details" class="form-details<?php echo ( $settings_accordion == 'email-details' ) ? ' on' : ''; ?>">
1667
 
1668
  <p><em><?php _e( '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.' , 'visual-form-builder'); ?></em></p>
1669
 
1670
+ <!-- E-mail Subject -->
1671
  <p class="description description-wide">
1672
  <label for="form-email-subject">
1673
  <?php _e( 'E-mail Subject' , 'visual-form-builder'); ?>
1678
  </p>
1679
  <br class="clear" />
1680
 
1681
+ <!-- Sender Name -->
1682
  <p class="description description-thin">
1683
  <label for="form-email-sender-name">
1684
  <?php _e( 'Your Name or Company' , 'visual-form-builder'); ?>
1704
  </p>
1705
  <br class="clear" />
1706
 
1707
+ <!-- Sender E-mail -->
1708
  <p class="description description-thin">
1709
  <label for="form-email-sender">
1710
  <?php _e( 'Reply-To E-mail' , 'visual-form-builder'); ?>
1730
  </p>
1731
  <br class="clear" />
1732
 
1733
+ <!-- E-mail(s) To -->
1734
  <?php
1735
  /* Basic count to keep track of multiple options */
1736
  $count = 1;
1777
  <br class="clear" />
1778
  <p class="description description-wide">
1779
  <?php
1780
+ $default_text = '';
1781
+
1782
  /* If there's no text message, make sure there is something displayed by setting a default */
1783
  if ( $form_success_message === '' )
1784
  $default_text = sprintf( '<p id="form_success">%s</p>', __( 'Your form was successfully submitted. Thank you for contacting us.' , 'visual-form-builder') );
1906
  </li>
1907
  </ul>
1908
  </div>
1909
+ <div class="vfb-pro-upgrade"><!-- VFB Pro Upgrade -->
1910
  <h3>Upgrade to <a href="http://vfb.matthewmuro.com">Visual Form Builder Pro</a> for only $10</h3>
1911
  <p>Attention Visual Form Builder users! I am happy to announce <a href="http://vfb.matthewmuro.com">Visual Form Builder Pro</a>, available now for only <strong>$10</strong>.</p>
1912
  <h3><?php _e( 'New Features of Visual Form Builder Pro' , 'visual-form-builder'); ?></h3>
1915
  <li><?php _e( 'Drag and Drop to add new form fields' , 'visual-form-builder'); ?></li>
1916
  <li><?php _e( '10 new Form Fields (Username, Password, Color Picker, Autocomplete, Hidden, and more)' , 'visual-form-builder'); ?></li>
1917
  <li><?php _e( 'Edit and Update Entries' , 'visual-form-builder'); ?></li>
1918
+ <li><?php _e( 'Import/Export forms, settings, and entries' , 'visual-form-builder'); ?></li>
1919
  <li><?php _e( 'Quality HTML Email Template' , 'visual-form-builder'); ?></li>
1920
  <li><?php _e( 'Plain Text Email Option' , 'visual-form-builder'); ?></li>
1921
  <li><?php _e( 'Email Designer' , 'visual-form-builder'); ?></li>
1982
  if ( isset( $_REQUEST['visual-form-builder-submit'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'visual-form-builder-nonce' ) ) {
1983
  /* Get forms */
1984
  $order = sanitize_sql_orderby( 'form_id DESC' );
1985
+ $forms = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->form_table_name WHERE form_id = %d ORDER BY $order", $form_id ) );
1986
 
1987
  foreach ( $forms as $form ) {
1988
  /* If text, return output and format the HTML for display */
2017
  ), $atts )
2018
  );
2019
 
2020
+ // Add JavaScript files to the front-end, only once
2021
+ if ( !$this->add_scripts )
2022
+ $this->scripts();
2023
+
2024
  /* Get form id. Allows use of [vfb id=1] or [vfb 1] */
2025
  $form_id = ( isset( $id ) && !empty( $id ) ) ? $id : $atts[0];
2026
 
2027
  $open_fieldset = $open_section = false;
2028
+ $output = '';
2029
 
2030
  /* Default the submit value */
2031
  $submit = 'Submit';
2035
  $output = $this->confirmation();
2036
  }
2037
  else {
2038
+ // Get forms
2039
+ $order = sanitize_sql_orderby( 'form_id DESC' );
2040
+ $forms = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->form_table_name WHERE form_id = %d ORDER BY $order", $form_id ) );
2041
 
2042
+ // Get fields
2043
  $order_fields = sanitize_sql_orderby( 'field_sequence ASC' );
2044
+ $fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->field_table_name WHERE form_id = %d ORDER BY $order_fields", $form_id ) );
2045
 
2046
  /* Setup count for fieldset and ul/section class names */
2047
  $count = 1;
2048
 
2049
  $verification = '';
2050
+
2051
  foreach ( $forms as $form ) :
2052
  $label_alignment = ( $form->form_label_alignment !== '' ) ? " $form->form_label_alignment" : '';
2053
  $output = '<form id="' . $form->form_key . '" class="visual-form-builder' . $label_alignment . '" method="post" enctype="multipart/form-data">
2056
 
2057
  foreach ( $fields as $field ) {
2058
  /* If field is required, build the span and add setup the 'required' class */
2059
+ $required_span = ( !empty( $field->field_required ) && $field->field_required === 'yes' ) ? ' <span>*</span>' : '';
2060
+ $required = ( !empty( $field->field_required ) && $field->field_required === 'yes' ) ? ' required' : '';
2061
+ $validation = ( !empty( $field->field_validation ) ) ? " $field->field_validation" : '';
2062
+ $css = ( !empty( $field->field_css ) ) ? " $field->field_css" : '';
2063
+ $id_attr = 'vfb-' . esc_html( $field->field_key ) . '-' . $field->field_id;
2064
+ $layout = ( !empty( $field->field_layout ) ) ? " $field->field_layout" : '';
2065
+ $default = ( !empty( $field->field_default ) ) ? html_entity_decode( stripslashes( $field->field_default ) ) : '';
2066
 
2067
  /* Close each section */
2068
  if ( $open_section == true ) {
2085
  if ( $open_fieldset == true )
2086
  $output .= '</ul><br /></fieldset>';
2087
 
2088
+ $output .= '<fieldset class="fieldset fieldset-' . $count . ' ' . $field->field_key . $css . '" id="' . $id_attr . '"><div class="legend"><h3>' . stripslashes( $field->field_name ) . '</h3></div><ul class="section section-' . $count . '">';
2089
  $open_fieldset = true;
2090
  $count++;
2091
  }
2101
  $columns_choice = ( in_array( $field->field_type, array( 'radio', 'checkbox' ) ) ) ? " $field->field_size" : '';
2102
 
2103
  if ( $field->field_type !== 'hidden' ) {
2104
+ $output .= '<li class="item item-' . $field->field_type . $columns_choice . $layout . '" id="item-' . $id_attr . '"><label for="' . $id_attr . '" class="desc">'. stripslashes( $field->field_name ) . $required_span . '</label>';
2105
  }
2106
  }
2107
  elseif ( in_array( $field->field_type, array( 'verification', 'secret' ) ) ) {
2129
  }
2130
 
2131
  $validation = ' {digits:true,maxlength:2,minlength:2}';
2132
+ $verification .= '<li class="item item-' . $field->field_type . '"' . $logged_in_display . '><label for="' . $id_attr . '" class="desc">'. stripslashes( $field->field_name ) . $required_span . '</label>';
2133
 
2134
  /* Set variable for testing if required is Yes/No */
2135
  if ( $required == '' )
2136
  $verification .= '<input type="hidden" name="_vfb-required-secret" value="0" />';
2137
 
2138
+ $verification .= '<input type="hidden" name="_vfb-secret" value="vfb-' . $field->field_id . '" />';
2139
 
2140
  if ( !empty( $field->field_description ) )
2141
+ $verification .= '<span><input type="text" name="vfb-' . $field->field_id . '" id="' . $id_attr . '" value="' . $logged_in_value . '" class="text ' . $field->field_size . $required . $validation . $css . '" /><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2142
  else
2143
+ $verification .= '<input type="text" name="vfb-' . $field->field_id . '" id="' . $id_attr . '" value="' . $logged_in_value . '" class="text ' . $field->field_size . $required . $validation . $css . '" />';
2144
  }
2145
  }
2146
 
2155
  case 'phone' :
2156
 
2157
  if ( !empty( $field->field_description ) )
2158
+ $output .= '<span><input type="text" name="vfb-' . $field->field_id . '" id="' . $id_attr . '" value="' . $default . '" class="text ' . $field->field_size . $required . $validation . $css . '" /><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2159
  else
2160
+ $output .= '<input type="text" name="vfb-' . $field->field_id . '" id="' . $id_attr . '" value="' . $default . '" class="text ' . $field->field_size . $required . $validation . $css . '" />';
2161
 
2162
  break;
2163
 
2166
  if ( !empty( $field->field_description ) )
2167
  $output .= '<span><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2168
 
2169
+ $output .= '<textarea name="vfb-' . $field->field_id . '" id="'. $id_attr . '" class="textarea ' . $field->field_size . $required . $css . '">' . $default . '</textarea>';
2170
 
2171
  break;
2172
 
2174
  if ( !empty( $field->field_description ) )
2175
  $output .= '<span><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2176
 
2177
+ $output .= '<select name="vfb-'. $field->field_id . '" id="' . $id_attr . '" class="select ' . $field->field_size . $required . $css . '">';
2178
 
2179
  $options = ( is_array( unserialize( $field->field_options ) ) ) ? unserialize( $field->field_options ) : explode( ',', unserialize( $field->field_options ) );
2180
 
2181
  /* Loop through each option and output */
2182
  foreach ( $options as $option => $value ) {
2183
+ $output .= '<option value="' . trim( stripslashes( $value ) ) . '"' . selected( $default, ++$option, 0 ) . '>'. trim( stripslashes( $value ) ) . '</option>';
2184
  }
2185
 
2186
  $output .= '</select>';
2198
 
2199
  /* Loop through each option and output */
2200
  foreach ( $options as $option => $value ) {
2201
+ // Increment the base index by one to match $default
2202
+ $option++;
2203
+
2204
  $output .= '<span>
2205
+ <input type="radio" name="vfb-' . $field->field_id . '" id="'. $id_attr . '-' . $option . '" value="'. trim( stripslashes( $value ) ) . '" class="radio' . $required . $css . '"' . checked( $default, $option, 0 ) . ' />'.
2206
+ ' <label for="' . $id_attr . '-' . $option . '" class="choice">' . trim( stripslashes( $value ) ) . '</label>' .
2207
  '</span>';
2208
  }
2209
 
2222
 
2223
  /* Loop through each option and output */
2224
  foreach ( $options as $option => $value ) {
2225
+ // Increment the base index by one to match $default
2226
+ $option++;
2227
 
2228
+ $output .= '<span><input type="checkbox" name="vfb-' . $field->field_id . '[]" id="' . $id_attr . '-' . $option . '" value="'. trim( stripslashes( $value ) ) . '" class="checkbox' . $required . $css . '"' . checked( $default, $option, 0 ) . ' />'.
2229
+ ' <label for="' . $id_attr . '-' . $option . '" class="choice">' . trim( stripslashes( $value ) ) . '</label></span>';
2230
  }
2231
 
2232
  $output .= '<div style="clear:both"></div></div>';
2241
  $output .= '<div>
2242
  <span class="full">
2243
 
2244
+ <input type="text" name="vfb-' . $field->field_id . '[address]" id="' . $id_attr . '-address" maxlength="150" class="text medium' . $required . $css . '" />
2245
+ <label for="' . $id_attr . '-address">Address</label>
2246
  </span>
2247
  <span class="full">
2248
+ <input type="text" name="vfb-' . $field->field_id . '[address-2]" id="' . $id_attr . 'address-2" maxlength="150" class="text medium' . $css . '" />
2249
+ <label for="' . $id_attr . '-address-2">Address Line 2</label>
2250
  </span>
2251
  <span class="left">
2252
 
2253
+ <input type="text" name="vfb-' . $field->field_id . '[city]" id="' . $id_attr . '-city" maxlength="150" class="text medium' . $required . $css . '" />
2254
+ <label for="' . $id_attr . '-city">City</label>
2255
  </span>
2256
  <span class="right">
2257
+ <input type="text" name="vfb-' . $field->field_id . '[state]" id="' . $id_attr . '-state" maxlength="150" class="text medium' . $required . $css . '" />
2258
+ <label for="' . $id_attr . '-state">State / Province / Region</label>
2259
  </span>
2260
  <span class="left">
2261
+ <input type="text" name="vfb-' . $field->field_id . '[zip]" id="' . $id_attr . '-zip" maxlength="150" class="text medium' . $required . $css . '" />
2262
+ <label for="' . $id_attr . '-zip">Postal / Zip Code</label>
 
2263
  </span>
2264
  <span class="right">
2265
+ <select class="select' . $required . $css . '" name="vfb-' . $field->field_id . '[country]" id="' . $id_attr . '-country">
2266
  <option selected="selected" value=""></option>';
2267
 
2268
  foreach ( $this->countries as $country ) {
2270
  }
2271
 
2272
  $output .= '</select>
2273
+ <label for="' . $id_attr . '-country">Country</label>
2274
  </span>
2275
  </div>';
2276
 
2279
  case 'date' :
2280
 
2281
  if ( !empty( $field->field_description ) )
2282
+ $output .= '<span><input type="text" name="vfb-' . $field->field_id . '" id="' . $id_attr . '" value="' . $default . '" class="text vfb-date-picker ' . $field->field_size . $required . $css . '" /><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2283
  else
2284
+ $output .= '<input type="text" name="vfb-' . $field->field_id . '" id="' . $id_attr . '" value="" class="text vfb-date-picker ' . $field->field_size . $required . $css . '" />';
2285
 
2286
  break;
2287
 
2298
  $hour_total = ( $time_format == '12' ) ? 12 : 23;
2299
 
2300
  /* Hour */
2301
+ $output .= '<span class="time"><select name="vfb-' . $field->field_id . '[hour]" id="' . $id_attr . '-hour" class="select' . $required . $css . '">';
2302
  for ( $i = $hour_start; $i <= $hour_total; $i++ ) {
2303
  /* Add the leading zero */
2304
  $hour = ( $i < 10 ) ? "0$i" : $i;
2305
  $output .= "<option value='$hour'>$hour</option>";
2306
  }
2307
+ $output .= '</select><label for="' . $id_attr . '-hour">HH</label></span>';
2308
 
2309
  /* Minute */
2310
+ $output .= '<span class="time"><select name="vfb-' . $field->field_id . '[min]" id="' . $id_attr . '-min" class="select' . $required . $css . '">';
2311
 
2312
  $total_mins = apply_filters( 'vfb_time_min_total', 55 );
2313
  $min_interval = apply_filters( 'vfb_time_min_interval', 5 );
2317
  $min = ( $i < 10 ) ? "0$i" : $i;
2318
  $output .= "<option value='$min'>$min</option>";
2319
  }
2320
+ $output .= '</select><label for="' . $id_attr . '-min">MM</label></span>';
2321
 
2322
  /* AM/PM */
2323
  if ( $time_format == '12' )
2324
+ $output .= '<span class="time"><select name="vfb-' . $field->field_id . '[ampm]" id="' . $id_attr . '-ampm" class="select' . $required . $css . '"><option value="AM">AM</option><option value="PM">PM</option></select><label for="' . $id_attr . '-ampm">AM/PM</label></span>';
2325
  $output .= '<div class="clear"></div>';
2326
  break;
2327
 
2330
  if ( !empty( $field->field_description ) )
2331
  $output .= '<span><label>' . html_entity_decode( stripslashes( $field->field_description ) ) . '</label></span>';
2332
 
2333
+ $output .= '<script type="text/javascript">edToolbar("' . $id_attr . '");</script>';
2334
+ $output .= '<textarea name="vfb-' . $field->field_id . '" id="' . $id_attr . '" class="textarea vfbEditor ' . $field->field_size . $required . $css . '"></textarea>';
2335
 
2336
  break;
2337
 
2341
  $accept = ( !empty( $options[0] ) ) ? " {accept:'$options[0]'}" : '';
2342
 
2343
  if ( !empty( $field->field_description ) )
2344
+ $output .= '<span><input type="file" size="35" name="vfb-' . $field->field_id . '" id="' . $id_attr . '" value="' . $default . '" class="text ' . $field->field_size . $required . $validation . $accept . $css . '" /><label>' . stripslashes( $field->field_description ) . '</label></span>';
2345
  else
2346
+ $output .= '<input type="file" size="35" name="vfb-' . $field->field_id . '" id="' . $id_attr . '" value="' . $default . '" class="text ' . $field->field_size . $required . $validation . $accept . $css . '" />';
2347
 
2348
 
2349
  break;
2396
  </li>
2397
 
2398
  <li class="item item-submit">
2399
+ <input type="submit" name="visual-form-builder-submit" value="' . $submit . '" class="submit" id="sendmail" />
2400
  </li>
2401
  </ul>
2402
  </fieldset></form>';
2418
 
2419
  $required = ( isset( $_REQUEST['_vfb-required-secret'] ) && $_REQUEST['_vfb-required-secret'] == '0' ) ? false : true;
2420
  $secret_field = ( isset( $_REQUEST['_vfb-secret'] ) ) ? $_REQUEST['_vfb-secret'] : '';
2421
+ $honeypot = ( isset( $_REQUEST['vfb-spam'] ) ) ? $_REQUEST['vfb-spam'] : '';
2422
 
2423
+ // If the verification is set to required, run validation check
2424
+ if ( true == $required && !empty( $secret_field ) ) {
2425
+ if ( !empty( $honeypot ) )
2426
+ wp_die( __( 'Security check: hidden spam field should be blank.' , 'visual-form-builder'), '', array( 'back_link' => true ) );
2427
+ if ( !is_numeric( $_REQUEST[ $secret_field ] ) || strlen( $_REQUEST[ $secret_field ] ) !== 2 )
2428
+ wp_die( __( 'Security check: failed secret question. Please try again!' , 'visual-form-builder'), '', array( 'back_link' => true ) );
2429
+ }
2430
+
2431
+ // Basic security check before moving any further
2432
+ if ( isset( $_REQUEST['visual-form-builder-submit'] ) ) :
2433
  $nonce = $_REQUEST['_wpnonce'];
2434
 
2435
+ // Security check to verify the nonce
2436
  if ( ! wp_verify_nonce( $nonce, 'visual-form-builder-nonce' ) )
2437
  wp_die( __( 'Security check: unable to verify nonce value.' , 'visual-form-builder') );
2438
 
2439
+ // Test if it's a known SPAM bot
2440
  if ( $this->isBot() )
2441
  wp_die( __( 'Security check: looks like you are a SPAM bot. If you think this is an error, please email the site owner.' , 'visual-form-builder') );
2442
 
2443
+ // Set submitted action to display success message
2444
  $this->submitted = true;
2445
 
2446
+ // Tells us which form to get from the database
2447
  $form_id = absint( $_REQUEST['form_id'] );
2448
 
2449
+ // Query to get all forms
2450
  $order = sanitize_sql_orderby( 'form_id DESC' );
2451
+ $forms = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->form_table_name WHERE form_id = %d ORDER BY $order", $form_id ) );
2452
 
2453
+ // Get sender and email details
 
 
 
2454
  foreach ( $forms as $form ) {
2455
  $form_settings = (object) array(
2456
+ 'form_title' => stripslashes( html_entity_decode( $form->form_title, ENT_QUOTES, 'UTF-8' ) ),
2457
+ 'form_subject' => stripslashes( html_entity_decode( $form->form_email_subject, ENT_QUOTES, 'UTF-8' ) ),
2458
+ 'form_to' => ( is_array( unserialize( $form->form_email_to ) ) ) ? unserialize( $form->form_email_to ) : explode( ',', unserialize( $form->form_email_to ) ),
2459
+ 'form_from' => stripslashes( $form->form_email_from ),
2460
+ 'form_from_name' => stripslashes( $form->form_email_from_name ),
2461
+ 'form_notification_setting' => stripslashes( $form->form_notification_setting ),
2462
+ 'form_notification_email_name' => stripslashes( $form->form_notification_email_name ),
2463
+ 'form_notification_email_from' => stripslashes( $form->form_notification_email_from ),
2464
+ 'form_notification_subject' => stripslashes( html_entity_decode( $form->form_notification_subject, ENT_QUOTES, 'UTF-8' ) ),
2465
+ 'form_notification_message' => stripslashes( $form->form_notification_message ),
2466
+ 'form_notification_entry' => stripslashes( $form->form_notification_entry )
2467
  );
2468
+ // Allow the form settings to be filtered (ex: return $form_settings->'form_title' = 'Hello World';)
 
2469
  $form_settings = (object) apply_filters_ref_array( 'vfb_email_form_settings', array( $form_settings, $form_id ) );
2470
  }
2471
 
2472
+ // Sender name override query
2473
+ $senders = $wpdb->get_results( $wpdb->prepare( "SELECT fields.field_id, 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 = %d", $form_id ) );
2474
 
2475
+ // Sender email override query
2476
+ $emails = $wpdb->get_results( $wpdb->prepare( "SELECT fields.field_id, 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 = %d", $form_id ) );
2477
 
2478
+ // Notification send to email override query
2479
+ $notification = $wpdb->get_results( $wpdb->prepare( "SELECT fields.field_id, fields.field_key FROM $this->form_table_name AS forms LEFT JOIN $this->field_table_name AS fields ON forms.form_notification_email = fields.field_id WHERE forms.form_id = %d", $form_id ) );
2480
 
2481
+ $reply_to_name = $form_settings->form_from_name;
 
2482
  $reply_to_email = $form_settings->form_from;
2483
 
2484
+ // Loop through name results and assign sender name to override, if needed
2485
  foreach( $senders as $sender ) {
2486
+ if ( !empty( $sender->field_key ) ) {
2487
+ $form_settings->form_from_name = $_POST[ 'vfb-' . $sender->field_id ];
2488
  $reply_to_name = $form_settings->form_from_name;
2489
+ }
2490
  }
2491
 
2492
+ // Loop through email results and assign sender email to override, if needed
2493
  foreach ( $emails as $email ) {
2494
+ if ( !empty( $email->field_key ) ) {
2495
+ $form_settings->form_from = $_POST[ 'vfb-' . $email->field_id ];
2496
  $reply_to_email = $form_settings->form_from;
2497
+ }
2498
  }
2499
 
2500
+ // Loop through email results and assign as blind carbon copy, if needed
2501
  foreach ( $notification as $notify ) {
2502
  if ( !empty( $notify->field_key ) )
2503
+ $copy_email = $_POST[ 'vfb-' . $notify->field_id ];
2504
  }
2505
 
2506
  /* Query to get all forms */
2507
  $order = sanitize_sql_orderby( 'field_sequence ASC' );
2508
+ $fields = $wpdb->get_results( $wpdb->prepare( "SELECT field_id, field_key, field_name, field_type, field_options, field_parent, field_required FROM $this->field_table_name WHERE form_id = %d ORDER BY $order", $form_id ) );
 
 
2509
 
2510
  /* Setup counter for alt rows */
2511
  $i = $points = 0;
2512
 
2513
  /* Setup HTML email vars */
2514
+ $header = $body = $message = $footer = $html_email = $auto_response_email = $attachments = '';
2515
 
2516
  /* Prepare the beginning of the content */
2517
  $header = '<html>
2525
  foreach ( $fields as $field ) {
2526
  /* Handle attachments */
2527
  if ( $field->field_type == 'file-upload' ) {
2528
+ $value = ( isset( $_FILES[ 'vfb-' . $field->field_id ] ) ) ? $_FILES[ 'vfb-' . $field->field_id ] : '';
2529
 
2530
  if ( $value['size'] > 0 ) {
2531
  /* 25MB is the max size allowed */
2573
  /* Update the attachment metadata */
2574
  wp_update_attachment_metadata( $attach_id, $attach_data );
2575
 
2576
+ $attachments[ 'vfb-' . $field->field_id ] = $uploaded_file['file'];
2577
 
2578
  $data[] = array(
2579
  'id' => $field->field_id,
2589
  }
2590
  }
2591
  else {
2592
+ $value = ( isset( $_POST[ 'vfb-' . $field->field_id ] ) ) ? $_POST[ 'vfb-' . $field->field_id ] : '';
2593
  $body .= '<tr><td><strong>' . stripslashes( $field->field_name ) . ': </strong></td><td>' . $value . '</td></tr>' . "\n";
2594
  }
2595
  }
2596
  /* Everything else */
2597
  else {
2598
+ $value = ( isset( $_POST[ 'vfb-' . $field->field_id ] ) ) ? $_POST[ 'vfb-' . $field->field_id ] : '';
2599
 
2600
  /* If time field, build proper output */
2601
  if ( is_array( $value ) && array_key_exists( 'hour', $value ) && array_key_exists( 'min', $value ) )
2638
  $address .= $value['country'];
2639
  }
2640
 
2641
+ $value = html_entity_decode( stripslashes( esc_html( $address ) ), ENT_QUOTES, 'UTF-8' );
2642
  }
2643
  /* If multiple values, build the list */
2644
  elseif ( is_array( $value ) )
2660
  elseif ( preg_match( $spamwords, $value ) )
2661
  $points += 1;
2662
 
2663
+ // Validate input
2664
+ $this->validate_input( $value, $field->field_name, $field->field_type, $field->field_required );
2665
 
2666
  //if ( $field->field_type !== 'submit' ) {
2667
  if ( !in_array( $field->field_type , array( 'verification', 'secret', 'submit' ) ) ) {
2746
  add_filter( 'wp_mail_from_name', array( &$this, 'mail_header_from_name' ) );
2747
  add_filter( 'wp_mail_from', array( &$this, 'mail_header_from' ) );
2748
 
2749
+ $attachments = ( $form_settings->form_notification_entry !== '' ) ? $attachments : '';
2750
+
2751
  /* Decode HTML for message so it outputs properly */
2752
  $notify_message = ( $form_settings->form_notification_message !== '' ) ? html_entity_decode( $form_settings->form_notification_message ) : '';
2753
 
2757
  else
2758
  $auto_response_email = $header . '<table cellspacing="0" border="0" cellpadding="0" width="100%"><tr><td colspan="2" class="mainbar" align="left" valign="top" width="600"><p style="font-size: 12px; font-weight: normal; margin: 14px 0 14px 0; color: black; padding: 0;">' . $notify_message . '</p></td></tr>' . $footer;
2759
 
2760
+ // Reset headers for notification email
2761
+ $from_name = ( $this->header_from_name == '' ) ? 'WordPress' : $this->header_from_name;
2762
+ $from_email = 'wordpress@' . $_SERVER['SERVER_NAME'];
2763
+ $reply_to = "\"$this->header_from_name\" <$this->header_from>";
2764
+ $headers = "From: \"$from_name\" <$from_email>\n" . "Reply-To: $reply_to\n" . "Content-Type: $this->header_content_type; charset=\"" . get_option('blog_charset') . "\"\n";
2765
 
2766
  /* Send the mail */
2767
+ wp_mail( $copy_email, esc_html( $form_settings->form_notification_subject ), $auto_response_email, $headers, $attachments );
2768
  endif;
2769
 
 
 
 
 
2770
  endif;
2771
  }
2772
 
2775
  *
2776
  * @since 2.2
2777
  */
2778
+ public function validate_input( $data, $name, $type, $required ) {
2779
+
2780
+ if ( 'yes' == $required && strlen( $data ) == 0 )
2781
+ wp_die( "<h1>$name</h1><br>" . __( 'This field is required and cannot be empty.', 'visual-form-builder-pro' ), $name, array( 'back_link' => true ) );
2782
+
2783
  if ( strlen( $data ) > 0 ) :
2784
  switch( $type ) {
2785
 
2786
  case 'email' :
2787
  if ( !is_email( $data ) )
2788
+ wp_die( "<h1>$name</h1><br>" . __( 'Not a valid email address', 'visual-form-builder-pro' ), '', array( 'back_link' => true ) );
2789
  break;
2790
 
2791
  case 'number' :
2792
  case 'currency' :
2793
  if ( !is_numeric( $data ) )
2794
+ wp_die( "<h1>$name</h1><br>" . __( 'Not a valid number', 'visual-form-builder-pro' ), '', array( 'back_link' => true ) );
2795
  break;
2796
 
2797
  case 'phone' :
2798
  if ( strlen( $data ) > 9 && preg_match( '/^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/', $data ) )
2799
  return true;
2800
  else
2801
+ wp_die( "<h1>$name</h1><br>" . __( 'Not a valid phone number. Most US/Canada and International formats accepted.', 'visual-form-builder-pro' ), '', array( 'back_link' => true ) );
2802
  break;
2803
 
2804
  case 'url' :
2805
  if ( !preg_match( '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $data ) )
2806
+ wp_die( "<h1>$name</h1><br>" . __( 'Not a valid URL.', 'visual-form-builder-pro' ), '', array( 'back_link' => true ) );
2807
  break;
2808
 
2809
  default :