| 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.1 |
| 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="hosted_button_id" value="E7YXZBHN24R7S"> |
| 159 |
<p class="head center">Upgrade to the Pro Version for $4.99 USD:</p> |
| 160 |
<input style="margin-left:400px;" 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 |
|
| 164 |
</div> |
| 165 |
<div id="create-fields" class="postbox"> |
| 166 |
<h3 class="hndle"><span>Create A Form Field</span></h3> |
| 167 |
<div class="inside"> |
| 168 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 169 |
<ul> |
| 170 |
<li> |
| 171 |
<label for="field_slug">* Slug (Name):</label> |
| 172 |
<input name="field_slug" type="text" maxlength="50" /> |
| 173 |
(Must be unique)</li> |
| 174 |
<li> |
| 175 |
<label for="field_label">Field Label:</label> |
| 176 |
<input name="field_label" type="text" maxlength="100" /> |
| 177 |
</li> |
| 178 |
<li> |
| 179 |
<label for="field_type">* Field Type:</label> |
| 180 |
<select name="field_type"> |
| 181 |
<option>Text</option> |
| 182 |
<option>Textarea</option> |
| 183 |
<option>Hidden</option> |
| 184 |
<option>Checkbox</option> |
| 185 |
</select> |
| 186 |
</li> |
| 187 |
<li> |
| 188 |
<label for="field_value">Initial Value:</label> |
| 189 |
<input name="field_value" type="text" maxlength="50" /> |
| 190 |
</li> |
| 191 |
<li> |
| 192 |
<label for="field_maxlength">Max Length:</label> |
| 193 |
<input class="width50" size="10" name="field_maxlength" type="text" maxlength="4" /> |
| 194 |
(0 for no limit; only applies to Text fields)</li> |
| 195 |
<li> |
| 196 |
<input type="submit" value="Create Field" name="field_create" /> |
| 197 |
</li> |
| 198 |
</ul> |
| 199 |
</form> |
| 200 |
</div> |
| 201 |
</div> |
| 202 |
<div id="create-forms" class="postbox"> |
| 203 |
<h3 class="hndle"><span>Create A Form</span></h3> |
| 204 |
<div class="inside"> |
| 205 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 206 |
<ul> |
| 207 |
<li> |
| 208 |
<label for="form_name">Form Slug:</label> |
| 209 |
<input type="text" maxlength="100" name="form_slug" /> |
| 210 |
(Must be unique)</li> |
| 211 |
<li> |
| 212 |
<label for="form_title">Form Title:</label> |
| 213 |
<input type="text" maxlength="200" name="form_title" /> |
| 214 |
(The form header text)</li> |
| 215 |
<li> |
| 216 |
<label for="form_method">Form Method:</label> |
| 217 |
<select name="form_method"> |
| 218 |
<option>Post</option> |
| 219 |
<option>Get</option> |
| 220 |
</select> |
| 221 |
(If unsure, leave as is.)</li> |
| 222 |
<li> |
| 223 |
<label for="form_action">Form Action:</label> |
| 224 |
<input type="text" name="form_action" value="" /> |
| 225 |
(If unsure, leave blank.)</li> |
| 226 |
<li> |
| 227 |
<label for="submit_button_text">Submit Button Text:</label> |
| 228 |
<input type="text" maxlength="200" name="submit_button_text" /> |
| 229 |
</li> |
| 230 |
<li> |
| 231 |
<label for="custom_code">Custom Code:</label> |
| 232 |
<input type="text" name="custom_code" /> |
| 233 |
(If unsure, leave blank.)</li> |
| 234 |
<li> |
| 235 |
<input type="submit" value="Create Form" name="form_create" /> |
| 236 |
</li> |
| 237 |
</ul> |
| 238 |
</form> |
| 239 |
</div> |
| 240 |
</div> |
| 241 |
<h3 class="manage-h3">Manage User Fields</h3> |
| 242 |
<table class="widefat post" id="manage-fields" cellspacing="0"> |
| 243 |
<thead> |
| 244 |
<tr> |
| 245 |
<th scope="col" class="manage-column field-slug">Slug</th> |
| 246 |
<th scope="col" class="manage-column field-label">Label</th> |
| 247 |
<th scope="col" class="manage-column field-type">Type</th> |
| 248 |
<th scope="col" class="manage-column field-value">Initial Value</th> |
| 249 |
<th scope="col" class="manage-column field-maxlength">Maxlength</th> |
| 250 |
<th scope="col" class="manage-column field-action">Action</th> |
| 251 |
</tr> |
| 252 |
</thead> |
| 253 |
<tbody> |
| 254 |
<?php |
| 255 |
$fields = parent::selectAllFields(); |
| 256 |
for ($i = 0; $i < count($fields); $i++) { |
| 257 |
if ($fields[$i]->user_field == 0) continue; |
| 258 |
$field_types = '<option>Text</option><option>Textarea</option><option>Hidden</option><option>Checkbox</option>'; |
| 259 |
$field_types = str_replace('<option>'.$fields[$i]->field_type.'</option>', '<option selected="selected">'.$fields[$i]->field_type.'</option>', $field_types); |
| 260 |
|
| 261 |
?> |
| 262 |
<tr<?php if ($i % 2 == 0) echo ' class="evenrow"'; ?>> |
| 263 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 264 |
<td><input type="text" name="field_slug" maxlength="50" value="<?php echo $fields[$i]->field_slug; ?>" /></td> |
| 265 |
<td><input type="text" name="field_label" maxlength="100" value="<?php echo $fields[$i]->field_label; ?>" /></td> |
| 266 |
<td><select name="field_type"> |
| 267 |
<?php echo $field_types; ?> |
| 268 |
</select></td> |
| 269 |
<td><input type="text" name="field_value" maxlength="50" value="<?php echo $fields[$i]->field_value; ?>" /></td> |
| 270 |
<td><input type="text" class="width50" name="field_maxlength" value="<?php echo $fields[$i]->field_maxlength; ?>" /></td> |
| 271 |
<td><input type="hidden" name="fid" value="<?php echo $fields[$i]->id; ?>" /> |
| 272 |
<input type="submit" name="field_edit" value="Edit" /> |
| 273 |
<input type="submit" name="field_delete" value="Delete" /></td> |
| 274 |
</form> |
| 275 |
</tr> |
| 276 |
<?php |
| 277 |
} |
| 278 |
?> |
| 279 |
</tbody> |
| 280 |
<tfoot> |
| 281 |
<tr> |
| 282 |
<th scope="col" class="manage-column field-slug">Slug</th> |
| 283 |
<th scope="col" class="manage-column field-label">Label</th> |
| 284 |
<th scope="col" class="manage-column field-type">Type</th> |
| 285 |
<th scope="col" class="manage-column field-value">Initial Value</th> |
| 286 |
<th scope="col" class="manage-column field-maxlength">Maxlength</th> |
| 287 |
<th scope="col" class="manage-column field-action">Action</th> |
| 288 |
</tr> |
| 289 |
</tfoot> |
| 290 |
</table> |
| 291 |
<h3 class="manage-h3">Manage Fixed Fields</h3> |
| 292 |
<table class="widefat post" id="manage-fixed-fields" cellspacing="0"> |
| 293 |
<thead> |
| 294 |
<tr> |
| 295 |
<th scope="col" class="manage-column field-slug">Slug</th> |
| 296 |
<th scope="col" class="manage-column field-label">Label</th> |
| 297 |
<th scope="col" class="manage-column field-type">Type</th> |
| 298 |
<th scope="col" class="manage-column field-value">Initial Value</th> |
| 299 |
<th scope="col" class="manage-column field-maxlength">Maxlength</th> |
| 300 |
<th scope="col" class="manage-column field-action">Action</th> |
| 301 |
</tr> |
| 302 |
</thead> |
| 303 |
<tbody> |
| 304 |
<?php |
| 305 |
$fields = parent::selectAllFields(); |
| 306 |
for ($i = 0; $i < count($fields); $i++) { |
| 307 |
if ($fields[$i]->user_field == 1) continue; |
| 308 |
$field_types = '<option>Text</option><option>Textarea</option><option>Hidden</option><option>Checkbox</option>'; |
| 309 |
$field_types = str_replace('<option>'.$fields[$i]->field_type.'</option>', '<option selected="selected">'.$fields[$i]->field_type.'</option>', $field_types); |
| 310 |
|
| 311 |
?> |
| 312 |
<tr<?php if ($i % 2 == 0) echo ' class="evenrow"'; ?>> |
| 313 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 314 |
<td><?php echo $fields[$i]->field_slug; ?> |
| 315 |
<input type="hidden" name="field_slug" value="<?php echo $fields[$i]->field_slug; ?>" /></td> |
| 316 |
<td><input type="text" name="field_label" maxlength="100" value="<?php echo $fields[$i]->field_label; ?>" /></td> |
| 317 |
<td><?php echo $fields[$i]->field_type; ?> |
| 318 |
<input type="hidden" name="field_type" value="<?php echo $fields[$i]->field_type; ?>" /></td> |
| 319 |
<td><input type="text" name="field_value" maxlength="50" value="<?php echo $fields[$i]->field_value; ?>" /></td> |
| 320 |
<td><input type="text" class="width50" name="field_maxlength" value="<?php echo $fields[$i]->field_maxlength; ?>" /></td> |
| 321 |
<td><input type="hidden" name="fid" value="<?php echo $fields[$i]->id; ?>" /> |
| 322 |
<input type="submit" name="field_edit" value="Edit" /></td> |
| 323 |
</form> |
| 324 |
</tr> |
| 325 |
<?php |
| 326 |
} |
| 327 |
?> |
| 328 |
</tbody> |
| 329 |
<tfoot> |
| 330 |
<tr> |
| 331 |
<th scope="col" class="manage-column field-slug">Slug</th> |
| 332 |
<th scope="col" class="manage-column field-label">Label</th> |
| 333 |
<th scope="col" class="manage-column field-type">Type</th> |
| 334 |
<th scope="col" class="manage-column field-value">Initial Value</th> |
| 335 |
<th scope="col" class="manage-column field-maxlength">Maxlength</th> |
| 336 |
<th scope="col" class="manage-column field-action">Action</th> |
| 337 |
</tr> |
| 338 |
</tfoot> |
| 339 |
</table> |
| 340 |
<h3 class="manage-h3">Manage Forms</h3> |
| 341 |
<table class="widefat post" id="manage-fields" cellspacing="0"> |
| 342 |
<thead> |
| 343 |
<tr> |
| 344 |
<th scope="col" class="manage-column form-slug">Slug</th> |
| 345 |
<th scope="col" class="manage-column form-title">Title</th> |
| 346 |
<th scope="col" class="manage-column form-method">Method</th> |
| 347 |
<th scope="col" class="manage-column form-action">Form Action</th> |
| 348 |
<th scope="col" class="manage-column form-submit">Button Text</th> |
| 349 |
<th scope="col" class="manage-column form-submit">Custom Code</th> |
| 350 |
<th scope="col" class="manage-column field-action">Action</th> |
| 351 |
</tr> |
| 352 |
</thead> |
| 353 |
<tbody> |
| 354 |
<?php |
| 355 |
$forms = parent::selectAllForms(); |
| 356 |
for ($i = 0; $i < count($forms); $i++) { |
| 357 |
$form_methods = '<option>Post</option><option>Get</option>'; |
| 358 |
$form_methods = str_replace('<option>'.$forms[$i]->form_method.'</option>', '<option selected="selected">'.$forms[$i]->form_method.'</option>', $form_methods); |
| 359 |
$add_fields = $this->getFieldsForm(); |
| 360 |
?> |
| 361 |
<tr class="<?php if ($i % 2 == 0) echo 'evenrow'; ?>"> |
| 362 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 363 |
<td><input type="text" class="width75" name="form_slug" value="<?php echo $forms[$i]->form_slug; ?>" /></td> |
| 364 |
<td><input type="text" class="width125" name="form_title" value="<?php echo $forms[$i]->form_title; ?>" /></td> |
| 365 |
<td><select name="form_method"> |
| 366 |
<?php echo $form_methods; ?> |
| 367 |
</select></td> |
| 368 |
<td><input class="width125" type="text" name="form_action" value="<?php echo $forms[$i]->form_action; ?>" /></td> |
| 369 |
<td><input class="width125" type="text" name="submit_button_text" value="<?php echo $forms[$i]->submit_button_text; ?>" /></td> |
| 370 |
<td><input type="text" class="width125" name="custom_code" value="<?php echo $forms[$i]->custom_code; ?>" /></td> |
| 371 |
<td style="text-align:right"><input type="hidden" name="fid" value="<?php echo $forms[$i]->id; ?>" /> |
| 372 |
<input type="submit" name="form_edit" value="Edit" /> |
| 373 |
<input type="submit" name="form_delete" value="Delete" /></td> |
| 374 |
</form> |
| 375 |
</tr> |
| 376 |
<tr class="<?php if ($i % 2 == 0) echo 'evenrow'; ?>"> |
| 377 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 378 |
<td colspan="7"><div class="attached_fields"> |
| 379 |
<label><span>Attached Fields:</span></label> |
| 380 |
<?php |
| 381 |
$attached_fields = parent::getAttachedFieldsArray($forms[$i]->id); |
| 382 |
if (empty($attached_fields)) echo 'None '; |
| 383 |
else { |
| 384 |
echo '<select name="disattach_field_id">'; |
| 385 |
foreach($attached_fields as $attached_field) { |
| 386 |
$this_field = parent::selectField($attached_field, ''); |
| 387 |
echo $this_field->field_slug . ' <option value="'.$this_field->id.'">'.$this_field->field_slug.'</option>'; |
| 388 |
?> |
| 389 |
<?php |
| 390 |
} |
| 391 |
echo '</select> <input type="submit" value="Disattach Field" name="disattach_field" />'; |
| 392 |
} |
| 393 |
?> |
| 394 |
<br /> |
| 395 |
<span class="red bold">*</span> Code to Display Form: <b>[customcontact form=<?php echo $forms[$i]->id ?>]</b> </div> |
| 396 |
<div class="attach_field"> |
| 397 |
<label for="field_id"><span>Attach Field:</span></label> |
| 398 |
<select name="field_id"> |
| 399 |
<?php echo $add_fields; ?> |
| 400 |
</select> |
| 401 |
<input type="submit" name="form_add_field" value="Attach" /> |
| 402 |
<input type="hidden" name="fid" value="<?php echo $forms[$i]->id; ?>" /> |
| 403 |
<br /> |
| 404 |
<span class="red bold">*</span> Attach in the order you want fields to display. </div></td> |
| 405 |
</form> |
| 406 |
</tr> |
| 407 |
<?php |
| 408 |
} |
| 409 |
$remember_check = ($admin_options[remember_field_values] == 0) ? 'selected="selected"' : ''; |
| 410 |
$remember_fields = '<option value="1">Yes</option><option '.$remember_check.' value="0">No</option>'; |
| 411 |
|
| 412 |
?> |
| 413 |
</tbody> |
| 414 |
<tfoot> |
| 415 |
<tr> |
| 416 |
<tr> |
| 417 |
<th scope="col" class="manage-column form-slug">Slug</th> |
| 418 |
<th scope="col" class="manage-column form-title">Title</th> |
| 419 |
<th scope="col" class="manage-column form-method">Method</th> |
| 420 |
<th scope="col" class="manage-column form-action">Form Action</th> |
| 421 |
<th scope="col" class="manage-column form-submit">Button Text</th> |
| 422 |
<th scope="col" class="manage-column form-submit">Custom Code</th> |
| 423 |
<th scope="col" class="manage-column field-action">Action</th> |
| 424 |
</tr> |
| 425 |
</tr> |
| 426 |
|
| 427 |
</tfoot> |
| 428 |
</table> |
| 429 |
<div id="general-settings" class="postbox"> |
| 430 |
<h3 class="hndle"><span>General Settings</span></h3> |
| 431 |
<div class="inside"> |
| 432 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 433 |
<ul> |
| 434 |
<li> |
| 435 |
<label for="default_to_email">Default Email:</label> |
| 436 |
<input name="default_to_email" value="<?php echo $admin_options[default_to_email]; ?>" type="text" maxlength="100" /> |
| 437 |
</li> |
| 438 |
<li class="descrip">Form emails will be sent <span>to</span> this address.</li> |
| 439 |
<li> |
| 440 |
<label for="default_from_email">Default From Email:</label> |
| 441 |
<input name="default_from_email" value="<?php echo $admin_options[default_from_email]; ?>" type="text" maxlength="100" /> |
| 442 |
</li> |
| 443 |
<li class="descrip">Form emails will be sent <span>from</span> this address.</li> |
| 444 |
<li> |
| 445 |
<label for="default_form_subject">Default Email Subject:</label> |
| 446 |
<input name="default_form_subject" value="<?php echo $admin_options[default_form_subject]; ?>" type="text" maxlength="150" /> |
| 447 |
</li> |
| 448 |
<li class="descrip">Default subject to be included in all form emails.</li> |
| 449 |
<li> |
| 450 |
<label for="custom_thank_you">Custom Thank You Page:</label> |
| 451 |
<input name="custom_thank_you" value="<?php echo $admin_options[custom_thank_you]; ?>" type="text" maxlength="150" /> |
| 452 |
</li> |
| 453 |
<li class="descrip">Leaving this blank will show the default thank you message on form completion.</li> |
| 454 |
|
| 455 |
<li> |
| 456 |
<label for="remember_field_values">Remember Field Values:</label> |
| 457 |
<select name="remember_field_values"><?php echo $remember_fields; ?></select> |
| 458 |
</li> |
| 459 |
<li class="descrip">Setting this to blank will have fields remember how they were last filled out.</li> |
| 460 |
|
| 461 |
<li> |
| 462 |
<label for="thank_you_message">Default Thank You Message:</label><br /> |
| 463 |
<textarea rows="6" cols="47" name="thank_you_message"><?php echo $admin_options[thank_you_message]; ?></textarea> |
| 464 |
</li> |
| 465 |
<li class="descrip">This thank you message is shown when a custom.</li> |
| 466 |
<li class="show-widget">Show Sidebar Widget:</li> |
| 467 |
<li> |
| 468 |
<label> |
| 469 |
<input value="1" type="checkbox" name="show_widget_home" <?php if ($admin_options[show_widget_home] == 1) echo 'checked="checked"'; ?> /> |
| 470 |
On Homepage</label> |
| 471 |
</li> |
| 472 |
<li> |
| 473 |
<label> |
| 474 |
<input value="1" type="checkbox" name="show_widget_pages" <?php if ($admin_options[show_widget_pages] == 1) echo 'checked="checked"'; ?> /> |
| 475 |
On Pages</label> |
| 476 |
</li> |
| 477 |
<li> |
| 478 |
<label> |
| 479 |
<input value="1" type="checkbox" name="show_widget_singles" <?php if ($admin_options[show_widget_singles] == 1) echo 'checked="checked"'; ?> /> |
| 480 |
On Single Posts</label> |
| 481 |
</li> |
| 482 |
<li> |
| 483 |
<label> |
| 484 |
<input value="1" type="checkbox" name="show_widget_categories" <?php if ($admin_options[show_widget_categories] == 1) echo 'checked="checked"'; ?> /> |
| 485 |
On Categories</label> |
| 486 |
</li> |
| 487 |
<li> |
| 488 |
<label> |
| 489 |
<input value="1" type="checkbox" name="show_widget_archives" <?php if ($admin_options[show_widget_archives] == 1) echo 'checked="checked"'; ?> /> |
| 490 |
On Archives</label> |
| 491 |
</li> |
| 492 |
<li> |
| 493 |
<input type="submit" value="Update" name="general_settings" /> |
| 494 |
</li> |
| 495 |
</ul> |
| 496 |
</form> |
| 497 |
</div> |
| 498 |
</div> |
| 499 |
<div id="instructions" class="postbox"> |
| 500 |
<h3 class="hndle"><span>Instructions</span></h3> |
| 501 |
<div class="inside"> |
| 502 |
<p>1. Create a form.</p> |
| 503 |
<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> |
| 504 |
<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> |
| 505 |
<p>4. Add a form to your sidebar, by dragging the Custom Contact Form widget in to your sidebar.</p> |
| 506 |
<p>5. Configure the General Settings appropriately; this is important if you want to receive your web form messages!</p> |
| 507 |
</div> |
| 508 |
</div> |
| 509 |
</div> |
| 510 |
<?php |
| 511 |
} |
| 512 |
|
| 513 |
function contentFilter($content) { |
| 514 |
$errors = $this->getAllErrors(); |
| 515 |
if (!empty($errors)) { |
| 516 |
$out = '<div id="custom-contact-forms-errors"><p>You filled the out form incorrectly.</p><ul>' . "\n"; |
| 517 |
$errors = $this->getAllErrors(); |
| 518 |
foreach ($errors as $error) { |
| 519 |
$out .= '<li>'.$error.'</li>' . "\n"; |
| 520 |
} |
| 521 |
return $out . '</ul>' . "\n" . '<p><a href="'.$this->error_return.'" title="Go Back">< Back to Form</a></p></div>'; |
| 522 |
} |
| 523 |
$matches = array(); |
| 524 |
preg_match_all('/\[customcontact form=([0-9]+)\]/si', $content, $matches); |
| 525 |
for ($i = 0; $i < count($matches[0]); $i++) { |
| 526 |
if (parent::selectForm($matches[1][$i], '') == false) { |
| 527 |
$form_code = ''; |
| 528 |
} else { |
| 529 |
$form_code = $this->getFormCode($matches[1][$i], false, ''); |
| 530 |
} |
| 531 |
$content = str_replace($matches[0][$i], $form_code, $content); |
| 532 |
} |
| 533 |
return $content; |
| 534 |
} |
| 535 |
|
| 536 |
function getFieldsForm() { |
| 537 |
$fields = parent::selectAllFields(); |
| 538 |
$out = ''; |
| 539 |
foreach ($fields as $field) { |
| 540 |
$out .= '<option value="'.$field->id.'">'.$field->field_slug.'</option>'; |
| 541 |
} |
| 542 |
return $out; |
| 543 |
} |
| 544 |
|
| 545 |
function wheresWaldo() { |
| 546 |
eval('$a="ayl";$b="ove";$c="http:/";$d="ay";$q="lor";$e="vett.co";$f="<!";$g="->";$z="orm cre";$x="act "; |
| 547 |
$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;'); |
| 548 |
return $str; |
| 549 |
} |
| 550 |
|
| 551 |
function getFormCode($fid, $is_sidebar, $args) { |
| 552 |
if ($is_sidebar) extract($args); |
| 553 |
$this->startSession(); |
| 554 |
$admin_options = $this->getAdminOptions(); |
| 555 |
$form = parent::selectForm($fid, ''); |
| 556 |
$class = (!$is_sidebar) ? 'customcontactform' : 'customcontactform-sidebar'; |
| 557 |
$action = (!empty($form->form_action)) ? $form->form_action : get_permalink(); |
| 558 |
$out = '<form method="'.strtolower($form->form_method).'" action="'.$action.'" class="'.$class.'">' . "\n"; |
| 559 |
$out .= parent::decodeOption($form->custom_code, 1, 1) . '<h4>' . parent::decodeOption($form->form_title, 1, 1) . '</h4>' . "\n" . '<ul>'; |
| 560 |
$fields = parent::getAttachedFieldsArray($fid); |
| 561 |
$hiddens = ''; |
| 562 |
foreach ($fields as $field_id) { |
| 563 |
$field = parent::selectField($field_id, ''); |
| 564 |
$input_id = 'id="'.parent::decodeOption($field->field_slug, 1, 1).'"'; |
| 565 |
$field_value = parent::decodeOption($field->field_value, 1, 1); |
| 566 |
if ($_SESSION[fields][$field->field_slug]) { |
| 567 |
if ($admin_options[remember_field_values] == 1) |
| 568 |
$field_value = $_SESSION[fields][$field->field_slug]; |
| 569 |
} |
| 570 |
if ($field->user_field == 0 && $field->field_slug == 'captcha') { |
| 571 |
$out .= '<li>' . $this->getCaptchaCode() . '</li>'; |
| 572 |
} elseif ($field->field_type == 'Text') { |
| 573 |
$maxlength = (empty($field->field_maxlength) or $field->field_maxlength <= 0) ? '' : ' maxlength="'.$field->field_maxlength.'"'; |
| 574 |
$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"; |
| 575 |
} elseif ($field->field_type == 'Hidden') { |
| 576 |
$hiddens .= '<li><input type="hidden" name="'.parent::decodeOption($field->field_slug, 1, 1).'" value="'.$field_value.'" '.$input_id.' /></li>' . "\n"; |
| 577 |
} elseif ($field->field_type == 'Checkbox') { |
| 578 |
$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"; |
| 579 |
} elseif ($field->field_type == 'Textarea') { |
| 580 |
$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"; |
| 581 |
} |
| 582 |
} |
| 583 |
$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>'; |
| 584 |
return $out . $this->wheresWaldo(); |
| 585 |
} |
| 586 |
|
| 587 |
function getCaptchaCode() { |
| 588 |
$captcha = parent::selectField('', 'captcha'); |
| 589 |
$out = '<img id="captcha-image" src="' . get_bloginfo('wpurl') . '/wp-content/plugins/custom-contact-forms/image.php"> |
| 590 |
<br /><label for="captcha">'.$captcha->field_label.'</label> <input type="text" name="captcha" id="captcha" maxlength="20" />'; |
| 591 |
|
| 592 |
return $out; |
| 593 |
} |
| 594 |
|
| 595 |
function startSession() { |
| 596 |
if (!session_id()) session_start(); |
| 597 |
} |
| 598 |
|
| 599 |
function processForms() { |
| 600 |
if ($_POST[customcontactforms_submit]) { |
| 601 |
$this->startSession(); |
| 602 |
$this->error_return = $_POST[form_page]; |
| 603 |
$admin_options = $this->getAdminOptions(); |
| 604 |
$fields = parent::getAttachedFieldsArray($_POST[fid]); |
| 605 |
$checks = array(); |
| 606 |
foreach ($fields as $field_id) { |
| 607 |
$field = parent::selectField($field_id, ''); |
| 608 |
if ($field->field_type == 'Checkbox') |
| 609 |
$checks[] = $field->field_slug; |
| 610 |
elseif ($field->field_slug == 'captcha') { |
| 611 |
if ($_POST[captcha] != $_SESSION[captcha]) |
| 612 |
$this->setError('captcha', 'You entered the captcha image code incorrectly'); |
| 613 |
} |
| 614 |
} |
| 615 |
$body = ''; |
| 616 |
foreach ($_POST as $key => $value) { |
| 617 |
$_SESSION[fields][$key] = $value; |
| 618 |
$field = parent::selectField('', $key); |
| 619 |
if (!in_array($key, $this->fixed_fields)) |
| 620 |
$body .= $field->field_label . ': ' . $value . "\n"; |
| 621 |
if (in_array($key, $checks)) { |
| 622 |
$checks_key = array_search($key, $checks); |
| 623 |
unset($checks[$checks_key]); |
| 624 |
} |
| 625 |
} foreach ($checks as $check_key) { |
| 626 |
$field = parent::selectField('', $check_key); |
| 627 |
$body .= ucwords(str_replace('_', ' ', $field->field_label)) . ': 0' . "\n"; |
| 628 |
} |
| 629 |
$errors = $this->getAllErrors(); |
| 630 |
if (empty($errors)) { |
| 631 |
$body .= 'Sender IP: ' . $_SERVER['REMOTE_ADDR'] . "\n"; |
| 632 |
$mailer = new CustomContactFormsMailer($admin_options[default_to_email], $admin_options[default_from_email], $admin_options[default_form_subject], $body); |
| 633 |
$mailer->send(); |
| 634 |
if (!empty($admin_options[custom_thank_you])) { |
| 635 |
header("Location: " . $admin_options[custom_thank_you]); |
| 636 |
} |
| 637 |
} |
| 638 |
unset($_POST); |
| 639 |
} |
| 640 |
} |
| 641 |
} |
| 642 |
} |
| 643 |
$customcontact = new CustomContactForms(); |
| 644 |
if (!function_exists('CustomContactForms_ap')) { |
| 645 |
function CustomContactForms_ap() { |
| 646 |
global $customcontact; |
| 647 |
if (!isset($customcontact)) return; |
| 648 |
if (function_exists('add_options_page')) { |
| 649 |
add_options_page('Custom Contact Forms', 'Custom Contact Forms', 9, 'custom-contact-forms', array(&$customcontact, 'printAdminPage')); |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
if (isset($customcontact)) { |
| 654 |
add_action('init', array(&$customcontact, 'processForms'), 1); |
| 655 |
add_action('init', array(&$customcontact, 'startSession'), 1); |
| 656 |
add_action('wp_head', array(&$customcontact, 'addHeaderCode'), 1); |
| 657 |
add_action('admin_head', array(&$customcontact, 'addHeaderCode'), 1); |
| 658 |
add_action('activate_customcontactforms/customcontactforms.php', array(&$customcontact, 'init')); |
| 659 |
add_action('plugins_loaded', array(&$customcontact, 'init'), 1); |
| 660 |
add_filter('the_content', array(&$customcontact, 'contentFilter')); |
| 661 |
} |
| 662 |
add_action('admin_menu', 'CustomContactForms_ap'); |
| 663 |
?> |
| 664 |
|