PluginProbe
Webling / 3.2.0
Webling v3.2.0
trunk 2.0 3.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.3.0 3.4.0 3.4.1 3.5.0 3.6.0 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.9.0 3.9.1 3.9.2
webling / src / admin / actions / save_form.php

save_form.php in Webling 3.2.0, at src/admin/actions/save_form.php

151 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 function webling_admin_save_form()
4 {
5 global $wpdb;
6
7 $_POST = stripslashes_deep($_POST);
8
9 // sanitize id
10 $id = intval($_POST['form_id']);
11
12 if ($id) {
13
14 // check if form exists
15 $existing = $wpdb->get_row("SELECT id from {$wpdb->prefix}webling_forms WHERE id = ".$id);
16 if (!$existing) {
17 die('Could not update form: form does not exist: '.$id);
18 }
19
20 // update form
21 $wpdb->query(
22 $wpdb->prepare("
23 UPDATE {$wpdb->prefix}webling_forms
24 SET
25 `title` = %s,
26 `group_id` = %d,
27 `notification_email` = %s,
28 `confirmation_text` = %s,
29 `submit_button_text` = %s,
30 `confirmation_email_enabled` = %d,
31 `confirmation_email_subject` = %s,
32 `confirmation_email_text` = %s,
33 `confirmation_email_webling_field` = %d,
34 `class` = %s
35 WHERE id = %d",
36 $_POST['title'],
37 intval($_POST['group_id']),
38 $_POST['notification_email'],
39 $_POST['confirmation_text'],
40 $_POST['submit_button_text'],
41 ($_POST['confirmation_email_enabled'] ? 1 : 0),
42 $_POST['confirmation_email_subject'],
43 $_POST['confirmation_email_text'],
44 intval($_POST['confirmation_email_webling_field']),
45 $_POST['class'],
46 $id
47 )
48 );
49
50 } else {
51 // create form
52 $wpdb->query(
53 $wpdb->prepare("
54 INSERT INTO {$wpdb->prefix}webling_forms
55 (
56 `title`,
57 `group_id`,
58 `notification_email`,
59 `confirmation_text`,
60 `submit_button_text`,
61 `confirmation_email_enabled`,
62 `confirmation_email_subject`,
63 `confirmation_email_text`,
64 `confirmation_email_webling_field`,
65 `class`
66 ) VALUES (
67 %s,
68 %d,
69 %s,
70 %s,
71 %s,
72 %d,
73 %s,
74 %s,
75 %d,
76 %s
77 )",
78 $_POST['title'],
79 intval($_POST['group_id']),
80 $_POST['notification_email'],
81 $_POST['confirmation_text'],
82 $_POST['submit_button_text'],
83 ($_POST['confirmation_email_enabled'] ? 1 : 0),
84 $_POST['confirmation_email_subject'],
85 $_POST['confirmation_email_text'],
86 intval($_POST['confirmation_email_webling_field']),
87 $_POST['class']
88 )
89 );
90
91 // update created_at field
92 $wpdb->query(
93 $wpdb->prepare("
94 UPDATE {$wpdb->prefix}webling_forms set `created_at` = `updated_at` WHERE id = %d",
95 $wpdb->insert_id
96 )
97 );
98
99 // set $id to newly created id
100 $id = $wpdb->insert_id;
101 }
102
103 $wpdb->query("DELETE FROM {$wpdb->prefix}webling_form_fields WHERE form_id = ".$id);
104
105 if (is_array($_POST['fields'])) {
106 foreach ($_POST['fields'] as $field_id => $field) {
107 if (intval($field['order']) > 0) {
108 $required = $show_all_groups = (isset($field['required']) ? 1 : 0);
109 $wpdb->query(
110 $wpdb->prepare("
111 INSERT INTO {$wpdb->prefix}webling_form_fields
112 (
113 `form_id`,
114 `order`,
115 `webling_field_id`,
116 `required`,
117 `field_name`,
118 `field_name_position`,
119 `placeholder_text`,
120 `description_text`,
121 `class`
122 ) VALUES (
123 %d,
124 %d,
125 %d,
126 %d,
127 %s,
128 %s,
129 %s,
130 %s,
131 %s
132 )",
133 $id,
134 intval($field['order']),
135 intval($field['webling_field_id']),
136 $required,
137 $field['field_name'],
138 $field['field_name_position'],
139 $field['placeholder_text'],
140 $field['description_text'],
141 $field['class']
142 )
143 );
144 }
145 }
146 }
147
148 wp_redirect(admin_url('admin.php?page=webling_page_main'));
149 exit;
150 }
151