source: trunk/docs/examples/contact_form/contact.php @ 376

Last change on this file since 376 was 376, checked in by quinn, 14 years ago

Updated copyright date, name to Strangecode LLC.

File size: 3.7 KB
Line 
1<?php
2/**
3 * The Strangecode Codebase - a general application development framework for PHP
4 * For details visit the project site: <http://trac.strangecode.com/codebase/>
5 * Copyright 2001-2010 Strangecode, LLC
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
23/*
24* contact.php
25*
26* @author   Quinn Comendant <quinn@strangecode.com>
27* @version  1.0
28* @since    01 Aug 2006 09:35:14
29*/
30
31require_once dirname(__FILE__) . '/_config.inc.php';
32
33
34/********************************************************************
35* CONFIG
36********************************************************************/
37
38require_once 'codebase/lib/FormValidator.inc.php';
39require_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
51if (!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
96include 'header.ihtml';
97include 'contact.ihtml';
98include 'footer.ihtml';
99
100
101/********************************************************************
102* FUNCTIONS
103********************************************************************/
104
105function 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?>
Note: See TracBrowser for help on using the repository browser.