Visual Form Builder - Version 1.0

Version Description

Download this release

Release Info

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

Version 1.0

css/visual-form-builder-admin.css ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ label.error{color:red;display:block;}
2
+ #visual-form-builder-update input.error, #visual-form-builder-update textarea.error{border:1px solid red;}
3
+ .menu-item-handle.fieldset{
4
+ background-image: -moz-linear-gradient(top, #E3E3E3 0%, #CCCCCC 100%);
5
+ background-image: -o-linear-gradient(top, #E3E3E3 0%, #CCCCCC 100%);
6
+ background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #E3E3E3), color-stop(1, #CCCCCC));
7
+ background-image: linear-gradient(top, #E3E3E3 0%, #CCCCCC 100%);
8
+ box-shadow:0 1px 0 #e3e3e3 inset;
9
+ }
10
+ .sender-labels{width:80px;}
11
+ .is-field-required{color:#BC1212; vertical-align:middle;}
css/visual-form-builder.css ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ form.visual-form-builder{
2
+ font-family:"Lucida Sans",Lucida Sans Unicode,Verdana,Arial,sans-serif;
3
+ margin:20px 0;
4
+ }
5
+ form.visual-form-builder li{width:auto !important;}
6
+ .visual-form-builder ul{
7
+ list-style:none;
8
+ margin:0 14px;
9
+ padding:0;
10
+ font-size:12px;
11
+ }
12
+ .visual-form-builder li{
13
+ clear:both;
14
+ margin:0;
15
+ padding:6px 1% 9px;
16
+ width:64%;
17
+ }
18
+ .visual-form-builder li div span, span.full input, span.full select{
19
+ display:block;
20
+ float:left;
21
+ width:100%;
22
+ }
23
+ .visual-form-builder span.left{
24
+ float:left;
25
+ width:48%;
26
+ }
27
+ .visual-form-builder span.right{
28
+ float:right;
29
+ width:48%;
30
+ }
31
+ .visual-form-builder span.right input, .visual-form-builder span.right select, .visual-form-builder span.left input, .visual-form-builder span.left select{width:100%;}
32
+ .visual-form-builder li div label, .visual-form-builder li span label{font-size:90%;}
33
+ .visual-form-builder fieldset{
34
+ background-color:#eeeeee;
35
+ -webkit-box-shadow:2px 2px 10px #ADADAD;
36
+ -moz-box-shadow:2px 2px 10px #ADADAD;
37
+ box-shadow:2px 2px 10px #ADADAD;
38
+ margin:15px 0;
39
+ clear:both;
40
+ }
41
+ .visual-form-builder .legend{
42
+ margin:5px 14px;
43
+ padding:0 6px;
44
+ color:#990000;
45
+ border-bottom:1px dotted #CCCCCC;
46
+ }
47
+ .visual-form-builder label, label.desc{
48
+ display:block;
49
+ margin:0;
50
+ padding-bottom:3px;
51
+ color:#000;
52
+ }
53
+ label.desc{font-weight:bold;}
54
+ .visual-form-builder label.choice{
55
+ font-size:100%;
56
+ line-height:150%;
57
+ margin:-17px 0 0 23px;
58
+ padding:0 0 5px;
59
+ width:88%;
60
+ }
61
+ .visual-form-builder label span{
62
+ color:#BC1212;
63
+ vertical-align:middle;
64
+ }
65
+ input.text, textarea.textarea, select.select{
66
+ font-size:100%;
67
+ font-family:"Lucida Sans",Lucida Sans Unicode,Verdana,Arial,sans-serif;
68
+ margin:0;
69
+ padding:2px 0;
70
+ }
71
+ input.medium, select.medium{width:50%;}
72
+ input.large, select.large, textarea.textarea{width:100%;}
73
+ textarea.medium{height:10em;}
74
+ .submit{font-size:1.1em;}
75
+ input.checkbox, input.radio{
76
+ font-size:1.1em;
77
+ display:block;
78
+ height:13px;
79
+ width:13px;
80
+ margin:4px 0 0;
81
+ }
82
+ label.error{
83
+ color:red;
84
+ font-weight:bold;
85
+ font-size:90%;
86
+ }
87
+ input.error, select.error, textarea.error{border:1px solid red;}
88
+ p#form_success{
89
+ color:green;
90
+ font-weight:bold;
91
+ }
92
+ #ui-datepicker-div { display: none; }
js/visual-form-builder-validate.js ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+ $( '.visual-form-builder' ).validate({
3
+ rules: {
4
+ secret:{
5
+ maxlength:2
6
+ }
7
+ },
8
+ errorPlacement: function(error, element) {
9
+ if ( element.is( ':radio' ) || element.is( ':checkbox' ) ) {
10
+ error.appendTo( element.parent().parent() );
11
+ }
12
+ else {
13
+ error.insertAfter( element );
14
+ }
15
+ }
16
+ });
17
+
18
+ /* Display jQuery UI date picker */
19
+ $( '.vfb-date-picker' ).datepicker();
20
+ });
js/visual-form-builder.js ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+ /* Field item details box toggle */
3
+ $( '.item-edit' ).click( function( e ){
4
+ $( e.target ).closest( 'li' ).children( '.menu-item-settings' ).slideToggle( 'fast' );
5
+ return false;
6
+ });
7
+
8
+ /* Highlight the shortcode to make easier copying */
9
+ $( '#form-copy-to-clipboard' ).focus( function(){
10
+ this.select();
11
+ });
12
+
13
+
14
+ /* Setup the tabs array */
15
+ var tabsWidth = new Array();
16
+
17
+ /* Set the width of each tab and add extra margins */
18
+ $( '.nav-tab' ).each(function(i){
19
+ if ( i == 0 )
20
+ tabsWidth[i] = Math.abs( $(this).outerWidth() ) + 26;
21
+ else
22
+ tabsWidth[i] = Math.abs( $(this).outerWidth() ) + 6;
23
+ });
24
+
25
+ /* Hide the left arrow on load */
26
+ $( '.nav-tabs-arrow-left' ).hide();
27
+
28
+ var count = 0;
29
+
30
+ /* Move tabs to the right */
31
+ $( '.nav-tabs-arrow-right' ).click( function(){
32
+
33
+ /* First time we click on the right arrow, show the left one */
34
+ if ( count == 0 )
35
+ $( '.nav-tabs-arrow-left' ).show();
36
+
37
+ /* Slide div over one tab at a time */
38
+ $( '.nav-tabs' ).animate({ marginLeft: '-=' + tabsWidth[count] });
39
+
40
+ /* Make sure we always show the + tab */
41
+ if ( count == tabsWidth.length - 2 ) {
42
+ $( this ).hide();
43
+ }
44
+
45
+ count += 1;
46
+ });
47
+
48
+ /* Move tabs to the left */
49
+ $( '.nav-tabs-arrow-left' ).click( function(){
50
+
51
+ count -= 1;
52
+
53
+ /* If we click on the left arrow, show the right one */
54
+ $( '.nav-tabs-arrow-right' ).show();
55
+
56
+ /* If at the beginning (left side), hide the left arrow */
57
+ if ( count == 0 )
58
+ $( this ).hide();
59
+
60
+ /* Slide div back to the left, one tab at a time */
61
+ $( '.nav-tabs' ).animate({ marginLeft: '+=' + tabsWidth[count] });
62
+ });
63
+
64
+
65
+
66
+ /* Handle sorting the field items */
67
+ $( '#menu-to-edit' ).sortable({
68
+ handle: '.menu-item-handle',
69
+ placeholder: 'sortable-placeholder',
70
+ stop: function( event, ui ){
71
+ opts = {
72
+ url: ajaxurl,
73
+ type: 'POST',
74
+ async: true,
75
+ cache: false,
76
+ dataType: 'json',
77
+ data: {
78
+ action: 'visual_form_builder_process_sort',
79
+ order: $( this ).sortable( 'toArray' ).toString()
80
+ },
81
+ success: function( response ) {
82
+ $( '#loading-animation' ).hide(); // Hide the loading animation
83
+ return;
84
+ },
85
+ error: function( xhr,textStatus,e ) { // This can be expanded to provide more information
86
+ alert('There was an error saving the updates');
87
+ $('#loading-animation').hide(); // Hide the loading animation
88
+ return;
89
+ }
90
+ };
91
+
92
+ $.ajax(opts);
93
+ }
94
+ });
95
+
96
+ /* Hide the spinner on load */
97
+ $('img.waiting').hide();
98
+
99
+ /* Show/hide the spinner image when creating a field */
100
+ $( '#submit-create-field' ).click( function(e){
101
+ $.ajax({
102
+ url: ajaxurl,
103
+ async: false,
104
+ success: function( response ) {
105
+ $( 'img.waiting' ).show();
106
+ return;
107
+ }
108
+ });
109
+ });
110
+
111
+ /* Validate the sender details section */
112
+ $( '#visual-form-builder-update' ).validate({
113
+ rules: {
114
+ form_email_subject: {
115
+ required: true
116
+ },
117
+ form_email_from_name: {
118
+ required: true
119
+ },
120
+ form_email_to: {
121
+ required: true,
122
+ multiemail: true
123
+ },
124
+ form_email_from: {
125
+ required: true,
126
+ email: true
127
+ }
128
+ },
129
+ errorPlacement: function( error, element ) {
130
+ error.insertAfter( element.parent() );
131
+ }
132
+ });
133
+
134
+ /* Custom validation method to check multiple emails */
135
+ $.validator.addMethod( 'multiemail', function( value, element ) {
136
+
137
+ /* Return true on an optional element */
138
+ if ( this.optional( element ) )
139
+ return true;
140
+
141
+ /* RegEx for emails - delimiters are commas or semicolons */
142
+ var emails = value.split( new RegExp( '\\s*[,|;]\\s*', 'gi' ) );
143
+
144
+ /* It's valid unless the loop below proves otherwise */
145
+ valid = true;
146
+
147
+ /* Loop through each email and validate as email */
148
+ for ( var i in emails ) {
149
+ value = emails[i];
150
+ valid = valid && jQuery.validator.methods.email.call( this, value, element );
151
+ }
152
+
153
+ return valid;
154
+
155
+ }, 'One or more email addresses are invalid'
156
+ );
157
+ });
readme.txt ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Visual Form Builder ===
2
+ Contributors: mmuro
3
+ Tags: form, forms, form to email, email form, email, input, validation, jquery, shortcode
4
+ Requires at least: 3.0
5
+ Tested up to: 3.2
6
+ Stable tag: 1.0
7
+
8
+ Dynamically build forms using a simple interface. Forms include jQuery validation and a basic logic-based verification system.
9
+
10
+ == Description ==
11
+
12
+ *Visual Form Builder* is a plugin that allows you to build simple contact forms using an easy-to-use and familiar interface.
13
+
14
+ **Features**
15
+
16
+ * Setup and organize your form using a drag-and-drop interface
17
+ * Automatically includes a basic logic-based verification system
18
+ * Send form submissions to multiple emails
19
+ * Utilizes jQuery Form Validation
20
+ * Save time by adding a complete address block field
21
+ * Easy date fields using the jQuery UI Date Picker
22
+
23
+ == Installation ==
24
+
25
+ 1. Upload `visual-form-builder` to the `/wp-content/plugins/` directory
26
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
27
+ 1. Create and configure a form (for help, refer to the FAQ or the Help on the plugin page)
28
+ 1. Copy the form shortcode from the Shortcode box on the plugin page
29
+ 1. Create a new page and add the shortcode to the content.
30
+
31
+ == Frequently Asked Questions ==
32
+
33
+ = How do I build my form? =
34
+
35
+ 1. Click on the + tab, give your form a name and click Create Form.
36
+ 1. Select form fields from the box on the left and click Create Field to add it to your form.
37
+ 1. Edit the information for each form field by clicking on the down arrow.
38
+ 1. Drag and drop the elements to put them in order.
39
+ 1. Click Save Form to save your changes.
40
+
41
+ = What's the deal with the fieldsets? =
42
+
43
+ Fieldsets, a way to group form fields, are an essential piece of this plugin's HTML. As such, at least one fieldset is required and must be first in the order. Subsequent fieldsets may be placed wherever you would like to start your next grouping of fields.
44
+
45
+ = Can I use my own verification system such as a CAPTCHA? =
46
+
47
+ At this time, there is no alternative to the built-in anti-spam system.
48
+
49
+ = How do I customize the CSS? =
50
+
51
+ If you want to customize the appearance of the forms using your own CSS, here's how to do it:
52
+
53
+ 1. Add this code to your theme's `functions.php` file: `add_filter( 'visual-form-builder-css', '__return_false' );`
54
+ 1. Copy everything from `css/visual-form-builder.css` into your theme's `style.css`
55
+ 1. Change the CSS properties in your theme's `style.css` as needed
56
+
57
+ If you want to customize the jQuery date picker CSS, follow these steps:
58
+
59
+ 1. Add this code to your theme's `functions.php` file: `add_filter( 'vfb-date-picker-css', '__return_false' );`
60
+ 1. Refer to the [jQuery UI Date Picker documentation on theming](http://jqueryui.com/demos/datepicker/#theming)
61
+
62
+ = How do I change the Date Picker configuration? =
63
+
64
+ The jQuery UI Date Picker is a complex and highly configurable plugin. By default, Visual Form Builder's date field will use the default options and configuration.
65
+
66
+ To use the more complex features of the Date Picker plugin, you will need to:
67
+
68
+ 1. Add a text field using Visual Form Builder
69
+ 1. Save the form and use the shortcode to add it to a page
70
+ 1. Use your browser to view the HTML source code
71
+ 1. Find the text field you want to use and copy the ID (ex: start-date)
72
+ 1. Using the above example ID, paste the following into your javascript file: `$( '#start-date' ).datepicker();`
73
+ 1. Add and customize the [jQuery UI Date Picker configuration options](http://jqueryui.com/demos/datepicker)
74
+
75
+ == Screenshots ==
76
+
77
+ 1. Visual Form Builder page
78
+ 2. Configuring field item options
79
+
80
+ == Changelog ==
81
+
82
+ **Version 1.0**
83
+
84
+ * Plugin launch!
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
uninstall.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
3
+ exit();
4
+
5
+ global $wpdb;
6
+
7
+ $form_table = $wpdb->prefix . 'visual_form_builder_fields';
8
+ $fields_table = $wpdb->prefix . 'visual_form_builder_forms';
9
+
10
+ $wpdb->query( "DROP TABLE IF EXISTS $form_table" );
11
+ $wpdb->query( "DROP TABLE IF EXISTS $fields_table" );
12
+ ?>
visual-form-builder.php ADDED
@@ -0,0 +1,1238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Visual Form Builder
4
+ Description: Dynamically build forms using a simple interface. Forms include jQuery validation and a basic logic-based verification system.
5
+ Author: Matthew Muro
6
+ Version: 1.0
7
+ */
8
+
9
+ /*
10
+ This program is free software; you can redistribute it and/or modify
11
+ it under the terms of the GNU General Public License as published by
12
+ the Free Software Foundation; version 2 of the License.
13
+
14
+ This program is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ GNU General Public License for more details.
18
+
19
+ You should have received a copy of the GNU General Public License
20
+ along with this program; if not, write to the Free Software
21
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
+ */
23
+
24
+ /* Instantiate new class */
25
+ $visual_form_builder = new Visual_Form_Builder();
26
+
27
+ /* Restrict Categories class */
28
+ class Visual_Form_Builder{
29
+
30
+ public function __construct(){
31
+ global $wpdb;
32
+
33
+ /* Setup global database table names */
34
+ $this->field_table_name = $wpdb->prefix . 'visual_form_builder_fields';
35
+ $this->form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
36
+
37
+ /* Make sure we are in the admin before proceeding. */
38
+ if ( is_admin() ) {
39
+ /* Build options and settings pages. */
40
+ add_action( 'admin_menu', array( &$this, 'add_admin' ) );
41
+ add_action( 'admin_menu', array( &$this, 'save' ) );
42
+ add_action( 'wp_ajax_visual_form_builder_process_sort', array( &$this, 'visual_form_builder_process_sort_callback' ) );
43
+ add_action( 'admin_init', array( &$this, 'add_visual_form_builder_contextual_help' ) );
44
+
45
+ /* Adds a Settings link to the Plugins page */
46
+ add_filter( 'plugin_action_links', array( &$this, 'visual_form_builder_plugin_action_links' ), 10, 2 );
47
+
48
+ /* Load the nav-menu CSS if we're on our plugin page */
49
+ if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'visual-form-builder' )
50
+ wp_admin_css( 'nav-menu' );
51
+
52
+ /* Load the jQuery and CSS we need if we're on our plugin page */
53
+ add_action( 'load-settings_page_visual-form-builder', array( &$this, 'form_admin_scripts' ) );
54
+ add_action( 'load-settings_page_visual-form-builder', array( &$this, 'form_admin_css' ) );
55
+ }
56
+
57
+ add_shortcode( 'vfb', array( &$this, 'form_code' ) );
58
+ add_action( 'init', array( &$this, 'email' ) );
59
+
60
+ /* Add jQuery and CSS to the front-end */
61
+ add_action( 'wp_head', array( &$this, 'form_css' ) );
62
+ add_action( 'template_redirect', array( &$this, 'form_validation' ) );
63
+ }
64
+
65
+ public function form_admin_css(){
66
+ wp_enqueue_style( 'visual-form-builder-style', plugins_url( 'visual-form-builder' ) . '/css/visual-form-builder-admin.css' );
67
+ }
68
+
69
+ public function add_visual_form_builder_contextual_help(){
70
+ $text = "<p><strong>Getting Started</strong></p>
71
+ <ul>
72
+ <li>Click on the + tab, give your form a name and click Create Form.</li>
73
+ <li>Select form fields from the box on the left and click Create Field to add it to your form.</li>
74
+ <li>Edit the information for each form field by clicking on the down arrow.</li>
75
+ <li>Drag and drop the elements to put them in order.</li>
76
+ <li>Click Save Form to save your changes.</li>
77
+ </ul>
78
+ <p><strong>Tips</strong></p>
79
+ <ul>
80
+ <li>Fieldsets, a way to group form fields, are an essential piece of this plugin's HTML. As such, at least one fieldset is required and must be first in the order. Subsequent fieldsets may be placed wherever you would like to start your next grouping of fields.</li>
81
+ <li>Security verification is automatically included on very form. It's a simple logic question and should keep out most, if not all, spam bots.</li>
82
+ <li>There is a hidden spam field, known as a honey pot, that should also help deter potential abusers of your form.</li>
83
+ </ul>";
84
+
85
+ add_contextual_help( 'settings_page_visual-form-builder', $text );
86
+ }
87
+ static function install_db() {
88
+ global $wpdb;
89
+
90
+ $field_table_name = $wpdb->prefix . 'visual_form_builder_fields';
91
+ $form_table_name = $wpdb->prefix . 'visual_form_builder_forms';
92
+
93
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
94
+
95
+ $field_sql = "CREATE TABLE $field_table_name (
96
+ field_id BIGINT(20) NOT NULL AUTO_INCREMENT,
97
+ form_id BIGINT(20) NOT NULL,
98
+ field_key TINYTEXT NOT NULL,
99
+ field_type TINYTEXT NOT NULL,
100
+ field_options TEXT,
101
+ field_description TEXT,
102
+ field_name TINYTEXT NOT NULL,
103
+ field_sequence TINYINT DEFAULT '0',
104
+ field_validation TINYTEXT,
105
+ field_required TINYTEXT,
106
+ field_size TINYTEXT,
107
+ UNIQUE KEY (field_id)
108
+ );";
109
+
110
+
111
+ $form_sql = "CREATE TABLE $form_table_name (
112
+ form_id BIGINT(20) NOT NULL AUTO_INCREMENT,
113
+ form_key TINYTEXT NOT NULL,
114
+ form_title TEXT NOT NULL,
115
+ form_email_subject TEXT,
116
+ form_email_to TEXT,
117
+ form_email_from TEXT,
118
+ form_email_from_name TEXT,
119
+ UNIQUE KEY (form_id)
120
+ );";
121
+
122
+ /* Check to see if the table already exists before creating it */
123
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '$field_table_name'" ) != $field_table_name )
124
+ dbDelta( $field_sql );
125
+
126
+ /* Check to see if the table already exists before creating it */
127
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '$form_table_name'" ) != $form_table_name )
128
+ dbDelta( $form_sql );
129
+ }
130
+
131
+ /**
132
+ * Queue plugin scripts for sorting form fields
133
+ *
134
+ * @since 1.0
135
+ */
136
+ public function form_admin_scripts() {
137
+ wp_enqueue_script( 'jquery-ui-sortable' );
138
+ wp_enqueue_script( 'jquery-form-validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.min.js', array( 'jquery' ), '', true );
139
+ wp_enqueue_script( 'form-elements-add', plugins_url( 'visual-form-builder' ) . '/js/visual-form-builder.js' , array( 'jquery', 'jquery-form-validation' ), '', true );
140
+ }
141
+
142
+ /**
143
+ * Queue form validation scripts
144
+ *
145
+ * @since 1.0
146
+ */
147
+ public function form_validation(){
148
+ wp_enqueue_script( 'jquery-form-validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.min.js', array( 'jquery' ), '', true );
149
+ wp_enqueue_script( 'jquery-ui-core ', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js', array( 'jquery' ), '', true );
150
+ wp_enqueue_script( 'visual-form-builder-validation', plugins_url( 'visual-form-builder' ) . '/js/visual-form-builder-validate.js' , array( 'jquery', 'jquery-form-validation' ), '', true );
151
+ }
152
+
153
+ /**
154
+ * Add form CSS to wp_head
155
+ *
156
+ * @since 1.0
157
+ */
158
+ public function form_css(){
159
+ echo apply_filters( 'visual-form-builder-css', '<link rel="stylesheet" href="' . plugins_url( 'css/visual-form-builder.css', __FILE__ ) . '" type="text/css" />' );
160
+ 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" />' );
161
+ }
162
+
163
+ /**
164
+ * Add Settings link to Plugins page
165
+ *
166
+ * @since 1.8
167
+ * @return $links array Links to add to plugin name
168
+ */
169
+ public function visual_form_builder_plugin_action_links($links, $file){
170
+ if ( $file == plugin_basename(__FILE__) )
171
+ $links[] = '<a href="options-general.php?page=visual-form-builder">'.__('Settings').'</a>';
172
+
173
+ return $links;
174
+ }
175
+
176
+ /**
177
+ * Add options page to Settings menu
178
+ *
179
+ *
180
+ * @since 1.0
181
+ * @uses add_options_page() Creates a menu item under the Settings menu.
182
+ */
183
+ public function add_admin() {
184
+ add_options_page( __('Visual Form Builder', 'visual-form-builder'), __('Visual Form Builder', 'visual-form-builder'), 'create_users', 'visual-form-builder', array( &$this, 'admin' ) );
185
+ }
186
+
187
+
188
+ /**
189
+ * Actions to save, update, and delete forms/form fields
190
+ *
191
+ *
192
+ * @since 1.0
193
+ */
194
+ public function save() {
195
+ global $wpdb;
196
+
197
+ if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'visual-form-builder' && isset( $_REQUEST['action'] ) ) {
198
+
199
+ switch ( $_REQUEST['action'] ) {
200
+ case 'create_form' :
201
+
202
+ $form_id = absint( $_REQUEST['form_id'] );
203
+ $form_key = sanitize_title( $_REQUEST['form_title'] );
204
+ $form_title = esc_html( $_REQUEST['form_title'] );
205
+
206
+ check_admin_referer( 'create_form-' . $form_id );
207
+
208
+ $newdata = array(
209
+ 'form_key' => $form_key,
210
+ 'form_title' => $form_title
211
+ );
212
+
213
+ $this->message = '<div id="message" class="updated"><p>The <strong>' . $form_title . '</strong> form has been created.</p></div>';
214
+
215
+ $wpdb->insert( $this->form_table_name, $newdata );
216
+
217
+ $new_form_selected = $wpdb->insert_id;
218
+
219
+ $initial_fieldset = array(
220
+ 'form_id' => $wpdb->insert_id,
221
+ 'field_key' => 'fieldset',
222
+ 'field_type' => 'fieldset',
223
+ 'field_name' => 'Fieldset',
224
+ 'field_sequence' => 0
225
+ );
226
+
227
+ $wpdb->insert( $this->field_table_name, $initial_fieldset );
228
+
229
+ wp_redirect( 'options-general.php?page=visual-form-builder&form=' . $new_form_selected );
230
+
231
+ break;
232
+
233
+ case 'update_form' :
234
+
235
+ $form_id = absint( $_REQUEST['form_id'] );
236
+ $form_key = sanitize_title( $_REQUEST['form_title'] );
237
+ $form_title = esc_html( $_REQUEST['form_title'] );
238
+ $form_subject = esc_html( $_REQUEST['form_email_subject'] );
239
+ $form_to = serialize( esc_html( $_REQUEST['form_email_to'] ) );
240
+ $form_from = esc_html( $_REQUEST['form_email_from'] );
241
+ $form_from_name = esc_html( $_REQUEST['form_email_from_name'] );
242
+
243
+ check_admin_referer( 'update_form-' . $form_id );
244
+
245
+ $newdata = array(
246
+ 'form_key' => $form_key,
247
+ 'form_title' => $form_title,
248
+ 'form_email_subject' => $form_subject,
249
+ 'form_email_to' => $form_to,
250
+ 'form_email_from' => $form_from,
251
+ 'form_email_from_name' => $form_from_name
252
+ );
253
+
254
+ $where = array(
255
+ 'form_id' => $form_id
256
+ );
257
+
258
+ $wpdb->update( $this->form_table_name, $newdata, $where );
259
+
260
+ /* Loop through each field and update all at once */
261
+ if ( !empty( $_REQUEST['field_id'] ) ) {
262
+ foreach ( $_REQUEST['field_id'] as $id ) {
263
+ $field_name = esc_html( $_REQUEST['field_name-' . $id] );
264
+ $field_key = sanitize_title( $field_name );
265
+ $field_desc = esc_html( $_REQUEST['field_description-' . $id] );
266
+ $field_options = serialize( esc_html( $_REQUEST['field_options-' . $id] ) );
267
+ $field_validation = esc_html( $_REQUEST['field_validation-' . $id] );
268
+ $field_required = esc_html( $_REQUEST['field_required-' . $id] );
269
+ $field_size = esc_html( $_REQUEST['field_size-' . $id] );
270
+
271
+ $field_data = array(
272
+ 'field_key' => $field_key,
273
+ 'field_name' => $field_name,
274
+ 'field_description' => $field_desc,
275
+ 'field_options' => $field_options,
276
+ 'field_validation' => $field_validation,
277
+ 'field_required' => $field_required,
278
+ 'field_size' => $field_size
279
+ );
280
+
281
+ $where = array(
282
+ 'form_id' => absint( $_REQUEST['form_id'] ),
283
+ 'field_id' => $id
284
+ );
285
+
286
+ $wpdb->update( $this->field_table_name, $field_data, $where );
287
+ }
288
+ }
289
+
290
+ $this->message = '<div id="message" class="updated"><p>The <strong>' . $form_title . '</strong> form has been updated.</p></div>';
291
+
292
+ break;
293
+
294
+ case 'delete_form' :
295
+ $id = absint( $_REQUEST['form'] );
296
+ check_admin_referer( 'delete-form-' . $id );
297
+
298
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $this->form_table_name WHERE form_id = %d", $id ) );
299
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $this->field_table_name WHERE form_id = %d", $id ) );
300
+
301
+ $this->message = '<div id="message" class="updated"><p>This form has been deleted.</p></div>';
302
+
303
+ wp_redirect( 'options-general.php?page=visual-form-builder' );
304
+
305
+ break;
306
+
307
+ case 'delete_field' :
308
+ $form_id = absint( $_REQUEST['form'] );
309
+ $field_id = absint( $_REQUEST['field'] );
310
+
311
+ check_admin_referer( 'delete-field-' . $form_id );
312
+
313
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $this->field_table_name WHERE field_id = %d", $field_id ) );
314
+
315
+ $this->message = '<div id="message" class="updated"><p>The field has been deleted.</p></div>';
316
+
317
+ wp_redirect( 'options-general.php?page=visual-form-builder&form=' . $form_id );
318
+
319
+ break;
320
+
321
+ case 'create_field' :
322
+ $form_id = absint( $_REQUEST['form_id'] );
323
+ $field_key = sanitize_title( $_REQUEST['field_name'] );
324
+ $field_name = esc_html( $_REQUEST['field_type'] );
325
+ $field_type = strtolower( esc_html( $_REQUEST['field_type'] ) );
326
+
327
+ check_admin_referer( 'create-field-' . $form_id );
328
+
329
+ $sequence_last_row = $wpdb->get_row( "SELECT field_sequence FROM $this->field_table_name WHERE form_id = $form_id ORDER BY field_sequence DESC LIMIT 1" );
330
+ $field_sequence = ( !empty( $sequence_last_row ) ) ? $sequence_last_row->field_sequence + 1 : 0;
331
+
332
+ $newdata = array(
333
+ 'form_id' => absint( $_REQUEST['form_id'] ),
334
+ 'field_key' => $field_key,
335
+ 'field_name' => $field_name,
336
+ 'field_type' => $field_type,
337
+ 'field_sequence' => $field_sequence
338
+ );
339
+
340
+ $wpdb->insert( $this->field_table_name, $newdata );
341
+
342
+ break;
343
+ }
344
+ }
345
+ }
346
+
347
+ /**
348
+ * The jQuery field sorting callback
349
+ *
350
+ *
351
+ * @since 1.0
352
+ */
353
+ public function visual_form_builder_process_sort_callback() {
354
+
355
+ global $wpdb;
356
+
357
+ $order = explode( ',', $_REQUEST['order'] );
358
+ $i = 0;
359
+
360
+ foreach ( $order as $k => $v ) {
361
+ preg_match( '/(\d+)/', $v, $matches );
362
+
363
+ $wpdb->update( $this->field_table_name, array( 'field_sequence' => $k ), array( 'field_id' => $matches[0] ) );
364
+ $i++;
365
+ }
366
+
367
+ die(1);
368
+ }
369
+
370
+ /**
371
+ * Builds the options settings page
372
+ *
373
+ * @since 1.0
374
+ */
375
+ public function admin() {
376
+ global $wpdb;
377
+
378
+ /* Set variables depending on which tab is selected */
379
+ $form_nav_selected_id = ( isset( $_REQUEST['form'] ) ) ? $_REQUEST['form'] : '0';
380
+ $action = ( isset( $_REQUEST['form'] ) && $_REQUEST['form'] !== '0' ) ? 'update_form' : 'create_form';
381
+
382
+ /* Query to get all forms */
383
+ $order = sanitize_sql_orderby( 'form_id DESC' );
384
+ $query = "SELECT * FROM $this->form_table_name ORDER BY $order";
385
+
386
+ /* Build our forms as an object */
387
+ $forms = $wpdb->get_results( $query );
388
+
389
+ /* Loop through each form and assign a form id, if any */
390
+ foreach ( $forms as $form ) {
391
+ $form_id = ( $form_nav_selected_id == $form->form_id ) ? $form->form_id : '';
392
+ //$form_name = ( $form_nav_selected_id == $form->form_id ) ? $form->form_title : '';
393
+ if ( $form_nav_selected_id == $form->form_id )
394
+ $form_name = stripslashes( $form->form_title );
395
+ }
396
+
397
+
398
+ ?>
399
+
400
+ <div class="wrap">
401
+ <?php screen_icon( 'options-general' ); ?>
402
+ <h2><?php _e('Visual Form Builder', 'visual-form-builder'); ?></h2>
403
+ <?php echo ( isset( $this->message ) ) ? $this->message : ''; ?>
404
+ <div id="nav-menus-frame">
405
+ <div id="menu-settings-column" class="metabox-holder<?php echo ( empty( $form_nav_selected_id ) ) ? ' metabox-holder-disabled' : ''; ?>">
406
+ <div id="side-sortables" class="metabox-holder">
407
+
408
+ <form id="form-items" class="nav-menu-meta" method="post" action="">
409
+ <input name="action" type="hidden" value="create_field" />
410
+ <input name="form_id" type="hidden" value="<?php echo $form_nav_selected_id; ?>" />
411
+ <?php
412
+ /* Security nonce */
413
+ wp_nonce_field( 'create-field-' . $form_nav_selected_id );
414
+
415
+ /* Disable the left box if there's no active form selected */
416
+ $disabled = ( empty( $form_nav_selected_id ) ) ? ' disabled="disabled"' : '';
417
+ ?>
418
+ <div class="postbox">
419
+ <h3 class="hndle"><span>Form Items</span></h3>
420
+ <div class="inside" >
421
+ <div class="taxonomydiv">
422
+ <ul id="taxonomy-category-tabs" class="taxonomy-tabs add-menu-item-tabs">
423
+ <li class="tabs"><a href="#" class="nav-tab-link">Input Type</a></li>
424
+ </ul>
425
+ <div id="input-type" class="tabs-panel tabs-panel-active">
426
+ <ul>
427
+ <li><input type="radio" id="form-element-fieldset" name="field_type" value="Fieldset"<?php echo $disabled; ?> /> Fieldset</li>
428
+ <li><input type="radio" id="form-element-text" name="field_type" value="Text"<?php echo $disabled; ?> /> Text</li>
429
+ <li><input type="radio" id="form-element-textarea" name="field_type" value="Textarea"<?php echo $disabled; ?> /> Textarea</li>
430
+ <li><input type="radio" id="form-element-checkbox" name="field_type" value="Checkbox"<?php echo $disabled; ?> /> Checkbox</li>
431
+ <li><input type="radio" id="form-element-radio" name="field_type" value="Radio"<?php echo $disabled; ?> /> Radio</li>
432
+ <li><input type="radio" id="form-element-select" name="field_type" value="Select"<?php echo $disabled; ?> /> Select</li>
433
+ <li><input type="radio" id="form-element-address" name="field_type" value="Address"<?php echo $disabled; ?> /> Address</li>
434
+ <li><input type="radio" id="form-element-datepicker" name="field_type" value="Date"<?php echo $disabled; ?> /> Date Picker</li>
435
+ </ul>
436
+ </div>
437
+
438
+ <p class="button-controls">
439
+ <span class="add-to-menu">
440
+ <img id="add-to-form" alt="" src="<?php echo admin_url( '/images/wpspin_light.gif' ); ?>" class="waiting" />
441
+ <input type="submit" id="submit-create-field" name="submit" value="Add to Form" class="button-secondary submit-add-to-menu"<?php echo $disabled; ?> />
442
+ </span>
443
+ </p>
444
+ </div>
445
+ </div>
446
+ </div>
447
+ </form>
448
+ <div class="postbox">
449
+ <h3 class="hndle"><span>Form Output</span></h3>
450
+ <div class="inside">
451
+ <div id="customlinkdiv" class="customlinkdiv">
452
+ <p>Copy this shortcode and paste into any Post or Page. <?php echo ( $form_nav_selected_id !== '0') ? "This will display the <strong>$form_name</strong> form." : ''; ?></p>
453
+ <p id="menu-item-url-wrap">
454
+ <form action="">
455
+ <label class="howto">
456
+ <span>Shortcode</span>
457
+ <input id="form-copy-to-clipboard" type="text" class="code menu-item-textbox" value="<?php echo ( $form_nav_selected_id !== '0') ? "[vfb id=$form_nav_selected_id]" : ''; ?>"<?php echo $disabled; ?> style="width:75%;" />
458
+ </label>
459
+ </form>
460
+ </p>
461
+ </div>
462
+ </div>
463
+ </div>
464
+ </div>
465
+ </div>
466
+
467
+ <div id="menu-management-liquid">
468
+ <div id="menu-management">
469
+ <div class="nav-tabs-nav">
470
+ <div class="nav-tabs-arrow nav-tabs-arrow-left"><a>&laquo;</a></div>
471
+ <div class="nav-tabs-wrapper">
472
+ <div class="nav-tabs">
473
+ <?php
474
+ /* Loop through each for and build the tabs */
475
+ foreach ( $forms as $form ) {
476
+ /* Control selected tab */
477
+ if ( $form_nav_selected_id == $form->form_id ) :
478
+ echo '<span class="nav-tab nav-tab-active">' . stripslashes( $form->form_title ) . '</span>';
479
+ $form_id = $form->form_id;
480
+ $form_title = stripslashes( $form->form_title );
481
+ $form_subject = stripslashes( $form->form_email_subject );
482
+ $form_email_from_name = stripslashes( $form->form_email_from_name );
483
+ $form_email_from = stripslashes( $form->form_email_from);
484
+ $form_email_to = unserialize( stripslashes( $form->form_email_to ) );
485
+ else :
486
+ echo '<a href="' .
487
+ esc_url( add_query_arg(
488
+ array(
489
+ 'form' => $form->form_id
490
+ ),
491
+ admin_url( 'options-general.php?page=visual-form-builder' )
492
+ ) ) . '" class="nav-tab" id="' . $form->form_key . '">' . stripslashes( $form->form_title ) . '</a>';
493
+ endif;
494
+
495
+ }
496
+
497
+ /* Displays the build new form tab */
498
+ if ( '0' == $form_nav_selected_id ) :
499
+ ?>
500
+ <span class="nav-tab menu-add-new nav-tab-active"><?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add form' ) ); ?></span>
501
+ <?php else : ?>
502
+ <a href="<?php
503
+ echo esc_url(add_query_arg(
504
+ array(
505
+ 'form' => 0,
506
+ ),
507
+ admin_url( 'options-general.php?page=visual-form-builder' )
508
+ ));
509
+ ?>" class="nav-tab menu-add-new"><?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add form' ) ); ?></a>
510
+ <?php endif; ?>
511
+ </div>
512
+ </div>
513
+ <div class="nav-tabs-arrow nav-tabs-arrow-right"><a>&raquo;</a></div>
514
+ </div>
515
+
516
+ <div class="menu-edit">
517
+ <form method="post" id="visual-form-builder-update" action="">
518
+ <input name="action" type="hidden" value="<?php echo $action; ?>" />
519
+ <input name="form_id" type="hidden" value="<?php echo $form_nav_selected_id; ?>" />
520
+ <?php wp_nonce_field( "$action-$form_nav_selected_id" ); ?>
521
+ <div id="nav-menu-header">
522
+ <div id="submitpost" class="submitbox">
523
+ <div class="major-publishing-actions">
524
+ <label for="form-name" class="menu-name-label howto open-label">
525
+ <span class="sender-labels">Form Name</span>
526
+ <input type="text" value="<?php echo ( isset( $form_title ) ) ? $form_title : ''; ?>" title="Enter form name here" class="menu-name regular-text menu-item-textbox" id="form-name" name="form_title" />
527
+ </label>
528
+ <?php
529
+ /* Display sender details if we're on a form, otherwise just the form name */
530
+ if ( $form_nav_selected_id !== '0' ) :
531
+ ?>
532
+ <br class="clear" />
533
+
534
+ <p><em>The forms you build here will send information to one or more email addresses when submitted by a user on your site. Use the fields below to customize the details of that email.</em></p>
535
+ <label for="form-email-subject" class="menu-name-label howto open-label">
536
+ <span class="sender-labels">E-mail Subject</span>
537
+ <input type="text" value="<?php echo $form_subject; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-subject" name="form_email_subject" />
538
+ </label>
539
+ <br class="clear" />
540
+ <label for="form-email-sender-name" class="menu-name-label howto open-label">
541
+ <span class="sender-labels">Sender Name</span>
542
+ <input type="text" value="<?php echo $form_email_from_name; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-sender-name" name="form_email_from_name" />
543
+ </label>
544
+ <br class="clear" />
545
+ <label for="form-email-sender" class="menu-name-label howto open-label">
546
+ <span class="sender-labels">Sender E-mail</span>
547
+ <input type="text" value="<?php echo $form_email_from; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-sender" name="form_email_from" />
548
+ </label>
549
+ <br class="clear" />
550
+ <label for="form-email-to" class="menu-name-label howto open-label">
551
+ <span class="sender-labels">E-mail(s) To</span>
552
+ <input type="text" value="<?php echo $form_email_to; ?>" class="menu-name regular-text menu-item-textbox" id="form-email-to" name="form_email_to" />
553
+ </label>
554
+ <span><em>(multiple emails separated by commas)</em></span>
555
+ <?php endif; ?>
556
+ <br class="clear" />
557
+ <div class="publishing-action">
558
+ <input type="submit" value="<?php echo ( $action == 'create_form' ) ? 'Create Form' : 'Save Form'; ?>" class="button-primary menu-save" id="save_form" name="save_form" />
559
+ </div>
560
+ <?php if ( !empty( $form_nav_selected_id ) ) : ?>
561
+ <div class="delete-action">
562
+ <a class="submitdelete deletion menu-delete" href="<?php echo esc_url( wp_nonce_url( admin_url('options-general.php?page=visual-form-builder&amp;action=delete_form&amp;form=' . $form_nav_selected_id ), 'delete-form-' . $form_nav_selected_id ) ); ?>"><?php _e('Delete Form'); ?></a>
563
+ </div>
564
+ <?php endif; ?>
565
+ </div>
566
+ </div>
567
+ </div>
568
+ <div id="post-body">
569
+ <div id="post-body-content">
570
+ <?php if ( '0' == $form_nav_selected_id ) : ?>
571
+ <div class="post-body-plain">
572
+ <p>To create a custom form, give it a name above and click Create Form. Then choose form elements from the left column to add to this form.</p>
573
+ <p>After you have added your items, drag and drop to put them in the order you want. You can also click each item to reveal additional configuration options.</p>
574
+ <p>When you have finished building your custom form, make sure you click the Save Form button.</p>
575
+ <p>For more help, click on the Help tab at the top of this page.</p>
576
+ </div>
577
+ <?php else :
578
+
579
+ if ( !empty( $form_nav_selected_id ) && $form_nav_selected_id !== '0' ) :
580
+ echo '<div class="post-body-plain" id="menu-instructions"><p>Select form inputs from the box at left to begin building your custom form. An initial fieldset has been automatically added to get you started.</p></div>';
581
+
582
+ $query_fields = "SELECT * FROM $this->field_table_name WHERE form_id = $form_nav_selected_id ORDER BY field_sequence ASC";
583
+
584
+ $fields = $wpdb->get_results( $query_fields );
585
+
586
+ echo '<ul id="menu-to-edit" class="menu ui-sortable">';
587
+
588
+ foreach ( $fields as $field ) :
589
+ ?>
590
+ <li id="form_item_<?php echo $field->field_id; ?>" class="form-item">
591
+ <dl class="menu-item-bar">
592
+ <dt class="menu-item-handle<?php echo ( $field->field_type == 'fieldset' ) ? ' fieldset' : ''; ?>">
593
+ <span class="item-title"><?php echo stripslashes( $field->field_name ); ?><?php echo ( $field->field_required == 'yes' ) ? ' <span class="is-field-required">*</span>' : ''; ?></span> <span class="item-controls">
594
+ <span class="item-type"><?php echo strtoupper( $field->field_type ); ?></span>
595
+ <a href="#" title="Edit Field Item" id="edit-<?php echo $field->field_id; ?>" class="item-edit">Edit Field Item</a>
596
+ </span>
597
+ </dt>
598
+ </dl>
599
+
600
+ <div id="form-item-settings-<?php echo $field->field_id; ?>" class="menu-item-settings" style="display: none;">
601
+ <?php if ( $field->field_type == 'fieldset' ) : ?>
602
+ <p class="description description-wide">
603
+ <label for="edit-form-item-name-<?php echo $field->field_id; ?>">Legend<br />
604
+ <input type="text" value="<?php echo $field->field_name; ?>" name="field_name-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-name-<?php echo $field->field_id; ?>" />
605
+ </label>
606
+ </p>
607
+ <?php else: ?>
608
+ <p class="description description-wide">
609
+ <label for="edit-form-item-name-<?php echo $field->field_id; ?>">
610
+ Name<br />
611
+ <input type="text" value="<?php echo $field->field_name; ?>" name="field_name-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-name-<?php echo $field->field_id; ?>" />
612
+ </label>
613
+ </p>
614
+ <p class="description description-wide">
615
+ <label for="edit-form-item-description-<?php echo $field->field_id; ?>">
616
+ Description<br />
617
+ <input type="text" value="<?php echo $field->field_description; ?>" name="field_description-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-description-<?php echo $field->field_id; ?>" />
618
+ </label>
619
+ </p>
620
+
621
+ <?php if ( in_array( $field->field_type, array( 'radio', 'checkbox', 'select' ) ) ) : ?>
622
+ <p class="description description-wide">
623
+ <?php
624
+ if ( !empty( $field->field_options ) ) {
625
+ if ( is_serialized( $field->field_options ) ) {
626
+ $opts_vals = unserialize( $field->field_options );
627
+ }
628
+ }
629
+
630
+ ?>
631
+ <label for="edit-form-item-options-<?php echo $field->field_id; ?>">
632
+ Options (separated by commas)<br />
633
+ <input type="text" value="<?php echo $opts_vals; ?>" name="field_options-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-options-<?php echo $field->field_id; ?>" />
634
+ </label>
635
+ </p>
636
+ <?php
637
+ /* Unset the options for any following radio, checkboxes, or selects */
638
+ unset( $opts_vals );
639
+ endif;
640
+ ?>
641
+
642
+ <p class="description description-thin">
643
+ <label for="edit-form-item-validation">
644
+ Validation<br />
645
+ <select name="field_validation-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-validation"<?php echo ( $field->field_type !== 'text' ) ? ' disabled="disabled"' : ''; ?>>
646
+ <option value="" <?php selected( $field->field_validation, '' ); ?>>None</option>
647
+ <option value="email" <?php selected( $field->field_validation, 'email' ); ?>>Email</option>
648
+ <option value="url" <?php selected( $field->field_validation, 'url' ); ?>>URL</option>
649
+ <option value="date" <?php selected( $field->field_validation, 'date' ); ?>>Date</option>
650
+ <option value="number" <?php selected( $field->field_validation, 'number' ); ?>>Number</option>
651
+ <option value="digits" <?php selected( $field->field_validation, 'digits' ); ?>>Digits</option>
652
+ </select>
653
+ </label>
654
+ </p>
655
+ <p class="field-link-target description description-thin">
656
+ <label for="edit-form-item-required">
657
+ Required<br />
658
+ <select name="field_required-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-required-<?php echo $field->field_id; ?>">
659
+ <option value="no" <?php selected( $field->field_required, 'no' ); ?>>No</option>
660
+ <option value="yes" <?php selected( $field->field_required, 'yes' ); ?>>Yes</option>
661
+ </select>
662
+ </label>
663
+ </p>
664
+
665
+ <?php if ( !in_array( $field->field_type, array( 'radio', 'checkbox' ) ) ) : ?>
666
+ <p class="description description-wide">
667
+ <label for="edit-form-item-size">
668
+ Size<br />
669
+ <select name="field_size-<?php echo $field->field_id; ?>" class="widefat" id="edit-form-item-size-<?php echo $field->field_id; ?>">
670
+ <option value="medium" <?php selected( $field->field_size, 'medium' ); ?>>Medium</option>
671
+ <option value="large" <?php selected( $field->field_size, 'large' ); ?>>Large</option>
672
+ </select>
673
+ </label>
674
+ </p>
675
+ <?php endif; ?>
676
+ <?php endif; ?>
677
+ <div class="menu-item-actions description-wide submitbox">
678
+ <a href="<?php echo esc_url( wp_nonce_url( admin_url('options-general.php?page=visual-form-builder&amp;action=delete_field&amp;form=' . $form_nav_selected_id . '&amp;field=' . $field->field_id ), 'delete-field-' . $form_nav_selected_id ) ); ?>" class="item-delete submitdelete deletion">Remove</a>
679
+ </div>
680
+ <input type="hidden" name="field_id[<?php echo $field->field_id; ?>]" value="<?php echo $field->field_id; ?>" />
681
+ </div>
682
+ </li>
683
+ <?php
684
+ endforeach;
685
+ echo '</ul>';
686
+ endif;
687
+ ?>
688
+
689
+ <?php endif; ?>
690
+ </div>
691
+ </div>
692
+ <div id="nav-menu-footer">
693
+ <div class="major-publishing-actions">
694
+ <div class="publishing-action">
695
+ <input type="submit" value="<?php echo ( $action == 'create_form' ) ? 'Create Form' : 'Save Form'; ?>" class="button-primary menu-save" id="save_form" name="save_form" />
696
+ </div>
697
+ </div>
698
+ </div>
699
+ </form>
700
+ </div>
701
+ </div>
702
+ </div>
703
+ </div>
704
+ </div>
705
+ <?php
706
+ }
707
+
708
+ /**
709
+ * Output form via shortcode
710
+ *
711
+ * @since 1.0
712
+ */
713
+ public function form_code( $atts ) {
714
+ global $wpdb;
715
+
716
+ /* Extract shortcode attributes, set defaults */
717
+ extract( shortcode_atts( array(
718
+ 'id' => ''
719
+ ), $atts )
720
+ );
721
+
722
+ $form_id = ( isset( $id ) && !empty( $id ) ) ? $id : $atts[0];
723
+
724
+ $order = sanitize_sql_orderby( 'form_id DESC' );
725
+ $query = "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order";
726
+
727
+ $forms = $wpdb->get_results( $query );
728
+
729
+ $query_fields = "SELECT * FROM $this->field_table_name WHERE form_id = " . $form_id . " ORDER BY field_sequence ASC";
730
+
731
+ $fields = $wpdb->get_results( $query_fields );
732
+
733
+ $open_fieldset = false;
734
+
735
+ if ( isset( $_REQUEST['success'] ) && $_REQUEST['success'] == 1 && wp_verify_nonce( $_REQUEST['key'], 'visual-form-builder-success-nonce' ) ) {
736
+ $output = '<p id="form_success">Your form was successfully submitted. Thank you for contacting us.';
737
+ }
738
+ else {
739
+ foreach ( $forms as $form ) :
740
+
741
+ $output = '<form id="' . $form->form_key . '" class="visual-form-builder" method="post">
742
+ <input type="hidden" name="form_id" value="' . $form->form_id . '" />';
743
+ $output .= wp_nonce_field( 'visual-form-builder-nonce', '_wpnonce', false, false );
744
+
745
+ foreach ( $fields as $field ) {
746
+ if ( $field->field_type == 'fieldset' ) {
747
+ /* Close each fieldset */
748
+ if ( $open_fieldset == true ) {
749
+ $output .= '</ul></fieldset>';
750
+ }
751
+
752
+ $output .= '<fieldset><div class="legend"><h3>' . $field->field_name . '</h3></div><ul>';
753
+ $open_fieldset = true;
754
+ }
755
+ else {
756
+ /* If field is required, build the span and add setup the 'required' class */
757
+ $required_span = ( !empty( $field->field_required ) && $field->field_required === 'yes' ) ? ' <span>*</span>' : '';
758
+ $required = ( !empty( $field->field_required ) && $field->field_required === 'yes' ) ? ' required' : '';
759
+
760
+ $output .= '<li><label for="' . $field->field_key . '" class="desc">'. stripslashes( $field->field_name ) . $required_span . '</label>';
761
+ }
762
+
763
+ switch ( $field->field_type ) {
764
+ case 'text':
765
+
766
+ if ( !empty( $field->field_description ) )
767
+ $output .= '<span><input type="text" name="' . esc_html( $field->field_key ) . '" id="' . esc_html( $field->field_key ) . '" value="" class="text ' . $field->field_size . $required . '" /><label>' . $field->field_description . '</label></span>';
768
+ else
769
+ $output .= '<input type="text" name="' . esc_html( $field->field_key ) . '" id="' . esc_html( $field->field_key ) . '" value="" class="text ' . $field->field_size . $required . '" />';
770
+ break;
771
+
772
+ case 'textarea':
773
+
774
+ if ( !empty( $field->field_description ) )
775
+ $output .= '<span><label>' . $field->field_description . '</label></span>';
776
+
777
+ $output .= '<textarea name="'. $field->field_key. '" id="'. $field->field_key. '" class="textarea ' . $field->field_size . $required . '"></textarea>';
778
+
779
+ break;
780
+
781
+ case 'select':
782
+ if ( !empty( $field->field_description ) )
783
+ $output .= '<span><label>' . $field->field_description . '</label></span>';
784
+
785
+ $output .= '<select name="'. $field->field_key. '" id="'. $field->field_key. '" class="select ' . $field->field_size . $required . '">';
786
+
787
+ $options = explode( ',', unserialize( $field->field_options ) );
788
+
789
+ /* Loop through each option and output */
790
+ foreach ( $options as $option => $value ) {
791
+ $output .= '<option value="' . $value . '">'. $value. '</option>';
792
+ }
793
+
794
+ $output .= '</select>';
795
+
796
+ break;
797
+
798
+ case 'radio':
799
+
800
+ if ( !empty( $field->field_description ) )
801
+ $output .= '<span><label>' . $field->field_description . '</label></span>';
802
+
803
+ $options = explode( ',', unserialize( $field->field_options ) );
804
+ $output .= '<div>';
805
+
806
+ /* Loop through each option and output */
807
+ foreach ( $options as $option => $value ) {
808
+ $output .= '<span>
809
+ <input type="radio" name="'. $field->field_key. '" value="'. $value . '" class="radio ' . $required . '" />'.
810
+ ' <label for="' . $field->field_key . '" class="choice">' . $value . '</label>' .
811
+ '</span>';
812
+ }
813
+
814
+ $output .= '</div>';
815
+
816
+ break;
817
+
818
+ case 'checkbox':
819
+
820
+ if ( !empty( $field->field_description ) )
821
+ $output .= '<span><label>' . $field->field_description . '</label></span>';
822
+
823
+ $options = explode( ',', unserialize( $field->field_options ) );
824
+
825
+ $output .= '<div>';
826
+
827
+ /* Loop through each option and output */
828
+ foreach ( $options as $option => $value ) {
829
+ $output .= '<span><input type="checkbox" name="'. $field->field_key. '" id="'. $field->field_key. '" value="'. $value . '" class="checkbox ' . $required . '" />'.
830
+ ' <label for="' . $field->field_key . '" class="choice">' . $value . '</label></span>';
831
+ }
832
+
833
+ $output .= '</div>';
834
+
835
+ break;
836
+
837
+ case 'address':
838
+
839
+ if ( !empty( $field->field_description ) )
840
+ $output .= '<span><label>' . $field->field_description . '</label></span>';
841
+
842
+ $output .= '<div>
843
+ <span class="full">
844
+
845
+ <input type="text" name="address" maxlength="150" id="address" class="text medium" />
846
+ <label>Address</label>
847
+ </span>
848
+ <span class="full">
849
+ <input type="text" name="address-2" maxlength="150" id="address-2" class="text medium" />
850
+ <label>Address Line 2</label>
851
+ </span>
852
+ <span class="left">
853
+
854
+ <input type="text" name="city" maxlength="150" id="city" class="text medium" />
855
+ <label>City</label>
856
+ </span>
857
+ <span class="right">
858
+ <input type="text" name="state" maxlength="150" id="state" class="text medium" />
859
+ <label>State / Province / Region</label>
860
+ </span>
861
+ <span class="left">
862
+
863
+ <input type="text" name="zip" maxlength="150" id="zip" class="text medium" />
864
+ <label>Postal / Zip Code</label>
865
+ </span>
866
+ <span class="right">
867
+ <select class="select" name="country" id="country">
868
+ <option selected="selected" value=""></option>
869
+ <option value="Afghanistan">Afghanistan</option>
870
+ <option value="Albania">Albania</option>
871
+
872
+ <option value="Algeria">Algeria</option>
873
+ <option value="Andorra">Andorra</option>
874
+ <option value="Angola">Angola</option>
875
+ <option value="Antigua and Barbuda">Antigua and Barbuda</option>
876
+ <option value="Argentina">Argentina</option>
877
+ <option value="Armenia">Armenia</option>
878
+
879
+ <option value="Aruba">Aruba</option>
880
+ <option value="Australia">Australia</option>
881
+ <option value="Austria">Austria</option>
882
+ <option value="Azerbaijan">Azerbaijan</option>
883
+ <option value="Bahamas">Bahamas</option>
884
+ <option value="Bahrain">Bahrain</option>
885
+
886
+ <option value="Bangladesh">Bangladesh</option>
887
+ <option value="Barbados">Barbados</option>
888
+ <option value="Belarus">Belarus</option>
889
+ <option value="Belgium">Belgium</option>
890
+ <option value="Belize">Belize</option>
891
+ <option value="Benin">Benin</option>
892
+
893
+ <option value="Bermuda">Bermuda</option>
894
+ <option value="Bhutan">Bhutan</option>
895
+ <option value="Bolivia">Bolivia</option>
896
+ <option value="Bosnia and Herzegovina">Bosnia and Herzegovina</option>
897
+ <option value="Botswana">Botswana</option>
898
+ <option value="Brazil">Brazil</option>
899
+
900
+ <option value="Brunei">Brunei</option>
901
+ <option value="Bulgaria">Bulgaria</option>
902
+ <option value="Burkina Faso">Burkina Faso</option>
903
+ <option value="Burundi">Burundi</option>
904
+ <option value="Cambodia">Cambodia</option>
905
+ <option value="Cameroon">Cameroon</option>
906
+
907
+ <option value="Canada">Canada</option>
908
+ <option value="Cape Verde">Cape Verde</option>
909
+ <option value="Central African Republic">Central African Republic</option>
910
+ <option value="Chad">Chad</option>
911
+ <option value="Chile">Chile</option>
912
+ <option value="China">China</option>
913
+
914
+ <option value="Colombia">Colombia</option>
915
+ <option value="Comoros">Comoros</option>
916
+ <option value="Democratic Republic of the Congo">Democratic Republic of the Congo</option>
917
+ <option value="Republic of the Congo">Republic of the Congo</option>
918
+ <option value="Cook Islands">Cook Islands</option>
919
+ <option value="Costa Rica">Costa Rica</option>
920
+
921
+ <option value="C&ocirc;te d&lsquo;Ivoire">C&ocirc;te d&lsquo;Ivoire</option>
922
+ <option value="Croatia">Croatia</option>
923
+ <option value="Cuba">Cuba</option>
924
+ <option value="Cyprus">Cyprus</option>
925
+ <option value="Czech Republic">Czech Republic</option>
926
+ <option value="Denmark">Denmark</option>
927
+
928
+ <option value="Djibouti">Djibouti</option>
929
+ <option value="Dominica">Dominica</option>
930
+ <option value="Dominican Republic">Dominican Republic</option>
931
+ <option value="East Timor">East Timor</option>
932
+ <option value="Ecuador">Ecuador</option>
933
+ <option value="Egypt">Egypt</option>
934
+
935
+ <option value="El Salvador">El Salvador</option>
936
+ <option value="Equatorial Guinea">Equatorial Guinea</option>
937
+ <option value="Eritrea">Eritrea</option>
938
+ <option value="Estonia">Estonia</option>
939
+ <option value="Ethiopia">Ethiopia</option>
940
+ <option value="Faroe Islands">Faroe Islands</option>
941
+
942
+ <option value="Fiji">Fiji</option>
943
+ <option value="Finland">Finland</option>
944
+ <option value="France">France</option>
945
+ <option value="Gabon">Gabon</option>
946
+ <option value="Gambia">Gambia</option>
947
+ <option value="Georgia">Georgia</option>
948
+
949
+ <option value="Germany">Germany</option>
950
+ <option value="Ghana">Ghana</option>
951
+ <option value="Gibraltar">Gibraltar</option>
952
+ <option value="Greece">Greece</option>
953
+ <option value="Grenada">Grenada</option>
954
+ <option value="Guatemala">Guatemala</option>
955
+
956
+ <option value="Guinea">Guinea</option>
957
+ <option value="Guinea-Bissau">Guinea-Bissau</option>
958
+ <option value="Guyana">Guyana</option>
959
+ <option value="Haiti">Haiti</option>
960
+ <option value="Honduras">Honduras</option>
961
+ <option value="Hong Kong">Hong Kong</option>
962
+
963
+ <option value="Hungary">Hungary</option>
964
+ <option value="Iceland">Iceland</option>
965
+ <option value="India">India</option>
966
+ <option value="Indonesia">Indonesia</option>
967
+ <option value="Iran">Iran</option>
968
+ <option value="Iraq">Iraq</option>
969
+
970
+ <option value="Ireland">Ireland</option>
971
+ <option value="Israel">Israel</option>
972
+ <option value="Italy">Italy</option>
973
+ <option value="Jamaica">Jamaica</option>
974
+ <option value="Japan">Japan</option>
975
+ <option value="Jordan">Jordan</option>
976
+
977
+ <option value="Kazakhstan">Kazakhstan</option>
978
+ <option value="Kenya">Kenya</option>
979
+ <option value="Kiribati">Kiribati</option>
980
+ <option value="North Korea">North Korea</option>
981
+ <option value="South Korea">South Korea</option>
982
+ <option value="Kuwait">Kuwait</option>
983
+
984
+ <option value="Kyrgyzstan">Kyrgyzstan</option>
985
+ <option value="Laos">Laos</option>
986
+ <option value="Latvia">Latvia</option>
987
+ <option value="Lebanon">Lebanon</option>
988
+ <option value="Lesotho">Lesotho</option>
989
+ <option value="Liberia">Liberia</option>
990
+
991
+ <option value="Libya">Libya</option>
992
+ <option value="Liechtenstein">Liechtenstein</option>
993
+ <option value="Lithuania">Lithuania</option>
994
+ <option value="Luxembourg">Luxembourg</option>
995
+ <option value="Macedonia">Macedonia</option>
996
+ <option value="Madagascar">Madagascar</option>
997
+
998
+ <option value="Malawi">Malawi</option>
999
+ <option value="Malaysia">Malaysia</option>
1000
+ <option value="Maldives">Maldives</option>
1001
+ <option value="Mali">Mali</option>
1002
+ <option value="Malta">Malta</option>
1003
+ <option value="Marshall Islands">Marshall Islands</option>
1004
+
1005
+ <option value="Mauritania">Mauritania</option>
1006
+ <option value="Mauritius">Mauritius</option>
1007
+ <option value="Mexico">Mexico</option>
1008
+ <option value="Micronesia">Micronesia</option>
1009
+ <option value="Moldova">Moldova</option>
1010
+ <option value="Monaco">Monaco</option>
1011
+
1012
+ <option value="Mongolia">Mongolia</option>
1013
+ <option value="Montenegro">Montenegro</option>
1014
+ <option value="Morocco">Morocco</option>
1015
+ <option value="Mozambique">Mozambique</option>
1016
+ <option value="Myanmar">Myanmar</option>
1017
+ <option value="Namibia">Namibia</option>
1018
+
1019
+ <option value="Nauru">Nauru</option>
1020
+ <option value="Nepal">Nepal</option>
1021
+ <option value="Netherlands">Netherlands</option>
1022
+ <option value="Netherlands Antilles">Netherlands Antilles</option>
1023
+ <option value="New Zealand">New Zealand</option>
1024
+ <option value="Nicaragua">Nicaragua</option>
1025
+
1026
+ <option value="Niger">Niger</option>
1027
+ <option value="Nigeria">Nigeria</option>
1028
+ <option value="Norway">Norway</option>
1029
+ <option value="Oman">Oman</option>
1030
+ <option value="Pakistan">Pakistan</option>
1031
+ <option value="Palau">Palau</option>
1032
+
1033
+ <option value="Palestine">Palestine</option>
1034
+ <option value="Panama">Panama</option>
1035
+ <option value="Papua New Guinea">Papua New Guinea</option>
1036
+ <option value="Paraguay">Paraguay</option>
1037
+ <option value="Peru">Peru</option>
1038
+ <option value="Philippines">Philippines</option>
1039
+
1040
+ <option value="Poland">Poland</option>
1041
+ <option value="Portugal">Portugal</option>
1042
+ <option value="Puerto Rico">Puerto Rico</option>
1043
+ <option value="Qatar">Qatar</option>
1044
+ <option value="Romania">Romania</option>
1045
+ <option value="Russia">Russia</option>
1046
+
1047
+ <option value="Rwanda">Rwanda</option>
1048
+ <option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option>
1049
+ <option value="Saint Lucia">Saint Lucia</option>
1050
+ <option value="Saint Vincent and the Grenadines">Saint Vincent and the Grenadines</option>
1051
+ <option value="Samoa">Samoa</option>
1052
+ <option value="San Marino">San Marino</option>
1053
+
1054
+ <option value="Sao Tome and Principe">Sao Tome and Principe</option>
1055
+ <option value="Saudi Arabia">Saudi Arabia</option>
1056
+ <option value="Senegal">Senegal</option>
1057
+ <option value="Serbia and Montenegro">Serbia and Montenegro</option>
1058
+ <option value="Seychelles">Seychelles</option>
1059
+ <option value="Sierra Leone">Sierra Leone</option>
1060
+
1061
+ <option value="Singapore">Singapore</option>
1062
+ <option value="Slovakia">Slovakia</option>
1063
+ <option value="Slovenia">Slovenia</option>
1064
+ <option value="Solomon Islands">Solomon Islands</option>
1065
+ <option value="Somalia">Somalia</option>
1066
+ <option value="South Africa">South Africa</option>
1067
+
1068
+ <option value="Spain">Spain</option>
1069
+ <option value="Sri Lanka">Sri Lanka</option>
1070
+ <option value="Sudan">Sudan</option>
1071
+ <option value="Suriname">Suriname</option>
1072
+ <option value="Swaziland">Swaziland</option>
1073
+ <option value="Sweden">Sweden</option>
1074
+
1075
+ <option value="Switzerland">Switzerland</option>
1076
+ <option value="Syria">Syria</option>
1077
+ <option value="Taiwan">Taiwan</option>
1078
+ <option value="Tajikistan">Tajikistan</option>
1079
+ <option value="Tanzania">Tanzania</option>
1080
+ <option value="Thailand">Thailand</option>
1081
+
1082
+ <option value="Togo">Togo</option>
1083
+ <option value="Tonga">Tonga</option>
1084
+ <option value="Trinidad and Tobago">Trinidad and Tobago</option>
1085
+ <option value="Tunisia">Tunisia</option>
1086
+ <option value="Turkey">Turkey</option>
1087
+ <option value="Turkmenistan">Turkmenistan</option>
1088
+
1089
+ <option value="Tuvalu">Tuvalu</option>
1090
+ <option value="Uganda">Uganda</option>
1091
+ <option value="Ukraine">Ukraine</option>
1092
+ <option value="United Arab Emirates">United Arab Emirates</option>
1093
+ <option value="United Kingdom">United Kingdom</option>
1094
+ <option value="United States">United States</option>
1095
+
1096
+ <option value="Uruguay">Uruguay</option>
1097
+ <option value="Uzbekistan">Uzbekistan</option>
1098
+ <option value="Vanuatu">Vanuatu</option>
1099
+ <option value="Vatican City">Vatican City</option>
1100
+ <option value="Venezuela">Venezuela</option>
1101
+ <option value="Vietnam">Vietnam</option>
1102
+
1103
+ <option value="Yemen">Yemen</option>
1104
+ <option value="Zambia">Zambia</option>
1105
+ <option value="Zimbabwe">Zimbabwe</option>
1106
+ </select>
1107
+ <label>Country</label>
1108
+ </span>
1109
+ </div>';
1110
+
1111
+
1112
+ break;
1113
+
1114
+ case 'date':
1115
+
1116
+ if ( !empty( $field->field_description ) )
1117
+ $output .= '<span><input type="text" name="' . esc_html( $field->field_key ) . '" id="' . esc_html( $field->field_key ) . '" value="" class="text vfb-date-picker ' . $field->field_size . $required . '" /><label>' . $field->field_description . '</label></span>';
1118
+ else
1119
+ $output .= '<input type="text" name="' . esc_html( $field->field_key ) . '" id="' . esc_html( $field->field_key ) . '" value="" class="text vfb-date-picker ' . $field->field_size . $required . '" />';
1120
+
1121
+ break;
1122
+ }
1123
+
1124
+ $output .= '</li>';
1125
+ }
1126
+
1127
+ $output .= '</ul></fieldset>';
1128
+
1129
+ $output .= '<fieldset>
1130
+ <div class="legend">
1131
+ <h3>Verification</h3>
1132
+ </div>
1133
+ <ul>
1134
+ <li>
1135
+ <label class="desc">Please enter any two digits with <strong>no</strong> spaces (Example: 12) <span>*</span></label>
1136
+ <div>
1137
+ <input type="text" name="secret" id="secret" class="text medium required digits" />
1138
+ </div>
1139
+ </li>
1140
+ <div style="display:none;">
1141
+ <li>
1142
+ <label for="spam">This box is for spam protection - <strong>please leave it blank</strong>:</label>
1143
+ <div>
1144
+ <input name="spam" id="spam" />
1145
+ </div>
1146
+ </li>
1147
+ </div>
1148
+ <li>
1149
+ <input type="submit" name="visual-form-builder-submit" value="Submit" class="submit" id="sendmail" />
1150
+ </li>
1151
+ </ul>
1152
+ </fieldset></form>';
1153
+
1154
+ endforeach;
1155
+ }
1156
+
1157
+ return $output;
1158
+ }
1159
+
1160
+ /**
1161
+ * Handle emailing the content
1162
+ *
1163
+ * @since 1.0
1164
+ * @uses wp_mail() E-mails a message
1165
+ */
1166
+ public function email() {
1167
+ global $wpdb, $post;
1168
+
1169
+ /* Resets the options */
1170
+ if ( isset( $_REQUEST['visual-form-builder-submit'] ) && $_REQUEST['visual-form-builder-submit'] == 'Submit' && $_REQUEST['spam'] == '' && is_numeric( $_REQUEST['secret'] ) && strlen( $_REQUEST['secret'] ) == 2 ) {
1171
+ $nonce = $_REQUEST['_wpnonce'];
1172
+
1173
+ /* Security check to verify the nonce */
1174
+ if ( ! wp_verify_nonce( $nonce, 'visual-form-builder-nonce' ) )
1175
+ die(__('Security check'));
1176
+
1177
+ /* Set submitted action to display success message */
1178
+ $this->submitted = true;
1179
+
1180
+ $form_id = absint( $_REQUEST['form_id'] );
1181
+
1182
+ /* Query to get all forms */
1183
+ $order = sanitize_sql_orderby( 'form_id DESC' );
1184
+ $query = "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order";
1185
+
1186
+ /* Build our forms as an object */
1187
+ $forms = $wpdb->get_results( $query );
1188
+
1189
+ foreach ( $forms as $form ) {
1190
+ $form_title = $form->form_title;
1191
+ $form_subject = $form->form_email_subject;
1192
+ $form_to = explode( ',', unserialize( $form->form_email_to ) );
1193
+ $form_from = $form->form_email_from;
1194
+ $form_from_name = $form->form_email_from_name;
1195
+ }
1196
+
1197
+ /* Prepare the beginning of the content */
1198
+ $message = '<html><body><table rules="all" style="border-color: #666;" cellpadding="10">';
1199
+
1200
+ /* Loop through each form field and build the body of the message */
1201
+ foreach ( $_POST as $key => $value ) {
1202
+ $key = strtolower( str_replace( '-', ' ', $key ) );
1203
+
1204
+ $value = esc_html( $value );
1205
+
1206
+ if ( !in_array( $key, array( 'spam', 'secret', 'visual form builder submit', '_wpnonce', 'form_id' ) ) )
1207
+ $message .= '<tr><td><strong>' . ucwords( $key ) . ': </strong></td><td>' . $value . '</td></tr>';
1208
+ }
1209
+
1210
+ /* Close out the content */
1211
+ $message .= '</table></body></html>';
1212
+
1213
+ /* Set headers to send an HTML email */
1214
+ $headers = "MIME-Version: 1.0\n".
1215
+ "From: " . $form_from_name . " <" . $form_from . ">\n" .
1216
+ "Content-Type: text/html; charset=\"" . get_settings( 'blog_charset' ) . "\"\n";
1217
+
1218
+ /* Send the mail */
1219
+ foreach ( $form_to as $email ) {
1220
+ $mail_sent = wp_mail( $email, esc_html( $form_subject ), $message, $headers );
1221
+ }
1222
+
1223
+ /* If a successful response, append a GET var to trigger the success message */
1224
+ if ( $mail_sent ) {
1225
+ $success_nonce = wp_create_nonce( 'visual-form-builder-success-nonce' );
1226
+ $sent = '?success=1&key=' . $success_nonce;
1227
+ }
1228
+
1229
+ /* Redirect to the same page with the appended success message */
1230
+ wp_redirect( get_permalink( $post->ID ) . $sent );
1231
+
1232
+ exit();
1233
+ }
1234
+ }
1235
+ }
1236
+
1237
+ register_activation_hook(__FILE__, array( 'Visual_Form_Builder', 'install_db' ) );
1238
+ ?>