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

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

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