* Copyright 2001-2010 Strangecode, LLC * * This file is part of The Strangecode Codebase. * * The Strangecode Codebase is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your option) * any later version. * * The Strangecode Codebase is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * The Strangecode Codebase. If not, see . */ /* * contact.php * * @author Quinn Comendant * @version 1.0 * @since 01 Aug 2006 09:35:14 */ require_once dirname(__FILE__) . '/_config.inc.php'; /******************************************************************** * CONFIG ********************************************************************/ require_once 'codebase/lib/FormValidator.inc.php'; require_once 'codebase/lib/Email.inc.php'; $fv = new FormValidator(); // Set this to the person who should receive emails. $email_to = 'The Form Admin '; /******************************************************************** * MAIN ********************************************************************/ if (!empty($_POST)) { // Validate submitted data. $fv->notEmpty('name', sprintf(_("%s cannot be blank."), _("Name"))); $fv->stringLength('name', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Name"), 0, 255)); $fv->notEmpty('email', sprintf(_("%s cannot be blank."), _("Email"))); $fv->stringLength('email', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Email"), 0, 255)); $fv->validateEmail('email'); $fv->notEmpty('message', sprintf(_("%s cannot be blank."), _("Message"))); $fv->stringLength('message', 0, 32000, sprintf(_("%s must be %d-to-%d characters in length."), _("Message"), 0, 32000)); if ($fv->anyErrors()) { // Re-populate form values with the user data so they can make corrections. $frm = resetForm(getFormData()); } else { // Setup email object. $email = new Email(array( 'to' => $email_to, 'from' => sprintf('%s <%s>', $frm['name'], $frm['email']), 'subject' => 'Contact form email', )); $email->setTemplate('contact.eml'); $email->replace(array( 'name' => $frm['name'], 'email' => $frm['email'], 'message' => $frm['question'], )); // Send email! $email->send(); // Reset form values to display a blank form. $frm = resetForm(); $app->raiseMsg(_("Thank You! Your message has been sent."), MSG_SUCCESS, __FILE__, __LINE__); } } else { // Reset form values to display a blank form. $frm = resetForm(); } /******************************************************************** * OUTPUT ********************************************************************/ include 'header.ihtml'; include 'contact.ihtml'; include 'footer.ihtml'; /******************************************************************** * FUNCTIONS ********************************************************************/ function resetForm($new_values = array()) { $default = array( 'name' => '', 'email' => '', 'message' => '', ); return array_merge($default, $new_values); } ?>