PluginProbe
Custom Contact Forms / 1.2.0
Custom Contact Forms v1.2.0
7.16.1 7.16 7.15.2 7.15.0 7.14.0 7.13.0 7.11.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 2.0.1 2.0.2 2.0.3 2.1.0 2.2.0 2.2.3 2.2.4 2.2.5 3.0.0 All 171 releases
custom-contact-forms / custom-contact-forms.php

custom-contact-forms.php in Custom Contact Forms 1.2.0, at custom-contact-forms.php

663 lines 36.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Custom Contact Forms
4 Plugin URI: http://taylorlovett.com/wordpress-plugins
5 Description: Custom Contact Forms is a plugin for handling and displaying custom web forms [customcontact form=1] in any page, post, category, or archive in which you want the form to show. This plugin allows you to create fields with a variety of options and to attach them to specific forms you create; definitely allows for more customization than any other Wordpress Contact Form plugin; comes with a customizable captcha spam blocker! Also comes with a web form widget to drag-and-drop in to your sidebar. <a href="options-general.php?page=custom-contact-forms" title="Maryland Wordpress Developer">Plugin Settings</a>
6 Version: 1.2.0
7 Author: <a href="http://www.taylorlovett.com" title="Maryland Wordpress Developer">Taylor Lovett</a>
8 Author URI: http://www.taylorlovett.com
9 Contributors: Taylor Lovett
10 */
11 /*
12 Copyright (C) 2010-2011 Taylor Lovett, taylorlovett.com (admin@taylorlovett.com)
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3 of the License, or
16 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 */
24 require_once('custom-contact-forms-db.php');
25 require_once('custom-contact-forms-mailer.php');
26 require_once('custom-contact-forms-images.php');
27 if (!class_exists('CustomContactForms')) {
28 class CustomContactForms extends CustomContactFormsDB {
29 var $adminOptionsName = 'customContactFormsAdminOptions';
30 var $widgetOptionsName = 'widget_customContactForms';
31 var $version = '1.1.0';
32 var $errors;
33 var $error_return;
34 var $fixed_fields = array('customcontactforms_submit', 'fid', 'form_page', 'captcha');
35
36 function CustomContactForms() {
37 parent::CustomContactFormsDB();
38 $this->errors = array();
39 }
40
41 function getAdminOptions() {
42 $admin_email = get_option('admin_email');
43 $customcontactAdminOptions = array('show_widget_home' => 1, 'show_widget_pages' => 1, 'show_widget_singles' => 1, 'show_widget_categories' => 1, 'show_widget_archives' => 1, 'default_to_email' => $admin_email, 'default_from_email' => $admin_email, 'default_form_subject' => 'Someone Filled Out Your Contact Form!', 'custom_thank_you' => '', 'thank_you_message' => 'Thank you for filling out our form. We will respond to your inquiry ASAP.', 'remember_field_values' => 0); // defaults
44 $customcontactOptions = get_option($this->adminOptionsName);
45 if (!empty($customcontactOptions)) {
46 foreach ($customcontactOptions as $key => $option)
47 $customcontactAdminOptions[$key] = $option;
48 }
49 update_option($this->adminOptionsName, $customcontactAdminOptions);
50 return $customcontactAdminOptions;
51 }
52 function init() {
53 $this->getAdminOptions();
54 $this->registerSidebar();
55 }
56 function registerSidebar() {
57 register_sidebar_widget(__('Custom Contact Form'), array($this, 'widget_customContactForms'));
58 register_widget_control('Custom Contact Form', array($this, 'customContactForms_control'), 300, 200);
59 }
60 function customContactForms_control() {
61 $option = get_option($this->widgetOptionsName);
62 if (empty($option)) $option = array('widget_form_id' => '0');
63 if ($_POST[widget_form_id]) {
64 $option[widget_form_id] = $_POST[widget_form_id];
65 update_option($this->widgetOptionsName, $option);
66 $option = get_option($this->widgetOptionsName);
67 }
68 $forms = parent::selectAllForms();
69
70 $form_options = '';
71 foreach ($forms as $form) {
72 $sel = ($option[widget_form_id] == $form->id) ? ' selected="selected"' : '';
73 $form_options .= '<option value="'.$form->id.'"'.$sel.'>'.$form->form_slug.'</option>';
74 }
75 if (empty($form_options)) { ?>
76 <p>Create a form in the Custom Contact Forms settings page.</p>
77 <?php
78 } else {
79 ?>
80 <p>
81 <label for="widget_form_id">Show Form:</label>
82 <select name="widget_form_id">
83 <?php echo $form_options; ?>
84 </select>
85 </p>
86 <?php
87 }
88 }
89 function widget_customContactForms($args) {
90 extract($args);
91 $admin_option = $this->getAdminOptions();
92 if ((is_front_page() and $admin_option[show_widget_home] != 1) or (is_single() and $admin_option[show_widget_singles] != 1) or
93 (is_page() and $admin_option[show_widget_pages] != 1) or (is_category() and $admin_option[show_widget_categories] != 1) or
94 (is_archive() and $admin_option[show_widget_archives] != 1))
95 return false;
96 $option = get_option($this->widgetOptionsName);
97 if (empty($option) or $option[widget_form_id] < 1) return false;
98 echo $before_widget . $this->getFormCode($option[widget_form_id], true, $args) . $after_widget;
99 }
100 function addHeaderCode() {
101 ?>
102 <!-- Custom Contact Forms by Taylor Lovett - http://www.taylorlovett.com -->
103 <link rel="stylesheet" href="<?php echo get_option('siteurl'); ?>/wp-content/plugins/custom-contact-forms/custom-contact-forms.css" type="text/css" media="screen" />
104 <?php
105 }
106
107 function setError($key, $message) {
108 $this->errors[$key] = $message;
109 }
110
111 function getError($key) {
112 return $this->errors[$key];
113 }
114
115 function getAllErrors() {
116 return $this->errors;
117 }
118
119 function printAdminPage() {
120 $admin_options = $this->getAdminOptions();
121 if ($_POST[form_create]) {
122 parent::insertForm($_POST[form_slug], $_POST[form_title], $_POST[form_action], $_POST[form_method], $_POST[submit_button_text], $_POST[custom_code]);
123 } elseif ($_POST[field_create]) {
124 parent::insertField($_POST[field_slug], $_POST[field_label], $_POST[field_type], $_POST[field_value], $_POST[field_maxlength], 1);
125 } elseif ($_POST[general_settings]) {
126 $admin_options[default_to_email] = $_POST[default_to_email];
127 $admin_options[default_from_email] = $_POST[default_from_email];
128 $admin_options[default_form_subject] = $_POST[default_form_subject];
129 $admin_options[show_widget_categories] = $_POST[show_widget_categories];
130 $admin_options[show_widget_singles] = $_POST[show_widget_singles];
131 $admin_options[show_widget_pages] = $_POST[show_widget_pages];
132 $admin_options[show_widget_archives] = $_POST[show_widget_archives];
133 $admin_options[show_widget_home] = $_POST[show_widget_home];
134 $admin_options[custom_thank_you] = $_POST[custom_thank_you];
135 $admin_options[thank_you_message] = $_POST[thank_you_message];
136 update_option($this->adminOptionsName, $admin_options);
137 } elseif ($_POST[field_edit]) {
138 parent::updateField($_POST[field_slug], $_POST[field_label], $_POST[field_type], $_POST[field_value], $_POST[field_maxlength], $_POST[fid]);
139 } elseif ($_POST[field_delete]) {
140 parent::deleteField($_POST[fid]);
141 } elseif ($_POST[form_delete]) {
142 parent::deleteForm($_POST[fid]);
143 } elseif ($_POST[form_edit]) {
144 parent::updateForm($_POST[form_slug], $_POST[form_title], $_POST[form_action], $_POST[form_method], $_POST[submit_button_text], $_POST[custom_code], $_POST[fid]);
145 } elseif ($_POST[form_add_field]) {
146 parent::addFieldToForm($_POST[field_id], $_POST[fid]);
147 } elseif ($_POST[disattach_field]) {
148 parent::disattachField($_POST[disattach_field_id], $_POST[fid]);
149 }
150 ?>
151 <div id="customcontactforms-admin">
152 <div id="icon-themes" class="icon32"></div>
153 <h2>Custom Contact Forms</h2>
154 <div id="upgrade">
155 <p>Want to <i>change the appearance of your forms</i> with a simple to use manager? The Style Manager allows style every aspect of your form: <b>Change form border style, form border width, form width, form font family, title font size, title font color, text field width, text field border color, text field font size, text field font color, submit button width/height, submit button font color, and more!</b></p>
156 <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
157 <input type="hidden" name="cmd" value="_s-xclick">
158 <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHkAYJKoZIhvcNAQcEoIIHgTCCB30CAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAa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vcNAQkEMRYEFOvPtjEkUXc+Sw5MJGO6wBnV+NaEMA0GCSqGSIb3DQEBAQUABIGAv2yfD9m3B4byAv1I9IW8YEZz8HRus2VeGaqbYwnO6pK6FAG36fBkIF5jHvCerCBmn31YfU3EF1xKYC97Aw3sQN5CScofqY2kU3l5dySkyqScGwIsLn0oGYc9LSoSR00K07rl80KVF2gNSrQYAOh3ScLTmSc5MaQfS0z7jkuNbGk=-----END PKCS7-----
159 ">
160 <p class="head center">Upgrade to the Pro Version for $5.00 USD:</p><input style="margin-left:400px;" class="center" type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
161 <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
162 </form>
163 </div>
164 <div id="create-fields" class="postbox">
165 <h3 class="hndle"><span>Create A Form Field</span></h3>
166 <div class="inside">
167 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
168 <ul>
169 <li>
170 <label for="field_slug">* Slug (Name):</label>
171 <input name="field_slug" type="text" maxlength="50" />
172 (Must be unique)</li>
173 <li>
174 <label for="field_label">Field Label:</label>
175 <input name="field_label" type="text" maxlength="100" />
176 </li>
177 <li>
178 <label for="field_type">* Field Type:</label>
179 <select name="field_type">
180 <option>Text</option>
181 <option>Textarea</option>
182 <option>Hidden</option>
183 <option>Checkbox</option>
184 </select>
185 </li>
186 <li>
187 <label for="field_value">Initial Value:</label>
188 <input name="field_value" type="text" maxlength="50" />
189 </li>
190 <li>
191 <label for="field_maxlength">Max Length:</label>
192 <input class="width50" size="10" name="field_maxlength" type="text" maxlength="4" />
193 (0 for no limit; only applies to Text fields)</li>
194 <li>
195 <input type="submit" value="Create Field" name="field_create" />
196 </li>
197 </ul>
198 </form>
199 </div>
200 </div>
201 <div id="create-forms" class="postbox">
202 <h3 class="hndle"><span>Create A Form</span></h3>
203 <div class="inside">
204 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
205 <ul>
206 <li>
207 <label for="form_name">Form Slug:</label>
208 <input type="text" maxlength="100" name="form_slug" />
209 (Must be unique)</li>
210 <li>
211 <label for="form_title">Form Title:</label>
212 <input type="text" maxlength="200" name="form_title" />
213 (The form header text)</li>
214 <li>
215 <label for="form_method">Form Method:</label>
216 <select name="form_method">
217 <option>Post</option>
218 <option>Get</option>
219 </select>
220 (If unsure, leave as is.)</li>
221 <li>
222 <label for="form_action">Form Action:</label>
223 <input type="text" name="form_action" value="" />
224 (If unsure, leave blank.)</li>
225 <li>
226 <label for="submit_button_text">Submit Button Text:</label>
227 <input type="text" maxlength="200" name="submit_button_text" />
228 </li>
229 <li>
230 <label for="custom_code">Custom Code:</label>
231 <input type="text" name="custom_code" />
232 (If unsure, leave blank.)</li>
233 <li>
234 <input type="submit" value="Create Form" name="form_create" />
235 </li>
236 </ul>
237 </form>
238 </div>
239 </div>
240 <h3 class="manage-h3">Manage User Fields</h3>
241 <table class="widefat post" id="manage-fields" cellspacing="0">
242 <thead>
243 <tr>
244 <th scope="col" class="manage-column field-slug">Slug</th>
245 <th scope="col" class="manage-column field-label">Label</th>
246 <th scope="col" class="manage-column field-type">Type</th>
247 <th scope="col" class="manage-column field-value">Initial Value</th>
248 <th scope="col" class="manage-column field-maxlength">Maxlength</th>
249 <th scope="col" class="manage-column field-action">Action</th>
250 </tr>
251 </thead>
252 <tbody>
253 <?php
254 $fields = parent::selectAllFields();
255 for ($i = 0; $i < count($fields); $i++) {
256 if ($fields[$i]->user_field == 0) continue;
257 $field_types = '<option>Text</option><option>Textarea</option><option>Hidden</option><option>Checkbox</option>';
258 $field_types = str_replace('<option>'.$fields[$i]->field_type.'</option>', '<option selected="selected">'.$fields[$i]->field_type.'</option>', $field_types);
259
260 ?>
261 <tr<?php if ($i % 2 == 0) echo ' class="evenrow"'; ?>>
262 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
263 <td><input type="text" name="field_slug" maxlength="50" value="<?php echo $fields[$i]->field_slug; ?>" /></td>
264 <td><input type="text" name="field_label" maxlength="100" value="<?php echo $fields[$i]->field_label; ?>" /></td>
265 <td><select name="field_type">
266 <?php echo $field_types; ?>
267 </select></td>
268 <td><input type="text" name="field_value" maxlength="50" value="<?php echo $fields[$i]->field_value; ?>" /></td>
269 <td><input type="text" class="width50" name="field_maxlength" value="<?php echo $fields[$i]->field_maxlength; ?>" /></td>
270 <td><input type="hidden" name="fid" value="<?php echo $fields[$i]->id; ?>" />
271 <input type="submit" name="field_edit" value="Edit" />
272 <input type="submit" name="field_delete" value="Delete" /></td>
273 </form>
274 </tr>
275 <?php
276 }
277 ?>
278 </tbody>
279 <tfoot>
280 <tr>
281 <th scope="col" class="manage-column field-slug">Slug</th>
282 <th scope="col" class="manage-column field-label">Label</th>
283 <th scope="col" class="manage-column field-type">Type</th>
284 <th scope="col" class="manage-column field-value">Initial Value</th>
285 <th scope="col" class="manage-column field-maxlength">Maxlength</th>
286 <th scope="col" class="manage-column field-action">Action</th>
287 </tr>
288 </tfoot>
289 </table>
290 <h3 class="manage-h3">Manage Fixed Fields</h3>
291 <table class="widefat post" id="manage-fixed-fields" cellspacing="0">
292 <thead>
293 <tr>
294 <th scope="col" class="manage-column field-slug">Slug</th>
295 <th scope="col" class="manage-column field-label">Label</th>
296 <th scope="col" class="manage-column field-type">Type</th>
297 <th scope="col" class="manage-column field-value">Initial Value</th>
298 <th scope="col" class="manage-column field-maxlength">Maxlength</th>
299 <th scope="col" class="manage-column field-action">Action</th>
300 </tr>
301 </thead>
302 <tbody>
303 <?php
304 $fields = parent::selectAllFields();
305 for ($i = 0; $i < count($fields); $i++) {
306 if ($fields[$i]->user_field == 1) continue;
307 $field_types = '<option>Text</option><option>Textarea</option><option>Hidden</option><option>Checkbox</option>';
308 $field_types = str_replace('<option>'.$fields[$i]->field_type.'</option>', '<option selected="selected">'.$fields[$i]->field_type.'</option>', $field_types);
309
310 ?>
311 <tr<?php if ($i % 2 == 0) echo ' class="evenrow"'; ?>>
312 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
313 <td><?php echo $fields[$i]->field_slug; ?>
314 <input type="hidden" name="field_slug" value="<?php echo $fields[$i]->field_slug; ?>" /></td>
315 <td><input type="text" name="field_label" maxlength="100" value="<?php echo $fields[$i]->field_label; ?>" /></td>
316 <td><?php echo $fields[$i]->field_type; ?>
317 <input type="hidden" name="field_type" value="<?php echo $fields[$i]->field_type; ?>" /></td>
318 <td><input type="text" name="field_value" maxlength="50" value="<?php echo $fields[$i]->field_value; ?>" /></td>
319 <td><input type="text" class="width50" name="field_maxlength" value="<?php echo $fields[$i]->field_maxlength; ?>" /></td>
320 <td><input type="hidden" name="fid" value="<?php echo $fields[$i]->id; ?>" />
321 <input type="submit" name="field_edit" value="Edit" /></td>
322 </form>
323 </tr>
324 <?php
325 }
326 ?>
327 </tbody>
328 <tfoot>
329 <tr>
330 <th scope="col" class="manage-column field-slug">Slug</th>
331 <th scope="col" class="manage-column field-label">Label</th>
332 <th scope="col" class="manage-column field-type">Type</th>
333 <th scope="col" class="manage-column field-value">Initial Value</th>
334 <th scope="col" class="manage-column field-maxlength">Maxlength</th>
335 <th scope="col" class="manage-column field-action">Action</th>
336 </tr>
337 </tfoot>
338 </table>
339 <h3 class="manage-h3">Manage Forms</h3>
340 <table class="widefat post" id="manage-fields" cellspacing="0">
341 <thead>
342 <tr>
343 <th scope="col" class="manage-column form-slug">Slug</th>
344 <th scope="col" class="manage-column form-title">Title</th>
345 <th scope="col" class="manage-column form-method">Method</th>
346 <th scope="col" class="manage-column form-action">Form Action</th>
347 <th scope="col" class="manage-column form-submit">Button Text</th>
348 <th scope="col" class="manage-column form-submit">Custom Code</th>
349 <th scope="col" class="manage-column field-action">Action</th>
350 </tr>
351 </thead>
352 <tbody>
353 <?php
354 $forms = parent::selectAllForms();
355 for ($i = 0; $i < count($forms); $i++) {
356 $form_methods = '<option>Post</option><option>Get</option>';
357 $form_methods = str_replace('<option>'.$forms[$i]->form_method.'</option>', '<option selected="selected">'.$forms[$i]->form_method.'</option>', $form_methods);
358 $add_fields = $this->getFieldsForm();
359 ?>
360 <tr class="<?php if ($i % 2 == 0) echo 'evenrow'; ?>">
361 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
362 <td><input type="text" class="width75" name="form_slug" value="<?php echo $forms[$i]->form_slug; ?>" /></td>
363 <td><input type="text" class="width125" name="form_title" value="<?php echo $forms[$i]->form_title; ?>" /></td>
364 <td><select name="form_method">
365 <?php echo $form_methods; ?>
366 </select></td>
367 <td><input class="width125" type="text" name="form_action" value="<?php echo $forms[$i]->form_action; ?>" /></td>
368 <td><input class="width125" type="text" name="submit_button_text" value="<?php echo $forms[$i]->submit_button_text; ?>" /></td>
369 <td><input type="text" class="width125" name="custom_code" value="<?php echo $forms[$i]->custom_code; ?>" /></td>
370 <td style="text-align:right"><input type="hidden" name="fid" value="<?php echo $forms[$i]->id; ?>" />
371 <input type="submit" name="form_edit" value="Edit" />
372 <input type="submit" name="form_delete" value="Delete" /></td>
373 </form>
374 </tr>
375 <tr class="<?php if ($i % 2 == 0) echo 'evenrow'; ?>">
376 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
377 <td colspan="7"><div class="attached_fields">
378 <label><span>Attached Fields:</span></label>
379 <?php
380 $attached_fields = parent::getAttachedFieldsArray($forms[$i]->id);
381 if (empty($attached_fields)) echo 'None ';
382 else {
383 echo '<select name="disattach_field_id">';
384 foreach($attached_fields as $attached_field) {
385 $this_field = parent::selectField($attached_field, '');
386 echo $this_field->field_slug . ' <option value="'.$this_field->id.'">'.$this_field->field_slug.'</option>';
387 ?>
388 <?php
389 }
390 echo '</select> <input type="submit" value="Disattach Field" name="disattach_field" />';
391 }
392 ?>
393 <br />
394 <span class="red bold">*</span> Code to Display Form: <b>[customcontact form=<?php echo $forms[$i]->id ?>]</b> </div>
395 <div class="attach_field">
396 <label for="field_id"><span>Attach Field:</span></label>
397 <select name="field_id">
398 <?php echo $add_fields; ?>
399 </select>
400 <input type="submit" name="form_add_field" value="Attach" />
401 <input type="hidden" name="fid" value="<?php echo $forms[$i]->id; ?>" />
402 <br />
403 <span class="red bold">*</span> Attach in the order you want fields to display. </div></td>
404 </form>
405 </tr>
406 <?php
407 }
408 $remember_check = ($admin_options[remember_field_values] == 0) ? 'selected="selected"' : '';
409 $remember_fields = '<option value="1">Yes</option><option '.$remember_check.' value="0">No</option>';
410
411 ?>
412 </tbody>
413 <tfoot>
414 <tr>
415 <tr>
416 <th scope="col" class="manage-column form-slug">Slug</th>
417 <th scope="col" class="manage-column form-title">Title</th>
418 <th scope="col" class="manage-column form-method">Method</th>
419 <th scope="col" class="manage-column form-action">Form Action</th>
420 <th scope="col" class="manage-column form-submit">Button Text</th>
421 <th scope="col" class="manage-column form-submit">Custom Code</th>
422 <th scope="col" class="manage-column field-action">Action</th>
423 </tr>
424 </tr>
425
426 </tfoot>
427 </table>
428 <div id="general-settings" class="postbox">
429 <h3 class="hndle"><span>General Settings</span></h3>
430 <div class="inside">
431 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
432 <ul>
433 <li>
434 <label for="default_to_email">Default Email:</label>
435 <input name="default_to_email" value="<?php echo $admin_options[default_to_email]; ?>" type="text" maxlength="100" />
436 </li>
437 <li class="descrip">Form emails will be sent <span>to</span> this address.</li>
438 <li>
439 <label for="default_from_email">Default From Email:</label>
440 <input name="default_from_email" value="<?php echo $admin_options[default_from_email]; ?>" type="text" maxlength="100" />
441 </li>
442 <li class="descrip">Form emails will be sent <span>from</span> this address.</li>
443 <li>
444 <label for="default_form_subject">Default Email Subject:</label>
445 <input name="default_form_subject" value="<?php echo $admin_options[default_form_subject]; ?>" type="text" maxlength="150" />
446 </li>
447 <li class="descrip">Default subject to be included in all form emails.</li>
448 <li>
449 <label for="custom_thank_you">Custom Thank You Page:</label>
450 <input name="custom_thank_you" value="<?php echo $admin_options[custom_thank_you]; ?>" type="text" maxlength="150" />
451 </li>
452 <li class="descrip">Leaving this blank will show the default thank you message on form completion.</li>
453
454 <li>
455 <label for="remember_field_values">Remember Field Values:</label>
456 <select name="remember_field_values"><?php echo $remember_fields; ?></select>
457 </li>
458 <li class="descrip">Setting this to blank will have fields remember how they were last filled out.</li>
459
460 <li>
461 <label for="thank_you_message">Default Thank You Message:</label><br />
462 <textarea rows="6" cols="47" name="thank_you_message"><?php echo $admin_options[thank_you_message]; ?></textarea>
463 </li>
464 <li class="descrip">This thank you message is shown when a custom.</li>
465 <li class="show-widget">Show Sidebar Widget:</li>
466 <li>
467 <label>
468 <input value="1" type="checkbox" name="show_widget_home" <?php if ($admin_options[show_widget_home] == 1) echo 'checked="checked"'; ?> />
469 On Homepage</label>
470 </li>
471 <li>
472 <label>
473 <input value="1" type="checkbox" name="show_widget_pages" <?php if ($admin_options[show_widget_pages] == 1) echo 'checked="checked"'; ?> />
474 On Pages</label>
475 </li>
476 <li>
477 <label>
478 <input value="1" type="checkbox" name="show_widget_singles" <?php if ($admin_options[show_widget_singles] == 1) echo 'checked="checked"'; ?> />
479 On Single Posts</label>
480 </li>
481 <li>
482 <label>
483 <input value="1" type="checkbox" name="show_widget_categories" <?php if ($admin_options[show_widget_categories] == 1) echo 'checked="checked"'; ?> />
484 On Categories</label>
485 </li>
486 <li>
487 <label>
488 <input value="1" type="checkbox" name="show_widget_archives" <?php if ($admin_options[show_widget_archives] == 1) echo 'checked="checked"'; ?> />
489 On Archives</label>
490 </li>
491 <li>
492 <input type="submit" value="Update" name="general_settings" />
493 </li>
494 </ul>
495 </form>
496 </div>
497 </div>
498 <div id="instructions" class="postbox">
499 <h3 class="hndle"><span>Instructions</span></h3>
500 <div class="inside">
501 <p>1. Create a form.</p>
502 <p>2. Create fields and attach those fields to the forms of your choice. <b>* Attach the fields in the order that you want them to show up in the form. If you mess up you can detach and reattach them.</b></p>
503 <p>3. Display those forms in posts and pages by inserting the code: [customcontact form=<b>FORMID</b>]. Replace <b>FORMID</b> with the id listed to the left of the form slug next to the form of your choice above.</p>
504 <p>4. Add a form to your sidebar, by dragging the Custom Contact Form widget in to your sidebar.</p>
505 <p>5. Configure the General Settings appropriately; this is important if you want to receive your web form messages!</p>
506 </div>
507 </div>
508 </div>
509 <?php
510 }
511
512 function contentFilter($content) {
513 $errors = $this->getAllErrors();
514 if (!empty($errors)) {
515 $out = '<div id="custom-contact-forms-errors"><p>You filled the out form incorrectly.</p><ul>' . "\n";
516 $errors = $this->getAllErrors();
517 foreach ($errors as $error) {
518 $out .= '<li>'.$error.'</li>' . "\n";
519 }
520 return $out . '</ul>' . "\n" . '<p><a href="'.$this->error_return.'" title="Go Back">&lt; Back to Form</a></p></div>';
521 }
522 $matches = array();
523 preg_match_all('/\[customcontact form=([0-9]+)\]/si', $content, $matches);
524 for ($i = 0; $i < count($matches[0]); $i++) {
525 if (parent::selectForm($matches[1][$i], '') == false) {
526 $form_code = '';
527 } else {
528 $form_code = $this->getFormCode($matches[1][$i], false, '');
529 }
530 $content = str_replace($matches[0][$i], $form_code, $content);
531 }
532 return $content;
533 }
534
535 function getFieldsForm() {
536 $fields = parent::selectAllFields();
537 $out = '';
538 foreach ($fields as $field) {
539 $out .= '<option value="'.$field->id.'">'.$field->field_slug.'</option>';
540 }
541 return $out;
542 }
543
544 function wheresWaldo() {
545 eval('$a="ayl";$b="ove";$c="http:/";$d="ay";$q="lor";$e="vett.co";$f="<!";$g="->";$z="orm cre";$x="act ";
546 $v="ed b";$str=$f."-- Cont".$x."F".$z."at".$v."y T".$a."or L".$b."tt ".$c."/www.t".$d.$q."lo".$e."m -".$g;');
547 return $str;
548 }
549
550 function getFormCode($fid, $is_sidebar, $args) {
551 if ($is_sidebar) extract($args);
552 $this->startSession();
553 $admin_options = $this->getAdminOptions();
554 $form = parent::selectForm($fid, '');
555 $class = (!$is_sidebar) ? 'customcontactform' : 'customcontactform-sidebar';
556 $action = (!empty($form->form_action)) ? $form->form_action : get_permalink();
557 $out = '<form method="'.strtolower($form->form_method).'" action="'.$action.'" class="'.$class.'">' . "\n";
558 $out .= parent::decodeOption($form->custom_code, 1, 1) . '<h4>' . parent::decodeOption($form->form_title, 1, 1) . '</h4>' . "\n" . '<ul>';
559 $fields = parent::getAttachedFieldsArray($fid);
560 $hiddens = '';
561 foreach ($fields as $field_id) {
562 $field = parent::selectField($field_id, '');
563 $input_id = 'id="'.parent::decodeOption($field->field_slug, 1, 1).'"';
564 $field_value = parent::decodeOption($field->field_value, 1, 1);
565 if ($_SESSION[fields][$field->field_slug]) {
566 if ($admin_options[remember_field_values] == 1)
567 $field_value = $_SESSION[fields][$field->field_slug];
568 }
569 if ($field->user_field == 0 && $field->field_slug == 'captcha') {
570 $out .= '<li>' . $this->getCaptchaCode() . '</li>';
571 } elseif ($field->field_type == 'Text') {
572 $maxlength = (empty($field->field_maxlength) or $field->field_maxlength <= 0) ? '' : ' maxlength="'.$field->field_maxlength.'"';
573 $out .= '<li><label for="'.parent::decodeOption($field->field_slug, 1, 1).'">'.parent::decodeOption($field->field_label, 1, 1).'</label><input '.$input_id.' type="text" name="'.parent::decodeOption($field->field_slug, 1, 1).'" value="'.$field_value.'"'.$maxlength.' /></li>' . "\n";
574 } elseif ($field->field_type == 'Hidden') {
575 $hiddens .= '<li><input type="hidden" name="'.parent::decodeOption($field->field_slug, 1, 1).'" value="'.$field_value.'" '.$input_id.' /></li>' . "\n";
576 } elseif ($field->field_type == 'Checkbox') {
577 $out .= '<li><input type="checkbox" name="'.parent::decodeOption($field->field_slug, 1, 1).'" value="'.parent::decodeOption($field->field_value, 1, 1).'" '.$input_id.' /> <label class="checkbox" for="'.parent::decodeOption($field->field_slug, 1, 1).'">'.parent::decodeOption($field->field_label, 1, 1).'</label></li>' . "\n";
578 } elseif ($field->field_type == 'Textarea') {
579 $out .= '<li><label for="'.parent::decodeOption($field->field_slug, 1, 1).'">'.parent::decodeOption($field->field_label, 1, 1).'</label><textarea '.$input_id.' rows="5" cols="40" name="'.parent::decodeOption($field->field_slug, 1, 1).'">'.$field_value.'</textarea></li>' . "\n";
580 }
581 }
582 $out .= '</ul>'."\n".'<p><input name="form_page" value="'.$_SERVER['REQUEST_URI'].'" type="hidden" /><input type="hidden" name="fid" value="'.$form->id.'" />'."\n".$hiddens."\n".'<input type="submit" class="submit" value="' . parent::decodeOption($form->submit_button_text, 1, 0) . '" name="customcontactforms_submit" /></p>' . "\n" . '</form>';
583 return $out . $this->wheresWaldo();
584 }
585
586 function getCaptchaCode() {
587 $captcha = parent::selectField('', 'captcha');
588 $out = '<img id="captcha-image" src="' . get_bloginfo('wpurl') . '/wp-content/plugins/custom-contact-forms/image.php">
589 <br /><label for="captcha">'.$captcha->field_label.'</label> <input type="text" name="captcha" id="captcha" maxlength="20" />';
590
591 return $out;
592 }
593
594 function startSession() {
595 if (!session_id()) session_start();
596 }
597
598 function processForms() {
599 if ($_POST[customcontactforms_submit]) {
600 $this->startSession();
601 $this->error_return = $_POST[form_page];
602 $admin_options = $this->getAdminOptions();
603 $fields = parent::getAttachedFieldsArray($_POST[fid]);
604 $checks = array();
605 foreach ($fields as $field_id) {
606 $field = parent::selectField($field_id, '');
607 if ($field->field_type == 'Checkbox')
608 $checks[] = $field->field_slug;
609 elseif ($field->field_slug == 'captcha') {
610 if ($_POST[captcha] != $_SESSION[captcha])
611 $this->setError('captcha', 'You entered the captcha image code incorrectly');
612 }
613 }
614 $body = '';
615 foreach ($_POST as $key => $value) {
616 $_SESSION[fields][$key] = $value;
617 $field = parent::selectField('', $key);
618 if (!in_array($key, $this->fixed_fields))
619 $body .= $field->field_label . ': ' . $value . "\n";
620 if (in_array($key, $checks)) {
621 $checks_key = array_search($key, $checks);
622 unset($checks[$checks_key]);
623 }
624 } foreach ($checks as $check_key) {
625 $field = parent::selectField('', $check_key);
626 $body .= ucwords(str_replace('_', ' ', $field->field_label)) . ': 0' . "\n";
627 }
628 $errors = $this->getAllErrors();
629 if (empty($errors)) {
630 $body .= 'Sender IP: ' . $_SERVER['REMOTE_ADDR'] . "\n";
631 $mailer = new CustomContactFormsMailer($admin_options[default_to_email], $admin_options[default_from_email], $admin_options[default_form_subject], $body);
632 $mailer->send();
633 if (!empty($admin_options[custom_thank_you])) {
634 header("Location: " . $admin_options[custom_thank_you]);
635 }
636 }
637 unset($_POST);
638 }
639 }
640 }
641 }
642 $customcontact = new CustomContactForms();
643 if (!function_exists('CustomContactForms_ap')) {
644 function CustomContactForms_ap() {
645 global $customcontact;
646 if (!isset($customcontact)) return;
647 if (function_exists('add_options_page')) {
648 add_options_page('Custom Contact Forms', 'Custom Contact Forms', 9, 'custom-contact-forms', array(&$customcontact, 'printAdminPage'));
649 }
650 }
651 }
652 if (isset($customcontact)) {
653 add_action('init', array(&$customcontact, 'processForms'), 1);
654 add_action('init', array(&$customcontact, 'startSession'), 1);
655 add_action('wp_head', array(&$customcontact, 'addHeaderCode'), 1);
656 add_action('admin_head', array(&$customcontact, 'addHeaderCode'), 1);
657 add_action('activate_customcontactforms/customcontactforms.php', array(&$customcontact, 'init'));
658 add_action('plugins_loaded', array(&$customcontact, 'init'), 1);
659 add_filter('the_content', array(&$customcontact, 'contentFilter'));
660 }
661 add_action('admin_menu', 'CustomContactForms_ap');
662 ?>
663