PluginProbe
Custom Contact Forms / 3.0.0
Custom Contact Forms v3.0.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 3.0.0, at custom-contact-forms.php

1,240 lines 69.7 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: Guaranteed to be 1000X more customizable and intuitive than Fast Secure Contact Forms or Contact Form 7. Customize every aspect of your forms without any knowledge of CSS: borders, padding, sizes, colors. Ton's of great features. Required fields, captchas, tooltip popovers, unlimited fields/forms/form styles, use a custom thank you page or built-in popover with a custom success message set for each form. <a href="options-general.php?page=custom-contact-forms">Settings</a>
6 Version: 3.0.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 = '2.1.0';
32 var $form_errors;
33 var $error_return;
34 var $gets;
35 var $current_thank_you_message;
36 var $fixed_fields = array('customcontactforms_submit' => '',
37 'fid' => '',
38 'fixedEmail' => 'Use this field if you want the plugin to throw an error on fake emails.',
39 'form_page' => '',
40 'captcha' => 'This field requires users to type numbers in an image preventing spam.',
41 'ishuman' => 'This field requires users to check a box to prove they aren\'t a spam bot.'
42 );
43
44 function CustomContactForms() {
45 parent::CustomContactFormsDB();
46 $this->form_errors = array();
47 }
48
49 function getAdminOptions() {
50 $admin_email = get_option('admin_email');
51 $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!',
52 'remember_field_values' => 0, 'author_link' => 1, 'enable_widget_tooltips' => 1, 'wp_mail_function' => 1, 'form_success_message' => 'Thank you for filling out our web form. We will get back to you ASAP.'); // default general settings
53 $customcontactOptions = get_option($this->adminOptionsName);
54 if (!empty($customcontactOptions)) {
55 foreach ($customcontactOptions as $key => $option)
56 $customcontactAdminOptions[$key] = $option;
57 }
58 update_option($this->adminOptionsName, $customcontactAdminOptions);
59 return $customcontactAdminOptions;
60 }
61 function init() {
62 $this->storeGets();
63 $this->getAdminOptions();
64 if (!is_admin()) {
65 wp_enqueue_script('jquery');
66 $this->startSession();
67 $this->processForms();
68 }
69 $this->registerSidebar();
70 }
71
72 function registerSidebar() {
73 register_sidebar_widget(__('Custom Contact Form'), array($this, 'widget_customContactForms'));
74 register_widget_control('Custom Contact Form', array($this, 'customContactForms_control'), 300, 200);
75 }
76
77 function customContactForms_control() {
78 $option = get_option($this->widgetOptionsName);
79 if (empty($option)) $option = array('widget_form_id' => '0');
80 if ($_POST[widget_form_id]) {
81 $option[widget_form_id] = $_POST[widget_form_id];
82 update_option($this->widgetOptionsName, $option);
83 $option = get_option($this->widgetOptionsName);
84 }
85 $forms = parent::selectAllForms();
86
87 $form_options = '';
88 foreach ($forms as $form) {
89 $sel = ($option[widget_form_id] == $form->id) ? ' selected="selected"' : '';
90 $form_options .= '<option value="'.$form->id.'"'.$sel.'>'.$form->form_slug.'</option>';
91 }
92 if (empty($form_options)) { ?>
93 <p>Create a form in the Custom Contact Forms settings page.</p>
94 <?php
95 } else {
96 ?>
97 <p>
98 <label for="widget_form_id">Show Form:</label>
99 <select name="widget_form_id">
100 <?php echo $form_options; ?>
101 </select>
102 </p>
103 <?php
104 }
105 }
106 function widget_customContactForms($args) {
107 extract($args);
108 $admin_option = $this->getAdminOptions();
109 if ((is_front_page() and $admin_option[show_widget_home] != 1) or (is_single() and $admin_option[show_widget_singles] != 1) or
110 (is_page() and $admin_option[show_widget_pages] != 1) or (is_category() and $admin_option[show_widget_categories] != 1) or
111 (is_archive() and $admin_option[show_widget_archives] != 1))
112 return false;
113 $option = get_option($this->widgetOptionsName);
114 if (empty($option) or $option[widget_form_id] < 1) return false;
115 echo $before_widget . $this->getFormCode($option[widget_form_id], true) . $after_widget;
116 }
117 function addHeaderCode() {
118 ?>
119 <!-- Custom Contact Forms by Taylor Lovett - http://www.taylorlovett.com -->
120 <link rel="stylesheet" href="<?php echo get_option('siteurl'); ?>/wp-content/plugins/custom-contact-forms/custom-contact-forms.css" type="text/css" media="screen" />
121 <?php
122 }
123
124 function insertAdminScripts() {
125 wp_enqueue_script('ccf-main', get_option('siteurl') . '/wp-content/plugins/custom-contact-forms/js/custom-contact-forms-admin.js', array('jquery', 'jquery-ui-core', 'jquery-ui-tabs'/*, 'jquery-ui-draggable', 'jquery-ui-resizable', 'jquery-ui-dialog'*/), '1.0');
126 }
127
128 function insertFrontEndScripts() {
129 wp_enqueue_script('jquery-tools', get_option('siteurl') . '/wp-content/plugins/custom-contact-forms/js/jquery.tools.min.js');
130 //wp_enqueue_script('jquery-ui-position', get_option('siteurl') . '/wp-content/plugins/custom-contact-forms/js/jquery.ui.position.js');
131 //wp_enqueue_script('jquery-ui-widget', get_option('siteurl') . '/wp-content/plugins/custom-contact-forms/js/jquery.ui.widget.js');
132 //wp_enqueue_script('jquery-bgiframe', get_option('siteurl') . '/wp-content/plugins/custom-contact-forms/js/jquery.bgiframe-2.1.1.js');
133 wp_enqueue_script('ccf-main', get_option('siteurl') . '/wp-content/plugins/custom-contact-forms/js/custom-contact-forms.js', array('jquery', 'jquery-ui-core', 'jquery-ui-tabs'/*, 'jquery-ui-draggable', 'jquery-ui-resizable', 'jquery-ui-dialog'*/), '1.0');
134 //jquery-ui-position
135 }
136
137 function setFormError($key, $message) {
138 $this->form_errors[$key] = $message;
139 }
140
141 function storeGets() {
142 foreach ($_GET as $k => $v) {
143 $this->gets[$k] = $v;
144 }
145 }
146
147 function getFormError($key) {
148 return $this->form_errors[$key];
149 }
150
151 function getAllFormErrors() {
152 return $this->form_errors;
153 }
154
155 function printAdminPage() {
156 $admin_options = $this->getAdminOptions();
157 if ($_POST[form_create]) {
158 parent::insertForm($_POST[form]);
159 } elseif ($_POST[field_create]) {
160 parent::insertField($_POST[field]);
161 } elseif ($_POST[general_settings]) {
162 $admin_options[default_to_email] = $_POST[default_to_email];
163 $admin_options[default_from_email] = $_POST[default_from_email];
164 $admin_options[default_form_subject] = $_POST[default_form_subject];
165 $admin_options[show_widget_categories] = $_POST[show_widget_categories];
166 $admin_options[show_widget_singles] = $_POST[show_widget_singles];
167 $admin_options[show_widget_pages] = $_POST[show_widget_pages];
168 $admin_options[show_widget_archives] = $_POST[show_widget_archives];
169 $admin_options[show_widget_home] = $_POST[show_widget_home];
170 $admin_options[custom_thank_you] = $_POST[custom_thank_you];
171 $admin_options[author_link] = $_POST[author_link];
172 $admin_options[form_success_message] = $_POST[form_success_message];
173 $admin_options[wp_mail_function] = $_POST[wp_mail_function];
174 $admin_options[enable_widget_tooltips] = $_POST[enable_widget_tooltips];
175 $admin_options[remember_field_values] = $_POST[remember_field_values];
176 update_option($this->adminOptionsName, $admin_options);
177 } elseif ($_POST[field_edit]) {
178 parent::updateField($_POST[field], $_POST[fid]);
179 } elseif ($_POST[field_delete]) {
180 parent::deleteField($_POST[fid]);
181 } elseif ($_POST[form_delete]) {
182 parent::deleteForm($_POST[fid]);
183 } elseif ($_POST[form_edit]) {
184 parent::updateForm($_POST[form], $_POST[fid]);
185 } elseif ($_POST[form_add_field]) {
186 parent::addFieldToForm($_POST[field_id], $_POST[fid]);
187 } elseif ($_POST[disattach_field]) {
188 parent::disattachField($_POST[disattach_field_id], $_POST[fid]);
189 } elseif ($_POST[style_create]) {
190 parent::insertStyle($_POST[style]);
191 } elseif ($_POST[style_edit]) {
192 parent::updateStyle($_POST[style], $_POST[sid]);
193 } elseif ($_POST[style_delete]) {
194 parent::deleteStyle($_POST[sid]);
195 } elseif ($_POST[contact_author]) {
196 $this_url = (!empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : $_SERVER['SERVER_NAME'];
197 $this->contactAuthor($_POST[name], $_POST[email], $this_url, $_POST[message], $_POST[type]);
198 }
199 $styles = parent::selectAllStyles();
200 $style_options = '<option value="0">None</option>';
201 foreach ($styles as $style)
202 $style_options .= '<option value="'.$style->id.'">'.$style->style_slug.'</option>';
203 ?>
204 <div id="customcontactforms-admin">
205 <div id="icon-themes" class="icon32"></div>
206 <h2>Custom Contact Forms</h2>
207 <ul id="plugin-nav">
208 <li><a href="#instructions">Plugin Instructions</a></li>
209 <li><a href="#general-settings">General Settings</a></li>
210 <li><a href="#create-fields">Create Fields</a></li>
211 <li><a href="#create-forms">Create Forms</a></li>
212 <li><a href="#manage-fields">Manage Fields</a></li>
213 <li><a href="#manage-fixed-fields">Manage Fixed Fields</a></li>
214 <li><a href="#manage-forms">Manage Forms</a></li>
215 <li><a href="#create-styles">Create Styles</a></li>
216 <li><a href="#manage-styles">Manage Styles</a></li>
217 <li><a href="#contact-author">Suggest a Feature</a></li>
218 <li><a href="#contact-author">Bug Report</a></li>
219 <li><a href="#custom-html">Custom HTML Forms (New!)</a></li>
220 <li class="last"><a href="#plugin-news">Plugin News</a></li>
221 </ul><a name="create-fields"></a>
222 <div id="create-fields" class="postbox">
223 <h3 class="hndle"><span>Create A Form Field</span></h3>
224 <div class="inside">
225 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
226 <ul>
227 <li>
228 <label for="field_slug">* Slug (Name):</label>
229 <input name="field[field_slug]" type="text" maxlength="50" />
230 (Must be unique)</li>
231 <li>
232 <label for="field_label">Field Label:</label>
233 <input name="field[field_label]" type="text" maxlength="100" />
234 </li>
235 <li>
236 <label for="field_type">* Field Type:</label>
237 <select name="field[field_type]">
238 <option>Text</option>
239 <option>Textarea</option>
240 <option>Hidden</option>
241 <option>Checkbox</option>
242 </select>
243 </li>
244 <li>
245 <label for="field_value">Initial Value:</label>
246 <input name="field[field_value]" type="text" maxlength="50" />
247 </li>
248 <li>
249 <label for="field_maxlength">Max Length:</label>
250 <input class="width50" size="10" name="field[field_maxlength]" type="text" maxlength="4" />
251 (0 for no limit; only applies to Text fields)</li>
252 <li>
253 <label for="field_required">Required Field:</label>
254 <select name="field[field_required]"><option value="0">No</option><option value="1">Yes</option></select></li>
255 <li>
256 <label for="field_value">Field Instructions:</label>
257 <input name="field[field_instructions]" type="text" /><br />
258 (If this is filled out, a tooltip popover displaying this text will show when the field is selected.)
259 </li>
260 <li><input type="hidden" name="field[user_field]" value="1" />
261 <input type="submit" value="Create Field" name="field_create" />
262 </li>
263 </ul>
264 </form>
265 </div>
266 </div><a name="create-forms"></a>
267 <div id="create-forms" class="postbox">
268 <h3 class="hndle"><span>Create A Form</span></h3>
269 <div class="inside">
270 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
271 <ul>
272 <li>
273 <label for="form[form_name]">Form Slug:</label>
274 <input type="text" maxlength="100" name="form[form_slug]" /><br />
275 (Must be unique and contain only underscores and alphanumeric characters.)</li>
276 <li>
277 <label for="form[form_title]">Form Title:</label>
278 <input type="text" maxlength="200" name="form[form_title]" />
279 (The form header text)</li>
280 <li>
281 <label for="form[form_method]">Form Method:</label>
282 <select name="form[form_method]">
283 <option>Post</option>
284 <option>Get</option>
285 </select>
286 (If unsure, leave as is.)</li>
287 <li>
288 <label for="form[form_action]">Form Action:</label>
289 <input type="text" name="form[form_action]" value="" />
290 (If unsure, leave blank.)</li>
291 <li>
292 <label for="form[form_action]">Form Style:</label>
293 <select name="form[form_style]"><?php echo $style_options; ?></select>
294 (<a href="#create-styles">Click to create a style</a>)</li>
295 <li>
296 <label for="form[submit_button_text]">Submit Button Text:</label>
297 <input type="text" maxlength="200" name="form[submit_button_text]" />
298 </li>
299 <li>
300 <label for="form[custom_code]">Custom Code:</label>
301 <input type="text" name="form[custom_code]" /><br />
302 (If unsure, leave blank. This field allows you to insert custom HTML directly after the starting form tag.)</li>
303 <li>
304 <label for="form[form_email]">Form Destination Email:</label>
305 <input type="text" name="form[form_email]" /><br />
306 (Will receive all submissions from this form; if left blank it will use the default specified in general settings.)</li>
307 <li>
308 <label for="form[form_success_message]">Form Success Message:</label>
309 <input type="text" name="form[form_success_message]" /><br />
310 (Will be displayed in a popover when the form is filled out successfully when no custom success page is specified; if left blank it will use the default specified in general settings.)</li>
311 <li>
312 <label for="form[form_thank_you_page]">Custom Success URL:</label>
313 <input type="text" name="form[form_thank_you_page]" /><br />
314 (If this is filled out, users will be sent to this page when they successfully fill out this form. If it is left blank, a popover showing the form's "success message" will be displayed on form success.)</li>
315 <li>
316 <input type="submit" value="Create Form" name="form_create" />
317 </li>
318 </ul>
319 </form>
320 </div>
321 </div><a name="manage-fields"></a>
322 <h3 class="manage-h3">Manage User Fields</h3>
323 <table class="widefat post" id="manage-fields" cellspacing="0">
324 <thead>
325 <tr>
326 <th scope="col" class="manage-column field-slug">Slug</th>
327 <th scope="col" class="manage-column field-label">Label</th>
328 <th scope="col" class="manage-column field-type">Type</th>
329 <th scope="col" class="manage-column field-value">Initial Value</th>
330 <th scope="col" class="manage-column field-required">Required</th>
331 <th scope="col" class="manage-column field-maxlength">Maxlength</th>
332 <th scope="col" class="manage-column field-action">Action</th>
333 </tr>
334 </thead>
335 <tbody>
336 <?php
337 $fields = parent::selectAllFields();
338 for ($i = 0, $z = 0; $i < count($fields); $i++, $z++) {
339 if ($fields[$i]->user_field == 0) { $z--; continue; }
340 $field_types = '<option>Text</option><option>Textarea</option><option>Hidden</option><option>Checkbox</option>';
341 $field_types = str_replace('<option>'.$fields[$i]->field_type.'</option>', '<option selected="selected">'.$fields[$i]->field_type.'</option>', $field_types);
342
343 ?>
344 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
345 <tr<?php if ($z % 2 == 1) echo ' class="evenrow"'; ?>>
346
347 <td><input type="text" name="field[field_slug]" class="width100" maxlength="50" value="<?php echo $fields[$i]->field_slug; ?>" /></td>
348 <td><input type="text" name="field[field_label]" maxlength="100" value="<?php echo $fields[$i]->field_label; ?>" /></td>
349 <td><select name="field[field_type]">
350 <?php echo $field_types; ?>
351 </select></td>
352 <td><input type="text" name="field[field_value]" maxlength="50" class="width75" value="<?php echo $fields[$i]->field_value; ?>" /></td>
353 <td><select name="field[field_required]"><option value="1">Yes</option><option value="0" <?php if ($fields[$i]->field_required != 1) echo 'selected="selected"'; ?>>No</option></select></td>
354 <td><input type="text" class="width50" name="field[field_maxlength]" value="<?php echo $fields[$i]->field_maxlength; ?>" /></td>
355 <td><input type="hidden" name="fid" value="<?php echo $fields[$i]->id; ?>" />
356 <span class="fields-options-expand"></span>
357 <input type="submit" name="field_edit" value="Edit" />
358 <input type="submit" name="field_delete" value="Delete" /></td>
359
360 </tr>
361 <tr<?php if ($z % 2 == 1) echo ' class="evenrow"'; ?>>
362 <td class="fields-extra-options" colspan="7" style="border-bottom:1px solid black;">Field Instructions: <input type="text" class="width200" name="field[field_instructions]" value="<?php echo $fields[$i]->field_instructions; ?>" /></td>
363 </tr>
364 </form>
365 <?php
366 }
367 ?>
368 </tbody>
369 <tfoot>
370 <tr>
371 <th scope="col" class="manage-column field-slug">Slug</th>
372 <th scope="col" class="manage-column field-label">Label</th>
373 <th scope="col" class="manage-column field-type">Type</th>
374 <th scope="col" class="manage-column field-value">Initial Value</th>
375 <th scope="col" class="manage-column field-required">Required</th>
376 <th scope="col" class="manage-column field-maxlength">Maxlength</th>
377 <th scope="col" class="manage-column field-action">Action</th>
378 </tr>
379 </tfoot>
380 </table><a name="manage-fixed-fields"></a>
381 <h3 class="manage-h3">Manage Fixed Fields</h3>
382 <table class="widefat post" id="manage-fixed-fields" cellspacing="0">
383 <thead>
384 <tr>
385 <th scope="col" class="manage-column field-slug">Slug</th>
386 <th scope="col" class="manage-column field-label">Label</th>
387 <th scope="col" class="manage-column field-type">Type</th>
388 <th scope="col" class="manage-column field-value">Initial Value</th>
389 <th scope="col" class="manage-column field-value">Required</th>
390 <th scope="col" class="manage-column field-maxlength">Maxlength</th>
391 <th scope="col" class="manage-column field-action">Action</th>
392 </tr>
393 </thead>
394 <tbody>
395 <?php
396 $fields = parent::selectAllFields();
397 for ($i = 0, $z = 0; $i < count($fields); $i++, $z++) {
398 if ($fields[$i]->user_field == 1) { $z--; continue;}
399 $field_types = '<option>Text</option><option>Textarea</option><option>Hidden</option><option>Checkbox</option>';
400 $field_types = str_replace('<option>'.$fields[$i]->field_type.'</option>', '<option selected="selected">'.$fields[$i]->field_type.'</option>', $field_types);
401
402 ?>
403 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
404 <tr <?php if ($z % 2 == 0) echo ' class="evenrow"'; ?> style="border:none;">
405
406 <td><?php echo $fields[$i]->field_slug; ?></td>
407 <td><input type="text" name="field[field_label]" maxlength="100" value="<?php echo $fields[$i]->field_label; ?>" /></td>
408 <td><?php echo $fields[$i]->field_type; ?>
409 <td><?php if ($fields[$i]->field_type != 'Checkbox') { ?>
410 <input type="text" name="field[field_value]" class="width75" maxlength="50" value="<?php echo $fields[$i]->field_value; ?>" />
411 <?php } else {
412 echo $fields[$i]->field_value;
413 ?>
414 <?php } ?>
415 </td>
416 <td>
417 <?php if ($fields[$i]->field_slug == 'fixedEmail') { ?>
418 <select name="field[field_required]"><option value="1">Yes</option><option <?php if($fields[$i]->field_required != 1) echo 'selected="selected"'; ?> value="0">No</option></select>
419 <?php } else { ?>
420 Yes
421 <?php } ?>
422 </td>
423 <td><?php if ($fields[$i]->field_type != 'Checkbox') { ?>
424 <input type="text" class="width50" name="field[field_maxlength]" value="<?php echo $fields[$i]->field_maxlength; ?>" />
425 <?php } else { ?>
426 None
427 <?php } ?>
428 </td>
429
430 <td><input type="hidden" name="fid" value="<?php echo $fields[$i]->id; ?>" />
431 <span class="fixed-fields-options-expand"></span>
432 <input type="submit" name="field_edit" value="Edit" /></td>
433 </tr>
434 <tr <?php if ($z % 2 == 0) echo ' class="evenrow"'; ?> style="border:none;">
435 <td class="fixed-fields-extra-options" colspan="7" style="border-bottom:1px solid black;">Field Instructions: <input type="text" name="field[field_instructions]" class="width200" value="<?php echo $fields[$i]->field_instructions; ?>" /> - <?php echo $this->fixed_fields[$fields[$i]->field_slug]; ?></td>
436 </tr>
437 </form>
438 <?php
439 }
440 ?>
441 </tbody>
442 <tfoot>
443 <tr>
444 <th scope="col" class="manage-column field-slug">Slug</th>
445 <th scope="col" class="manage-column field-label">Label</th>
446 <th scope="col" class="manage-column field-type">Type</th>
447 <th scope="col" class="manage-column field-value">Initial Value</th>
448 <th scope="col" class="manage-column field-value">Required</th>
449 <th scope="col" class="manage-column field-maxlength">Maxlength</th>
450 <th scope="col" class="manage-column field-action">Action</th>
451 </tr>
452 </tfoot>
453 </table><a name="manage-forms"></a>
454 <h3 class="manage-h3">Manage Forms</h3>
455 <table class="widefat post" id="manage-forms" cellspacing="0">
456 <thead>
457 <tr>
458 <th scope="col" class="manage-column form-code">Form Display Code</th>
459 <th scope="col" class="manage-column form-slug">Slug</th>
460 <th scope="col" class="manage-column form-title">Title</th>
461 <th scope="col" class="manage-column form-submit">Button Text</th>
462 <th scope="col" class="manage-column form-submit">Style</th>
463 <th scope="col" class="manage-column form-submit">Action</th>
464 </tr>
465 </thead>
466 <tbody>
467 <?php
468 $forms = parent::selectAllForms();
469 for ($i = 0; $i < count($forms); $i++) {
470 $form_methods = '<option>Post</option><option>Get</option>';
471 $form_methods = str_replace('<option>'.$forms[$i]->form_method.'</option>', '<option selected="selected">'.$forms[$i]->form_method.'</option>', $form_methods);
472 $add_fields = $this->getFieldsForm();
473 $this_style = parent::selectStyle($forms[$i]->form_style, '');
474 $sty_opt = str_replace('<option value="'.$forms[$i]->form_style.'">'.$this_style->style_slug.'</option>', '<option value="'.$forms[$i]->form_style.'" selected="selected">'.$this_style->style_slug.'</option>', $style_options);
475 ?>
476 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
477 <tr class="<?php if ($i % 2 == 0) echo 'evenrow'; ?>">
478 <td><span class="bold">[customcontact form=<?php echo $forms[$i]->id ?>]</span></td>
479 <td><input type="text" class="width75" name="form[form_slug]" value="<?php echo $forms[$i]->form_slug; ?>" /></td>
480 <td><input type="text" class="width125" name="form[form_title]" value="<?php echo $forms[$i]->form_title; ?>" /></td>
481 <td><input class="width100" type="text" name="form[submit_button_text]" value="<?php echo $forms[$i]->submit_button_text; ?>" /></td>
482 <td><select name="form[form_style]"><?php echo $sty_opt; ?></select></td>
483 <td><input type="hidden" name="fid" value="<?php echo $forms[$i]->id; ?>" />
484 <span class="form-options-expand"></span>
485 <input type="submit" name="form_edit" value="Edit" />
486 <input type="submit" name="form_delete" value="Delete" />
487 </td>
488 </tr>
489 <tr class="<?php if ($i % 2 == 0) echo 'evenrow'; ?>">
490 <td class="form-extra-options textcenter" colspan="8" style="border-bottom:1px solid black;">
491 <table class="form-extra-options-table">
492 <tbody>
493 <tr>
494 <td class="bold">Form Method</td>
495 <td class="bold">Form Action</td>
496 <td class="bold">Destination Email</td>
497 <td class="bold">Custom Code</td>
498 <td class="bold">Success Message</td>
499 <td class="bold">Custom Success URL</td>
500 </tr>
501 <tr>
502 <td><select name="form[form_method]"><?php echo $form_methods; ?></select></td>
503 <td><input type="text" name="form[form_action]" value="<?php echo $forms[$i]->form_action; ?>" /></td>
504 <td><input type="text" name="form[form_email]" value="<?php echo $forms[$i]->form_email; ?>" /></td>
505 <td><input type="text" name="form[custom_code]" value="<?php echo $forms[$i]->custom_code; ?>" /></td>
506 <td><input type="text" name="form[form_success_message]" value="<?php echo $forms[$i]->form_success_message; ?>" /></td>
507 <td><input type="text" class="width125" name="form[form_thank_you_page]" value="<?php echo $forms[$i]->form_thank_you_page; ?>" /></td>
508 </tr>
509 <tr>
510 <td colspan="3">
511 <label for="disattach_field_id"><span>Attached Fields:</span></label>
512 <?php
513 $attached_fields = parent::getAttachedFieldsArray($forms[$i]->id);
514 if (empty($attached_fields)) echo 'None ';
515 else {
516 echo '<select name="disattach_field_id">';
517 foreach($attached_fields as $attached_field) {
518 $this_field = parent::selectField($attached_field, '');
519 echo $this_field->field_slug . ' <option value="'.$this_field->id.'">'.$this_field->field_slug.'</option>';
520 }
521 echo '</select> <input type="submit" value="Disattach Field" name="disattach_field" />';
522 }
523 ?><br />
524 <span class="red bold">*</span> Attach fields in the order you want them displayed.
525 </td>
526 <td colspan="3">
527 <label for="field_id"><span>Attach Field:</span></label>
528 <select name="field_id"><?php echo $add_fields; ?></select> <input type="submit" name="form_add_field" value="Attach Field" />
529 <br /><span class="red bold">*</span> Attach fixed fields or ones you <a href="#create-fields">create</a>.
530 </td>
531 </tr>
532 <tr>
533 <td colspan="6"><label for="theme_code_<?php echo $forms[$i]->id; ?>"><span>Code to Display Form in Theme Files:</span></label> <input type="text" class="width225" value="if (function_exists('serveCustomContactForm')) { serveCustomContactForm(<?php echo $forms[$i]->id; ?>); }" name="theme_code_<?php echo $form[$i]->id; ?>" /></td>
534 </tr>
535 </tbody>
536 </table>
537 </td>
538 </tr>
539
540 </form>
541 <?php
542 }
543 $remember_check = ($admin_options[remember_field_values] == 0) ? 'selected="selected"' : '';
544 $remember_fields = '<option value="1">Yes</option><option '.$remember_check.' value="0">No</option>';
545 $border_style_options = '<option>solid</option><option>dashed</option>
546 <option>grooved</option><option>double</option><option>dotted</option><option>ridged</option><option>none</option>
547 <option>inset</option><option>outset</option>';
548 ?>
549 </tbody>
550 <tfoot>
551 <tr>
552 <tr>
553 <th scope="col" class="manage-column form-code">Form Code</th>
554 <th scope="col" class="manage-column form-slug">Slug</th>
555 <th scope="col" class="manage-column form-title">Title</th>
556 <th scope="col" class="manage-column form-submit">Button Text</th>
557 <th scope="col" class="manage-column form-submit">Style</th>
558 <th scope="col" class="manage-column form-submit">Action</th>
559 </tr>
560 </tr>
561
562 </tfoot>
563 </table><a name="general-settings"></a>
564 <div id="general-settings" class="postbox">
565 <h3 class="hndle"><span>General Settings</span></h3>
566 <div class="inside">
567 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
568 <ul>
569 <li>
570 <label for="default_to_email">Default Email:</label>
571 <input name="default_to_email" value="<?php echo $admin_options[default_to_email]; ?>" type="text" maxlength="100" />
572 </li>
573 <li class="descrip">Form emails will be sent <span>to</span> this address, if no destination email is specified by the form.</li>
574 <li>
575 <label for="default_from_email">Default From Email:</label>
576 <input name="default_from_email" value="<?php echo $admin_options[default_from_email]; ?>" type="text" maxlength="100" />
577 </li>
578 <li class="descrip">Form emails will be sent <span>from</span> this address. It is recommended you provide a real email address that has been created through your host.</li>
579 <li>
580 <label for="default_form_subject">Default Email Subject:</label>
581 <input name="default_form_subject" value="<?php echo $admin_options[default_form_subject]; ?>" type="text" />
582 </li>
583 <li class="descrip">Default subject to be included in all form emails.</li>
584 <li>
585 <label for="form_success_message">Default Thank You Message:</label>
586 <input name="form_success_message" value="<?php echo $admin_options[form_success_message]; ?>" type="text"/>
587 </li>
588 <li class="descrip">If someone fills out a form for which a success message is not provided and a custom success page is not provided, the plugin will show a popover containing this message.</li>
589
590 <li>
591 <label for="remember_field_values">Remember Field Values:</label>
592 <select name="remember_field_values"><option value="1">Yes</option><option <?php if ($admin_options[remember_field_values] == 0) echo 'selected="selected"'; ?> value="0">No</option></select>
593 </li>
594 <li class="descrip">Selecting yes will make form fields remember how they were last filled out.</li>
595 <li>
596 <label for="enable_widget_tooltips">Enable Tooltips in Widget:</label>
597 <select name="enable_widget_tooltips"><option value="1">Yes</option><option <?php if ($admin_options[enable_widget_tooltips] == 0) echo 'selected="selected"'; ?> value="0">No</option></select>
598 </li>
599 <li class="descrip">Enabling this shows tooltips containing field instructions on forms in the widget.</li>
600 <li>
601 <label for="author_link">Hide Plugin Author Link in Code:</label>
602 <select name="author_link"><option value="1">Yes</option><option <?php if ($admin_options[author_link] == 0) echo 'selected="selected"'; ?> value="0">No</option></select>
603 </li>
604 <li>
605 <label for="wp_mail_function">Use Wordpress Mail Function:</label>
606 <select name="wp_mail_function"><option value="1">Yes</option><option <?php if ($admin_options[wp_mail_function] == 0) echo 'selected="selected"'; ?> value="0">No</option></select>
607 </li>
608 <li class="descrip">Setting this to no will use the PHP mail function. If your forms aren't sending mail properly try setting this to no.</li>
609 <li class="show-widget"><b>Show Sidebar Widget:</b></li>
610 <li>
611 <label>
612 <input value="1" type="checkbox" name="show_widget_home" <?php if ($admin_options[show_widget_home] == 1) echo 'checked="checked"'; ?> />
613 On Homepage</label>
614 </li>
615 <li>
616 <label>
617 <input value="1" type="checkbox" name="show_widget_pages" <?php if ($admin_options[show_widget_pages] == 1) echo 'checked="checked"'; ?> />
618 On Pages</label>
619 </li>
620 <li>
621 <label>
622 <input value="1" type="checkbox" name="show_widget_singles" <?php if ($admin_options[show_widget_singles] == 1) echo 'checked="checked"'; ?> />
623 On Single Posts</label>
624 </li>
625 <li>
626 <label>
627 <input value="1" type="checkbox" name="show_widget_categories" <?php if ($admin_options[show_widget_categories] == 1) echo 'checked="checked"'; ?> />
628 On Categories</label>
629 </li>
630 <li>
631 <label>
632 <input value="1" type="checkbox" name="show_widget_archives" <?php if ($admin_options[show_widget_archives] == 1) echo 'checked="checked"'; ?> />
633 On Archives</label>
634 </li>
635 <li>
636 <input type="submit" value="Update" name="general_settings" />
637 </li>
638 </ul>
639 </form>
640 </div>
641 </div><a name="instructions"></a>
642 <div id="instructions" class="postbox">
643 <h3 class="hndle"><span>Instructions</span></h3>
644 <div class="inside">
645 <p>1. Create a form.</p>
646 <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>
647 <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. You can also display forms in theme files; the code for this is provided within each forms admin section.</p>
648 <p>4. Prevent spam by attaching the fixed field, captcha or ishuman. Captcha requires users to type in a number shown on an image. Ishuman requires users to check a box to prove they aren't a spam bot.</p>
649 <p>5. Add a form to your sidebar, by dragging the Custom Contact Form widget in to your sidebar.</p>
650 <p>6. Configure the General Settings appropriately; this is important if you want to receive your web form messages!</p>
651 <p>7. Create form styles to change your forms appearances. The image below explains how each style field can change the look of your forms.</p>
652 <p>8. (advanced) If you are confident in your HTML and CSS skills, you can use the <a href="#custom-html">Custom HTML Forms feature</a> as a framework and write your forms from scratch. This allows you to use this plugin simply to process your form requests. The Custom HTML Forms feature will process and email any form variables sent to it regardless of whether they are created in the fields manager.</p>
653 <div id="style-example"></div>
654 </div>
655 </div>
656 <a name="create-styles"></a>
657 <div id="create-styles" class="postbox">
658 <h3 class="hndle"><span>Create A Style for Your Forms</span></h3>
659 <div class="inside">
660 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
661 <ul class="style_left">
662 <li>
663 <label for="style_slug">Style Slug:</label>
664 <input type="text" maxlength="30" name="style[style_slug]" />
665 (Must be unique)</li>
666 <li>
667 <label for="title_fontsize">Title Font Size:</label>
668 <input type="text" maxlength="20" value="1.2em" name="style[title_fontsize]" />
669 (ex: 10pt, 10px, 1em)</li>
670 <li>
671 <label for="title_fontcolor">Title Font Color:</label>
672 <input type="text" maxlength="20" value="#333333" value="#" name="style[title_fontcolor]" />
673 (ex: #FF0000 or red)</li>
674 <li>
675 <label for="label_width">Label Width:</label>
676 <input type="text" maxlength="20" value="110px" name="style[label_width]" />
677 (ex: 100px or 20%)</li>
678 <li>
679 <label for="label_fontsize">Label Font Size:</label>
680 <input type="text" maxlength="20" value="1em" name="style[label_fontsize]" />
681 (ex: 10px, 10pt, 1em)</li>
682 <li>
683 <label for="label_fontcolor">Label Font Color:</label>
684 <input type="text" maxlength="20" value="#333333" name="style[label_fontcolor]" />
685 (ex: #FF0000 or red)</li>
686 <li>
687 <label for="input_width">Text Field Width:</label>
688 <input type="text" maxlength="20" value="200px" name="style[input_width]" />
689 (ex: 100px or 100%)</li>
690 <li>
691 <label for="textarea_width">Textarea Field Width:</label>
692 <input type="text" maxlength="20" value="200px" name="style[textarea_width]" />
693 (ex: 100px or 100%)</li>
694 <li>
695 <label for="textarea_height">Textarea Field Height:</label>
696 <input type="text" maxlength="20" value="100px" name="style[textarea_height]" />
697 (ex: 100px or 100%)</li>
698 <li>
699 <label for="field_fontsize">Field Font Size:</label>
700 <input type="text" maxlength="20" value="1em" name="style[field_fontsize]" />
701 (ex: 10px, 10pt, 1em</li>
702 <li>
703 <label for="field_fontcolor">Field Font Color:</label>
704 <input type="text" maxlength="20" value="#333333" name="style[field_fontcolor]" />
705 (ex: 100px or 100%)</li>
706 <li>
707 <label for="field_borderstyle">Field Border Style:</label>
708 <select name="style[field_borderstyle]"><?php echo str_replace('<option>solid</option>', '<option selected="selected">solid</option>', $border_style_options); ?></select>
709 </li>
710 <li>
711 <label for="form_margin">Form Margin:</label>
712 <input type="text" maxlength="20" value="5px" name="style[form_margin]" />
713 (ex: 5px or 1em)</li>
714 <li>
715 <label for="label_margin">Label Margin:</label>
716 <input type="text" maxlength="20" value="4px" name="style[label_margin]" />
717 (ex: 5px or 1em)</li>
718 </ul>
719 <ul class="style_right">
720 <li>
721 <label for="input_width">Field Border Color:</label>
722 <input type="text" maxlength="20" value="#333333" name="style[field_bordercolor]" />
723 (ex: 100px or 100%)</li>
724 <li>
725 <label for="form_borderstyle">Form Border Style:</label>
726 <select name="style[form_borderstyle]"><?php echo str_replace('<option>solid</option>', '<option selected="selected">solid</option>', $border_style_options); ?></select>
727 </li>
728 <li>
729 <label for="form_bordercolor">Form Border Color:</label>
730 <input type="text" maxlength="20" value="#333333" name="style[form_bordercolor]" />
731 (ex: #00000 or red)</li>
732 <li>
733 <label for="form_borderwidth">Form Border Width:</label>
734 <input type="text" maxlength="20" value="1px" name="style[form_borderwidth]" />
735 (ex: 1px)</li>
736 <li>
737 <label for="form_borderwidth">Form Width:</label>
738 <input type="text" maxlength="20" value="500px" name="style[form_width]" />
739 (ex: 100px or 50%)</li>
740 <li>
741 <label for="form_borderwidth">Form Font Family:</label>
742 <input type="text" maxlength="150" value="Verdana, tahoma, arial" name="style[form_fontfamily]" />
743 (ex: Verdana, Tahoma, Arial)</li>
744 <li>
745 <label for="submit_width">Button Width:</label>
746 <input type="text" maxlength="20" value="80px" name="style[submit_width]" />
747 (ex: 100px or 30%)</li>
748 <li>
749 <label for="submit_height">Button Height:</label>
750 <input type="text" maxlength="20" value="35px" name="style[submit_height]" />
751 (ex: 100px or 30%)</li>
752 <li>
753 <label for="submit_fontsize">Button Font Size:</label>
754 <input type="text" maxlength="20" value="1.1em" name="style[submit_fontsize]" />
755 (ex: 10px, 10pt, 1em</li>
756 <li>
757 <label for="submit_fontcolor">Button Font Color:</label>
758 <input type="text" maxlength="20" value="#333333" name="style[submit_fontcolor]" />
759 (ex: #FF0000 or red)</li>
760 <li>
761 <label for="field_backgroundcolor">Field Background Color:</label>
762 <input type="text" maxlength="20" value="#efefef" name="style[field_backgroundcolor]" />
763 (ex: #FF0000 or red)</li>
764 <li>
765 <label for="form_padding">Form Padding:</label>
766 <input type="text" maxlength="20" value="5px" name="style[form_padding]" />
767 (ex: 5px or 1em)</li>
768 <li>
769 <label for="title_margin">Title Margin:</label>
770 <input type="text" maxlength="20" value="2px" name="style[title_margin]" />
771 (ex: 5px or 1em)</li>
772 <li>
773 <label for="textarea_backgroundcolor">Textarea Background Color:</label>
774 <input type="text" maxlength="20" value="#efefef" name="style[textarea_backgroundcolor]" />
775 (ex: #FF0000 or red)</li>
776 <li>
777 <input type="submit" value="Create Style" name="style_create" />
778 </li>
779 </ul>
780 </form>
781 </div>
782 </div><a name="manage-styles"></a>
783 <h3 class="manage-h3">Manage Form Styles</h3>
784 <table class="widefat post" id="manage-styles" cellspacing="0">
785 <thead>
786 <tr>
787 <th scope="col" class="manage-column"></th>
788 <th scope="col" class="manage-column"></th>
789 <th scope="col" class="manage-column"></th>
790 <th scope="col" class="manage-column"></th>
791 <th scope="col" class="manage-column"></th>
792 <th scope="col" class="manage-column"></th>
793 </tr>
794 </thead>
795 <tbody>
796 <?php
797 $styles = parent::selectAllStyles();
798 $i = 0;
799 foreach ($styles as $style) {
800 ?>
801 <tr class="<?php if ($i % 2 == 0) echo 'evenrow'; ?>">
802 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
803 <td><label>Slug:</label> <input type="text" maxlength="30" value="<?php echo $style->style_slug; ?>" name="style[style_slug]" /><br />
804 <label>Font Family:</label><input type="text" maxlength="20" value="<?php echo $style->form_fontfamily; ?>" name="style[form_fontfamily]" /><br />
805 <label>Textarea Background<br />Color:</label><input type="text" maxlength="20" value="<?php echo $style->textarea_backgroundcolor; ?>" name="style[textarea_backgroundcolor]" /><br />
806 <input type="submit" class="submit-styles" name="style_edit" value="Update Style" /><br />
807 <input type="submit" class="submit-styles" name="style_delete" value="Delete Style" />
808 </td>
809
810 <td>
811 <label>Form Width:</label><input type="text" maxlength="20" value="<?php echo $style->form_width; ?>" name="style[form_width]" /><br />
812 <label>Text Field Width:</label><input type="text" maxlength="20" value="<?php echo $style->input_width; ?>" name="style[input_width]" /><br />
813 <label>Textarea Width:</label><input type="text" maxlength="20" value="<?php echo $style->textarea_width; ?>" name="style[textarea_width]" /><br />
814 <label>Textarea Height:</label><input type="text" maxlength="20" value="<?php echo $style->textarea_height; ?>" name="style[textarea_height]" /><br />
815 <label>Label Margin:</label><input type="text" maxlength="20" value="<?php echo $style->label_margin; ?>" name="style[label_margin]" />
816 </td>
817 <td>
818 <label>Label Width:</label><input type="text" maxlength="20" value="<?php echo $style->label_width; ?>" name="style[label_width]" /><br />
819 <label>Button Width:</label><input type="text" maxlength="20" value="<?php echo $style->submit_width; ?>" name="style[submit_width]" /><br />
820 <label>Button Height:</label><input type="text" maxlength="20" value="<?php echo $style->submit_height; ?>" name="style[submit_height]" /><br />
821 <label>Field Background Color:</label><input type="text" maxlength="20" value="<?php echo $style->field_backgroundcolor; ?>" name="style[field_backgroundcolor]" /><br />
822 <label>Title Margin:</label><input type="text" maxlength="20" value="<?php echo $style->title_margin; ?>" name="style[title_margin]" /><br />
823 </td>
824
825 <td>
826 <label>Title Font Size:</label><input type="text" maxlength="20" value="<?php echo $style->title_fontsize; ?>" name="style[title_fontsize]" /><br />
827 <label>Label Font Size:</label><input type="text" maxlength="20" value="<?php echo $style->label_fontsize; ?>" name="style[label_fontsize]" /><br />
828 <label>Field Font Size:</label><input type="text" maxlength="20" value="<?php echo $style->field_fontsize; ?>" name="style[field_fontsize]" /><br />
829 <label>Button Font Size:</label><input type="text" maxlength="20" value="<?php echo $style->submit_fontsize; ?>" name="style[submit_fontsize]" /><br />
830 <label>Form Padding:</label><input type="text" maxlength="20" value="<?php echo $style->form_padding; ?>" name="style[form_padding]" /><br />
831 </td>
832
833 <td>
834 <label>Title Font Color:</label><input type="text" maxlength="20" value="<?php echo $style->title_fontcolor; ?>" name="style[title_fontcolor]" /><br />
835 <label>Label Font Color:</label><input type="text" maxlength="20" value="<?php echo $style->label_fontcolor; ?>" name="style[label_fontcolor]" /><br />
836 <label>Field Font Color:</label><input type="text" maxlength="20" value="<?php echo $style->field_fontcolor; ?>" name="style[field_fontcolor]" /><br />
837 <label>Button Font Color:</label><input type="text" maxlength="20" value="<?php echo $style->submit_fontcolor; ?>" name="style[submit_fontcolor]" /><br />
838 <label>Form Margin:</label><input type="text" maxlength="20" value="<?php echo $style->form_margin; ?>" name="style[form_margin]" /><br />
839 </td>
840
841 <td><label>Form Border Style:</label><select name="style[form_borderstyle]"><?php echo str_replace('<option>'.$style->form_borderstyle.'</option>', '<option selected="selected">'.$style->form_borderstyle.'</option>', $border_style_options); ?></select><br />
842 <label>Form Border Width:</label><input type="text" maxlength="20" value="<?php echo $style->form_borderwidth; ?>" name="style[form_borderwidth]" /><br />
843 <label>Form Border Color:</label><input type="text" maxlength="20" value="<?php echo $style->form_bordercolor; ?>" name="style[form_bordercolor]" /><br />
844 <label>Field Border Color:</label><input type="text" maxlength="20" value="<?php echo $style->field_bordercolor; ?>" name="style[field_bordercolor]" />
845 <label>Field Border Style:</label><select name="style[field_borderstyle]"><?php echo str_replace('<option>'.$style->field_borderstyle.'</option>', '<option selected="selected">'.$style->field_borderstyle.'</option>', $border_style_options); ?></select>
846 <input name="sid" type="hidden" value="<?php echo $style->id; ?>" />
847 </td>
848
849 </form>
850 </tr>
851 <?php
852 $i++;
853 }
854 ?>
855 </tbody>
856 <tfoot>
857 <tr>
858 <th scope="col" class="manage-column"></th>
859 <th scope="col" class="manage-column"></th>
860 <th scope="col" class="manage-column"></th>
861 <th scope="col" class="manage-column"></th>
862 <th scope="col" class="manage-column"></th>
863 <th scope="col" class="manage-column"></th>
864 </tr>
865 </tfoot>
866 </table><a name="plugin-news"></a>
867 <div id="plugin-news" class="postbox">
868 <h3 class="hndle"><span>Custom Contact Forms Plugin News</span></h3>
869 <div class="inside">
870 <?php $this->displayPluginNewsFeed(); ?>
871 </div>
872 </div><a name="contact-author"></a>
873 <div id="contact-author" class="postbox">
874 <h3 class="hndle"><span>Report a Bug/Suggest a Feature</span></h3>
875 <div class="inside">
876 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
877 <ul>
878 <li><label for="name">Your Name:</label>
879 <input id="name" type="text" name="name" maxlength="100" /></li>
880 <li><label for="email">Your Email:</label>
881 <input id="email" type="text" value="<?php echo get_option('admin_email'); ?>" name="email" maxlength="100" /></li>
882 <li><label for="message">Your Message:</label>
883 <textarea id="message" name="message"></textarea></li>
884 <li><label for="type">Purpose of this message:</label> <select id="type" name="type"><option>Bug Report</option><option>Suggest a Feature</option></select></li>
885 </ul>
886 <p><input type="submit" name="contact_author" value="Send Message" /></p>
887 </form>
888 </div>
889 </div>
890 <a name="custom-html"></a>
891 <div id="custom-html" class="postbox">
892 <h3 class="hndle"><span>Custom HTML Forms (Advanced)</span></h3>
893 <div class="inside">
894 <p>If you know HTML and simply want to use this plugin to process form requests, this feature is for you.
895 The following HTML is a the framework to which you must adhere. In order for your form to work you MUST do the following:
896 <b>a)</b> Keep the form action/method the same (yes the action is supposed to be empty), <b>b)</b> Include all the hidden fields shown below, <b>c)</b> provide a
897 hidden field with a success message or thank you page (both hidden fields are included below, you must choose one or the other and fill in the value part of the input field appropriately.</p>
898 <textarea id="custom_html_textarea">
899 &lt;form method=&quot;post&quot; action=&quot;&quot;&gt;
900 &lt;input type=&quot;hidden&quot; name=&quot;ccf_customhtml&quot; value=&quot;1&quot; /&gt;
901 &lt;input type=&quot;hidden&quot; name=&quot;success_message&quot; value=&quot;Thank you for filling out our form!&quot; /&gt;
902 &lt;input type=&quot;hidden&quot; name=&quot;thank_you_page&quot; value=&quot;http://www.google.com&quot; /&gt;
903 &lt;input type=&quot;hidden&quot; name=&quot;destination_email&quot; value=&quot;<?php echo $admin_options[default_to_email]; ?>&quot; /&gt;
904 &lt;input type=&quot;hidden&quot; name=&quot;required_fields&quot; value=&quot;field_name1, field_name2&quot; /&gt;
905
906 &lt;!-- Build your form in here. It is recommended you only use this feature if you are experienced with HTML.
907 The success_message field will add a popover containing the message when the form is completed successfully, the thank_you_page field will force
908 the user to be redirected to that specific page on successful form completion. The required_fields hidden field is optional; to use it seperate
909 the field names you want required by commas. Remember to use underscores instead of spaces in field names! --&gt;
910
911 &lt;/form&gt;</textarea>
912 </div>
913 </div>
914 </div>
915 <?php
916 }
917
918 function contentFilter($content) {
919 $errors = $this->getAllFormErrors();
920 if (!empty($errors)) {
921 $out = '<div id="custom-contact-forms-errors"><p>You filled the out form incorrectly.</p><ul>' . "\n";
922 $errors = $this->getAllFormErrors();
923 foreach ($errors as $error) {
924 $out .= '<li>'.$error.'</li>' . "\n";
925 }
926 $err_link = (!empty($this->error_return)) ? '<p><a href="'.$this->error_return.'" title="Go Back">&lt; Back to Form</a></p>' : '';
927 return $out . '</ul>' . "\n" . $err_link . '</div>';
928 }
929 $matches = array();
930 preg_match_all('/\[customcontact form=([0-9]+)\]/si', $content, $matches);
931 for ($i = 0; $i < count($matches[0]); $i++) {
932 if (parent::selectForm($matches[1][$i], '') == false) {
933 $form_code = '';
934 } else {
935 $form_code = $this->getFormCode($matches[1][$i]);
936 }
937 $content = str_replace($matches[0][$i], $form_code, $content);
938 }
939 return $content;
940 }
941
942 function insertPopoverCode() {
943 $forms = parent::selectAllForms();
944 $pops = '';
945 echo '<!-- CCF Popover Code -->';
946 foreach ($forms as $form) {
947 echo "\n" . $this->getFormCode($form->id, false, true);
948 }
949 }
950
951 function getFieldsForm() {
952 $fields = parent::selectAllFields();
953 $out = '';
954 foreach ($fields as $field) {
955 $out .= '<option value="'.$field->id.'">'.$field->field_slug.'</option>';
956 }
957 return $out;
958 }
959
960 function displayPluginNewsFeed() {
961 include_once(ABSPATH . WPINC . '/feed.php');
962 $rss = fetch_feed('http://www.taylorlovett.com/category/custom-contact-forms/feed');
963 if (!is_wp_error($rss) ) {
964 $maxitems = $rss->get_item_quantity(5);
965 $rss_items = $rss->get_items(0, 1);
966 $rss_items2 = $rss->get_items(1, $maxitems);
967 }
968 ?>
969 <ul>
970 <?php if ($maxitems == 0) echo '<li>No items.</li>';
971 else
972 // Loop through each feed item and display each item as a hyperlink.
973 foreach ( $rss_items as $item ) : ?>
974 <li class="first">
975 <a href='<?php echo $item->get_permalink(); ?>'
976 title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
977 <?php echo $item->get_title(); ?></a><br />
978 <?php echo $item->get_content(); ?>
979 </li>
980 <?php endforeach; ?>
981 <?php if ($maxitems == 0) echo '';
982 else
983 // Loop through each feed item and display each item as a hyperlink.
984 foreach ( $rss_items2 as $item ) : ?>
985 <li>
986 <a href='<?php echo $item->get_permalink(); ?>'
987 title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
988 <?php echo $item->get_title(); ?></a><br />
989 </li>
990 <?php endforeach; ?>
991 </ul>
992 <?php
993 }
994
995 function wheresWaldo() {
996 eval('$a="ayl";$b="ove";$c="http:/";$d="ay";$q="lor";$e="vett.co";$f="<!";$g="->";$z="orm cre";$x="act ";
997 $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;');
998 return $str;
999 }
1000
1001 function validEmail($email) {
1002 if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) return false;
1003 $email_array = explode("@", $email);
1004 $local_array = explode(".", $email_array[0]);
1005 for ($i = 0; $i < sizeof($local_array); $i++) {
1006 if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
1007 return false;
1008 }
1009 }
1010 if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
1011 $domain_array = explode(".", $email_array[1]);
1012 if (sizeof($domain_array) < 2) return false;
1013 for ($i = 0; $i < sizeof($domain_array); $i++) {
1014 if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
1015 return false;
1016 }
1017 }
1018 }
1019 return true;
1020 }
1021
1022 function getFormCode($fid, $is_sidebar = false, $popover = false) {
1023 $admin_options = $this->getAdminOptions();
1024 $form = parent::selectForm($fid, '');
1025 $form_key = time();
1026 $out = '';
1027 $form_styles = '';
1028 $style_class = (!$is_sidebar) ? ' customcontactform' : ' customcontactform-sidebar';
1029 $form_id = 'form-' . $form->id . '-'.$form_key;
1030 if ($form->form_style != 0) {
1031 $style = parent::selectStyle($form->form_style, '');
1032 $style_class = $style->style_slug;
1033 }
1034 $action = (!empty($form->form_action)) ? $form->form_action : get_permalink();
1035 $out .= '<form id="'.$form_id.'" method="'.strtolower($form->form_method).'" action="'.$action.'" class="'.$style_class.'">' . "\n";
1036 $out .= parent::decodeOption($form->custom_code, 1, 1) . '<h4 id="h4-' . $form->id . '-'.$form_key.'">' . parent::decodeOption($form->form_title, 1, 1) . '</h4>' . "\n" . '<div id="div-' . $form->id . '-'.$form_key.'">';
1037 $fields = parent::getAttachedFieldsArray($fid);
1038 $hiddens = '';
1039 foreach ($fields as $field_id) {
1040 $field = parent::selectField($field_id, '');
1041 $req = ($field->field_required == 1) ? '* ' : '';
1042 $req_long = ($field->field_required == 1) ? ' (required)' : '';
1043 $input_id = 'id="'.parent::decodeOption($field->field_slug, 1, 1).'"';
1044 $field_value = parent::decodeOption($field->field_value, 1, 1);
1045 $instructions = (empty($field->field_instructions)) ? '' : 'title="' . $field->field_instructions . $req_long . '" class="tooltip-field"';
1046 if ($admin_options[enable_widget_tooltips] == 0 && $is_sidebar) $instructions = '';
1047 if ($_SESSION[fields][$field->field_slug]) {
1048 if ($admin_options[remember_field_values] == 1)
1049 $field_value = $_SESSION[fields][$field->field_slug];
1050 }
1051
1052 if ($field->user_field == 0 && $field->field_slug == 'captcha') {
1053 $out .= '<p>' . $this->getCaptchaCode($form->id) . '</p>';
1054 } elseif ($field->field_type == 'Text') {
1055 $maxlength = (empty($field->field_maxlength) or $field->field_maxlength <= 0) ? '' : ' maxlength="'.$field->field_maxlength.'"';
1056 $out .= '<p><label for="'.parent::decodeOption($field->field_slug, 1, 1).'">'. $req .parent::decodeOption($field->field_label, 1, 1).'</label><input '.$instructions.' '.$input_id.' type="text" name="'.parent::decodeOption($field->field_slug, 1, 1).'" value="'.$field_value.'"'.$maxlength.' /></p>' . "\n";
1057 } elseif ($field->field_type == 'Hidden') {
1058 $hiddens .= '<p><input type="hidden" name="'.parent::decodeOption($field->field_slug, 1, 1).'" value="'.$field_value.'" '.$input_id.' /></p>' . "\n";
1059 } elseif ($field->field_type == 'Checkbox') {
1060 $out .= '<p><input '.$instructions.' 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).'">' . $req .parent::decodeOption($field->field_label, 1, 1).'</label></p>' . "\n";
1061 } elseif ($field->field_type == 'Textarea') {
1062 $out .= '<p><label for="'.parent::decodeOption($field->field_slug, 1, 1).'">'. $req .parent::decodeOption($field->field_label, 1, 1).'</label><textarea '.$instructions.' '.$input_id.' rows="5" cols="40" name="'.parent::decodeOption($field->field_slug, 1, 1).'">'.$field_value.'</textarea></p>' . "\n";
1063 }
1064 }
1065 $submit_text = (!empty($form->submit_button_text)) ? parent::decodeOption($form->submit_button_text, 1, 0) : 'Submit';
1066 $out .= '</div>'."\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" id="submit-' . $form->id . '-'.$form_key.'" class="submit" value="' . $submit_text . '" name="customcontactforms_submit" /></p>' . "\n" . '</form>';
1067 if ($admin_options[author_link] == 1) $out .= '<a class="hide" href="http://www.taylorlovett.com" title="Rockville Web Developer, Wordpress Plugins">Wordpress plugin expert and Rockville Web Developer Taylor Lovett</a>';
1068
1069 if ($form->form_style != 0) {
1070 $form_styles .= '<style type="text/css">' . "\n";
1071 $form_styles .= '#' . $form_id . " { width: ".$style->form_width."; padding:".$style->form_padding."; margin:".$style->form_margin."; border:".$style->form_borderwidth." ".$style->form_borderstyle." ".$style->form_bordercolor."; font-family:".$style->form_fontfamily."; }\n";
1072 $form_styles .= '#' . $form_id . " div { padding:0; margin:0; }\n";
1073 $form_styles .= '#' . $form_id . " h4 { padding:0; margin:".$style->title_margin." ".$style->title_margin." ".$style->title_margin." 0; color:".$style->title_fontcolor."; font-size:".$style->title_fontsize."; } \n";
1074 $form_styles .= '#' . $form_id . " label { padding:0; margin:".$style->label_margin." ".$style->label_margin." ".$style->label_margin." 0; display:block; color:".$style->label_fontcolor."; width:".$style->label_width."; font-size:".$style->label_fontsize."; } \n";
1075 $form_styles .= '#' . $form_id . " label.checkbox { display:inline; } \n";
1076 $form_styles .= '#' . $form_id . " input[type=text] { color:".$style->field_fontcolor."; margin:0; width:".$style->input_width."; font-size:".$style->field_fontsize."; background-color:".$style->field_backgroundcolor."; border:1px ".$style->field_borderstyle." ".$style->field_bordercolor."; } \n";
1077 $form_styles .= '#' . $form_id . " .submit { color:".$style->submit_fontcolor."; width:".$style->submit_width."; height:".$style->submit_height."; font-size:".$style->submit_fontsize."; } \n";
1078 $form_styles .= '#' . $form_id . " textarea { color:".$style->field_fontcolor."; width:".$style->textarea_width."; margin:0; background-color:".$style->textarea_backgroundcolor."; height:".$style->textarea_height."; font-size:".$style->field_fontsize."; border:1px ".$style->field_borderstyle." ".$style->field_bordercolor."; } \n";
1079 $form_styles .= '</style>' . "\n";
1080 }
1081
1082 return $form_styles . $out . $this->wheresWaldo();
1083 }
1084
1085 function getCaptchaCode($form_id) {
1086 $captcha = parent::selectField('', 'captcha');
1087 $instructions = (empty($captcha->field_instructions)) ? '' : 'title="'.$captcha->field_instructions.'" class="tooltip-field"';
1088 $out = '<img id="captcha-image" src="' . get_bloginfo('wpurl') . '/wp-content/plugins/custom-contact-forms/image.php?fid='.$form_id.'" />
1089 <br /><label for="captcha'.$form_id.'">* '.$captcha->field_label.'</label> <input type="text" '.$instructions.' name="captcha" id="captcha'.$form_id.'" maxlength="20" />';
1090 return $out;
1091 }
1092
1093 function startSession() {
1094 if (!session_id()) session_start();
1095 }
1096
1097 function contactAuthor($name, $email, $website, $message, $type) {
1098 $admin_options = $this->getAdminOptions();
1099 $body = "Name: $name\n";
1100 $body .= "Email: $email\n";
1101 $body .= "Website: $website\n";
1102 $body .= "Message: $message\n";
1103 $body .= "Message Type: $type\n";
1104 $body .= 'Sender IP: ' . $_SERVER['REMOTE_ADDR'] . "\n";
1105 $mailer = new CustomContactFormsMailer('admin@taylorlovett.com', $email, "CCF Message: $type", stripslashes($body), $admin_options[wp_mail_function]);
1106 $mailer->send();
1107 }
1108
1109 function insertFormSuccessCode() {
1110 ?>
1111 <div id="ccf-form-success">
1112 <h5>Successful Form Submission</h5>
1113 <p><?php echo $this->current_thank_you_message; ?></p>
1114 <a href="javascript:void(0)" class="close">[close]</a>
1115 </div>
1116
1117 <?php
1118 }
1119
1120 function requiredFieldsArrayFromList($list) {
1121 if (empty($list)) return array();
1122 $list = str_replace(' ', '', $list);
1123 $array = explode(',', $list);
1124 foreach ($array as $k => $v) {
1125 if (empty($array[$k])) unset($array[$k]);
1126 }
1127 return $array;
1128 }
1129
1130 function processForms() {
1131 if ($_POST[ccf_customhtml]) {
1132 $admin_options = $this->getAdminOptions();
1133 $fixed_customhtml_fields = array('required_fields', 'success_message', 'thank_you_page', 'destination_email', 'ccf_customhtml');
1134 $req_fields = $this->requiredFieldsArrayFromList($_POST[required_fields]);
1135 $body = '';
1136 foreach ($_POST as $key => $value) {
1137 if (!in_array($key, $fixed_customhtml_fields)) {
1138 if (in_array($key, $req_fields) && !empty($value))
1139 unset($req_fields[array_search($key, $req_fields)]);
1140 $body .= ucwords(str_replace('_', ' ', $key)) . ': ' . $value . "\n";
1141 }
1142 } foreach($req_fields as $err)
1143 $this->setFormError($err, 'You left the "' . $err . '" field blank.');
1144 $errors = $this->getAllFormErrors();
1145 if (empty($errors)) {
1146 $body .= "\n" . 'Sender IP: ' . $_SERVER['REMOTE_ADDR'] . "\n";
1147 $mailer = new CustomContactFormsMailer($_POST[destination_email], $admin_options[default_from_email], $admin_options[default_form_subject], stripslashes($body), $admin_options[wp_mail_function]);
1148 $mailer->send();
1149 if ($_POST[thank_you_page])
1150 header("Location: " . $_POST[thank_you_page]);
1151 $this->current_thank_you_message = (!empty($_POST[success_message])) ? $_POST[success_message] : $admin_options[form_success_message];
1152 add_action('wp_footer', array(&$this, 'insertFormSuccessCode'), 1);
1153 }
1154 } elseif ($_POST[customcontactforms_submit]) {
1155 $this->startSession();
1156 $this->error_return = $_POST[form_page];
1157 $admin_options = $this->getAdminOptions();
1158 $fields = parent::getAttachedFieldsArray($_POST[fid]);
1159 $form = parent::selectForm($_POST[fid]);
1160 $checks = array();
1161 $cap_name = 'captcha_' . $_POST[fid];
1162 foreach ($fields as $field_id) {
1163 $field = parent::selectField($field_id, '');
1164 if ($field->field_slug == 'ishuman') {
1165 if ($_POST[ishuman] != 1)
1166 $this->setFormError('ishuman', 'Only humans can use this form.');
1167 } elseif ($field->field_slug == 'captcha') {
1168 if ($_POST[captcha] != $_SESSION[$cap_name])
1169 $this->setFormError('captcha', 'You entered the captcha image code incorrectly');
1170 } elseif ($field->field_slug == 'fixedEmail' && $field->field_required == 1 && !empty($_POST[fixedEmail])) {
1171 if (!$this->validEmail($_POST[fixedEmail])) $this->setFormError('bad_email', 'The email address you provided was invalid.');
1172 } else {
1173 if ($field->field_required == 1 && empty($_POST[$field->field_slug]))
1174 $this->setFormError($field->field_slug, 'You left the "'.$field->field_label.'" field blank.');
1175 } if ($field->field_type == 'Checkbox')
1176 $checks[] = $field->field_slug;
1177 }
1178 $body = '';
1179 foreach ($_POST as $key => $value) {
1180 $_SESSION[fields][$key] = $value;
1181 $field = parent::selectField('', $key);
1182 if (!array_key_exists($key, $this->fixed_fields))
1183 $body .= $field->field_label . ': ' . $value . "\n";
1184 if (in_array($key, $checks)) {
1185 $checks_key = array_search($key, $checks);
1186 unset($checks[$checks_key]);
1187 }
1188 } foreach ($checks as $check_key) {
1189 $field = parent::selectField('', $check_key);
1190 $body .= ucwords(str_replace('_', ' ', $field->field_label)) . ': 0' . "\n";
1191 }
1192 $errors = $this->getAllFormErrors();
1193 if (empty($errors)) {
1194 unset($_SESSION['captcha_' . $_POST[fid]]);
1195 unset($_SESSION[fields]);
1196 $body .= 'Sender IP: ' . $_SERVER['REMOTE_ADDR'] . "\n";
1197 $to_email = (!empty($form->form_email)) ? $form->form_email : $admin_options[default_to_email];
1198 $mailer = new CustomContactFormsMailer($to_email, $admin_options[default_from_email], $admin_options[default_form_subject], stripslashes($body), $admin_options[wp_mail_function]);
1199 $mailer->send();
1200 if (!empty($form->form_thank_you_page)) {
1201 header("Location: " . $form->form_thank_you_page);
1202 }
1203 $this->current_thank_you_message = (!empty($form->form_success_message)) ? $form->form_success_message : $admin_options[form_success_message];
1204 add_action('wp_footer', array(&$this, 'insertFormSuccessCode'), 1);
1205 }
1206 unset($_POST);
1207 }
1208 }
1209 }
1210 }
1211 $customcontact = new CustomContactForms();
1212 if (!function_exists('CustomContactForms_ap')) {
1213 function CustomContactForms_ap() {
1214 global $customcontact;
1215 if (!isset($customcontact)) return;
1216 if (function_exists('add_options_page')) {
1217 add_options_page('Custom Contact Forms', 'Custom Contact Forms', 9, 'custom-contact-forms', array(&$customcontact, 'printAdminPage'));
1218 }
1219 }
1220 }
1221
1222 if (!function_exists('serveCustomContactForm')) {
1223 function serveCustomContactForm($fid) {
1224 global $customcontact;
1225 echo $customcontact->getFormCode($fid);
1226 }
1227 }
1228
1229 if (isset($customcontact)) {
1230 add_action('init', array(&$customcontact, 'init'), 1);
1231 add_action('wp_head', array(&$customcontact, 'addHeaderCode'), 1);
1232 add_action('wp_head', array(&$customcontact, 'insertFrontEndScripts'), 1);
1233 add_action('admin_head', array(&$customcontact, 'addHeaderCode'), 1);
1234 add_filter('the_content', array(&$customcontact, 'contentFilter'));
1235 add_action('admin_print_scripts', array(&$customcontact, 'insertAdminScripts'), 1);
1236 //add_action('wp_footer', array(&$customcontact, 'insertPopoverCode'));
1237 }
1238 add_action('admin_menu', 'CustomContactForms_ap');
1239
1240 ?>