[288] | 1 | <?php |
---|
[362] | 2 | /** |
---|
| 3 | * The Strangecode Codebase - a general application development framework for PHP |
---|
| 4 | * For details visit the project site: <http://trac.strangecode.com/codebase/> |
---|
[396] | 5 | * Copyright 2001-2012 Strangecode, LLC |
---|
[550] | 6 | * |
---|
[362] | 7 | * This file is part of The Strangecode Codebase. |
---|
| 8 | * |
---|
| 9 | * The Strangecode Codebase is free software: you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License as published by the |
---|
| 11 | * Free Software Foundation, either version 3 of the License, or (at your option) |
---|
| 12 | * any later version. |
---|
[550] | 13 | * |
---|
[362] | 14 | * The Strangecode Codebase is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
| 17 | * details. |
---|
[550] | 18 | * |
---|
[362] | 19 | * You should have received a copy of the GNU General Public License along with |
---|
| 20 | * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. |
---|
| 21 | */ |
---|
| 22 | |
---|
[288] | 23 | /* |
---|
| 24 | * contact.php |
---|
[362] | 25 | * |
---|
[288] | 26 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
| 27 | * @version 1.0 |
---|
| 28 | * @since 01 Aug 2006 09:35:14 |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | require_once dirname(__FILE__) . '/_config.inc.php'; |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | /******************************************************************** |
---|
| 35 | * CONFIG |
---|
| 36 | ********************************************************************/ |
---|
| 37 | |
---|
| 38 | require_once 'codebase/lib/FormValidator.inc.php'; |
---|
| 39 | require_once 'codebase/lib/Email.inc.php'; |
---|
| 40 | |
---|
| 41 | $fv = new FormValidator(); |
---|
| 42 | |
---|
| 43 | // Set this to the person who should receive emails. |
---|
| 44 | $email_to = 'The Form Admin <me@example.com>'; |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | /******************************************************************** |
---|
| 48 | * MAIN |
---|
| 49 | ********************************************************************/ |
---|
| 50 | |
---|
| 51 | if (!empty($_POST)) { |
---|
| 52 | // Validate submitted data. |
---|
[413] | 53 | validateInput(); |
---|
[479] | 54 | if ($fv->anyErrors()) { |
---|
[288] | 55 | // Re-populate form values with the user data so they can make corrections. |
---|
[479] | 56 | $frm = resetForm(getFormData()); |
---|
| 57 | } else { |
---|
[288] | 58 | // Setup email object. |
---|
| 59 | $email = new Email(array( |
---|
| 60 | 'to' => $email_to, |
---|
[550] | 61 | 'from' => sprintf('"%s" <%s>', addcslashes(getFormData('name'), '"'), getFormData('email')), |
---|
[288] | 62 | 'subject' => 'Contact form email', |
---|
| 63 | )); |
---|
| 64 | $email->setTemplate('contact.eml'); |
---|
| 65 | $email->replace(array( |
---|
[413] | 66 | 'name' => getFormData('name'), |
---|
| 67 | 'email' => getFormData('email'), |
---|
| 68 | 'message' => getFormData('message'), |
---|
[288] | 69 | )); |
---|
| 70 | // Send email! |
---|
| 71 | $email->send(); |
---|
| 72 | |
---|
| 73 | // Reset form values to display a blank form. |
---|
| 74 | $frm = resetForm(); |
---|
| 75 | $app->raiseMsg(_("<strong>Thank You!</strong> Your message has been sent."), MSG_SUCCESS, __FILE__, __LINE__); |
---|
[479] | 76 | } |
---|
[288] | 77 | } else { |
---|
| 78 | // Reset form values to display a blank form. |
---|
| 79 | $frm = resetForm(); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | /******************************************************************** |
---|
| 84 | * OUTPUT |
---|
| 85 | ********************************************************************/ |
---|
| 86 | |
---|
| 87 | include 'header.ihtml'; |
---|
| 88 | include 'contact.ihtml'; |
---|
| 89 | include 'footer.ihtml'; |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | /******************************************************************** |
---|
| 93 | * FUNCTIONS |
---|
| 94 | ********************************************************************/ |
---|
| 95 | |
---|
| 96 | function resetForm($new_values = array()) |
---|
| 97 | { |
---|
[479] | 98 | $default = array( |
---|
| 99 | 'name' => '', |
---|
| 100 | 'email' => '', |
---|
| 101 | 'message' => '', |
---|
| 102 | ); |
---|
| 103 | return array_merge($default, $new_values); |
---|
[288] | 104 | } |
---|
| 105 | |
---|
[413] | 106 | function validateInput() |
---|
| 107 | { |
---|
| 108 | global $fv; |
---|
| 109 | |
---|
| 110 | $fv->notEmpty('name', sprintf(_("%s cannot be blank."), _("Name"))); |
---|
| 111 | $fv->stringLength('name', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Name"), 0, 255)); |
---|
[550] | 112 | |
---|
[413] | 113 | $fv->notEmpty('email', sprintf(_("%s cannot be blank."), _("Email"))); |
---|
| 114 | $fv->stringLength('email', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Email"), 0, 255)); |
---|
| 115 | $fv->validateEmail('email'); |
---|
[550] | 116 | |
---|
[413] | 117 | $fv->notEmpty('message', sprintf(_("%s cannot be blank."), _("Message"))); |
---|
| 118 | $fv->stringLength('message', 0, 32000, sprintf(_("%s must be %d-to-%d characters in length."), _("Message"), 0, 32000)); |
---|
| 119 | } |
---|
| 120 | |
---|