PluginProbe
Webling / 3.0
Webling v3.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.0, at src/admin/actions/save_form.php

123 lines 2.4 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 `class` = %s
31 WHERE id = %d",
32 $_POST['title'],
33 intval($_POST['group_id']),
34 $_POST['notification_email'],
35 $_POST['confirmation_text'],
36 $_POST['submit_button_text'],
37 $_POST['class'],
38 $id
39 )
40 );
41
42 } else {
43 // create form
44 $wpdb->query(
45 $wpdb->prepare("
46 INSERT INTO {$wpdb->prefix}webling_forms
47 (
48 `title`,
49 `group_id`,
50 `notification_email`,
51 `confirmation_text`,
52 `submit_button_text`,
53 `class`
54 ) VALUES (
55 %s,
56 %d,
57 %s,
58 %s,
59 %s,
60 %s
61 )",
62 $_POST['title'],
63 intval($_POST['group_id']),
64 $_POST['notification_email'],
65 $_POST['confirmation_text'],
66 $_POST['submit_button_text'],
67 $_POST['class']
68 )
69 );
70
71 // set $id to newly created id
72 $id = $wpdb->insert_id;
73 }
74
75 $wpdb->query("DELETE FROM {$wpdb->prefix}webling_form_fields WHERE form_id = ".$id);
76
77 if (is_array($_POST['fields'])) {
78 foreach ($_POST['fields'] as $field_id => $field) {
79 if (intval($field['order']) > 0) {
80 $required = $show_all_groups = (isset($field['required']) ? 1 : 0);
81 $wpdb->query(
82 $wpdb->prepare("
83 INSERT INTO {$wpdb->prefix}webling_form_fields
84 (
85 `form_id`,
86 `order`,
87 `webling_field_id`,
88 `required`,
89 `field_name`,
90 `field_name_position`,
91 `placeholder_text`,
92 `description_text`,
93 `class`
94 ) VALUES (
95 %d,
96 %d,
97 %d,
98 %d,
99 %s,
100 %s,
101 %s,
102 %s,
103 %s
104 )",
105 $id,
106 intval($field['order']),
107 intval($field['webling_field_id']),
108 $required,
109 $field['field_name'],
110 $field['field_name_position'],
111 $field['placeholder_text'],
112 $field['description_text'],
113 $field['class']
114 )
115 );
116 }
117 }
118 }
119
120 wp_redirect(admin_url('admin.php?page=webling_page_main'));
121 exit;
122 }
123