3 # This form requires wfpl. See: http://sametwice.com/wfpl
7 # To send results by e-mail, all you have to do is set your e-mail address here:
8 $GLOBALS['contact_to'] = 'fixme@example.com';
9 $GLOBALS['contact_from'] = 'noreply@example.com';
10 $GLOBALS['contact_cc'] = '';
11 $globals['contact_subject'] = '';
12 $GLOBALS['contact_robot_answer'] = 1002;
15 require_once(DOCROOT . 'inc/wfpl/format.php');
16 require_once(DOCROOT . 'inc/wfpl/email.php');
18 function contact_get_fields() {
21 $data['name'] = format_oneline(_REQUEST_cut('name'));
22 $data['email'] = format_email(_REQUEST_cut('email'));
23 $data['robot'] = format_oneline(_REQUEST_cut('robot'));
24 $data['comments'] = format_unix(_REQUEST_cut('comments'));
30 function contact_main() {
31 return contact_main_form();
34 function contact_main_form() {
35 $robot_correct = "" . $GLOBALS['contact_robot_answer'];
36 $robot_minus_one = "" . ($GLOBALS['contact_robot_answer'] - 1);
37 $robot_plus_one = "" . ($GLOBALS['contact_robot_answer'] + 1);
38 tem_set('robot_minus_one', $robot_minus_one);
39 tem_set('robot_plus_one', $robot_plus_one);
41 if (isset($_POST['name'])) {
42 $data = contact_get_fields();
45 if (!$data['name'] && !$data['email'] && !$data['comments']) {
46 // message("you didn't fill anything out")
47 } elseif ($data['robot'] !== $robot_correct) {
48 message("Please type $robot_correct into the Robot Barrier field");
50 if ($GLOBALS['contact_to'] != 'fixme@example.com') {
51 $to = $GLOBALS['contact_to'];
52 if ($GLOBALS['contact_from'] === '') {
53 $from = "$host/contact <noreply@$host>";
55 $from = $GLOBALS['contact_from'];
58 if (isset($data['email']) and valid_email($data['email'])) {
59 $reply_to = $data['email'];
60 if ($data['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $data['name']) !== false) {
61 $reply_to = "$data[name] <$reply_to>";
64 if ($GLOBALS['contact_subject'] === '') {
65 $subject = "Your message via $host/contact";
67 $subject = $GLOBALS['contact_subject'];
69 $email_template = new tem();
70 $email_template->load('contact.email.txt');
71 $email_template->sets($data);
72 $email_template->set('$host', $host);
73 $message = $email_template->run();
74 $cc = $GLOBALS['contact_cc'];
76 if (email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
77 message('Due to an internal error, your message could not be sent. Please try again later.');
80 message('Message sent');
83 if ($error !== true) {
84 # FIXME create this page or change this to go elsewhere
85 return './contact_thanks';
88 # otherwise, we display the form again. We've got the form field
89 # values in $data and will put those back in the filds below. You
90 # should add some message asking people to fix their entry in
91 # whatever way you require.
93 # form not submitted, you can set default values like so:
94 #$data = array('name' => 'Yes');
98 tem_set('form', $data);