[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 |
---|
[362] | 6 | * |
---|
| 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. |
---|
| 13 | * |
---|
| 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. |
---|
| 18 | * |
---|
| 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. |
---|
| 53 | $fv->notEmpty('name', sprintf(_("%s cannot be blank."), _("Name"))); |
---|
| 54 | $fv->stringLength('name', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Name"), 0, 255)); |
---|
| 55 | |
---|
| 56 | $fv->notEmpty('email', sprintf(_("%s cannot be blank."), _("Email"))); |
---|
| 57 | $fv->stringLength('email', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Email"), 0, 255)); |
---|
| 58 | $fv->validateEmail('email'); |
---|
| 59 | |
---|
| 60 | $fv->notEmpty('message', sprintf(_("%s cannot be blank."), _("Message"))); |
---|
| 61 | $fv->stringLength('message', 0, 32000, sprintf(_("%s must be %d-to-%d characters in length."), _("Message"), 0, 32000)); |
---|
| 62 | |
---|
| 63 | if ($fv->anyErrors()) { |
---|
| 64 | // Re-populate form values with the user data so they can make corrections. |
---|
| 65 | $frm = resetForm(getFormData()); |
---|
| 66 | } else { |
---|
| 67 | // Setup email object. |
---|
| 68 | $email = new Email(array( |
---|
| 69 | 'to' => $email_to, |
---|
| 70 | 'from' => sprintf('%s <%s>', $frm['name'], $frm['email']), |
---|
| 71 | 'subject' => 'Contact form email', |
---|
| 72 | )); |
---|
| 73 | $email->setTemplate('contact.eml'); |
---|
| 74 | $email->replace(array( |
---|
| 75 | 'name' => $frm['name'], |
---|
| 76 | 'email' => $frm['email'], |
---|
| 77 | 'message' => $frm['question'], |
---|
| 78 | )); |
---|
| 79 | // Send email! |
---|
| 80 | $email->send(); |
---|
| 81 | |
---|
| 82 | // Reset form values to display a blank form. |
---|
| 83 | $frm = resetForm(); |
---|
| 84 | $app->raiseMsg(_("<strong>Thank You!</strong> Your message has been sent."), MSG_SUCCESS, __FILE__, __LINE__); |
---|
| 85 | } |
---|
| 86 | } else { |
---|
| 87 | // Reset form values to display a blank form. |
---|
| 88 | $frm = resetForm(); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | /******************************************************************** |
---|
| 93 | * OUTPUT |
---|
| 94 | ********************************************************************/ |
---|
| 95 | |
---|
| 96 | include 'header.ihtml'; |
---|
| 97 | include 'contact.ihtml'; |
---|
| 98 | include 'footer.ihtml'; |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | /******************************************************************** |
---|
| 102 | * FUNCTIONS |
---|
| 103 | ********************************************************************/ |
---|
| 104 | |
---|
| 105 | function resetForm($new_values = array()) |
---|
| 106 | { |
---|
| 107 | $default = array( |
---|
| 108 | 'name' => '', |
---|
| 109 | 'email' => '', |
---|
| 110 | 'message' => '', |
---|
| 111 | ); |
---|
| 112 | return array_merge($default, $new_values); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | ?> |
---|