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