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_form_recipient'] = 'fixme@example.com';
9 $GLOBALS['contact_robot_answer'] = 1002;
12 require_once(DOCROOT . 'inc/wfpl/format.php');
13 require_once(DOCROOT . 'inc/wfpl/email.php');
15 function contact_get_fields() {
18 $data['name'] = format_oneline(_REQUEST_cut('name'));
19 $data['email'] = format_email(_REQUEST_cut('email'));
20 $data['robot'] = format_oneline(_REQUEST_cut('robot'));
21 $data['comments'] = format_unix(_REQUEST_cut('comments'));
27 function contact_main() {
28 return contact_main_form();
31 function contact_main_form($id = false) {
32 $robot_correct = "" . $GLOBALS['contact_robot_answer'];
33 $robot_minus_one = "" . ($GLOBALS['contact_robot_answer'] - 1);
34 $robot_plus_one = "" . ($GLOBALS['contact_robot_answer'] + 1);
35 tem_set('robot_minus_one', $robot_minus_one);
36 tem_set('robot_plus_one', $robot_plus_one);
38 if(isset($_POST['name'])) {
39 $data = contact_get_fields();
42 if(!$data['name'] && !$data['email'] && !$data['comments']) {
43 // message("you didn't fill anything out")
44 } elseif($data['robot'] !== $robot_correct) {
45 message("Please type $robot_correct into the Robot Barrier field");
47 if($GLOBALS['contact_form_recipient'] != 'fixme@example.com') {
48 $to = $GLOBALS['contact_form_recipient'];
49 $from = "$host/contact <noreply@cmstest.com>";
51 if(isset($data['email']) and valid_email($data['email'])) {
52 $reply_to = $data['email'];
53 if($data['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $data['name']) !== false) {
54 $reply_to = "$data[name] <$reply_to>";
57 $subject = "Your message via $host/contact";
58 $email_template = new tem();
59 $email_template->load('contact.email.txt');
60 $email_template->sets($data);
61 $email_template->set('$host', $host);
62 $message = $email_template->run();
65 if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
66 message('Due to an internal error, your message could not be sent. Please try again later.');
69 message('Message sent');
73 # FIXME create this page or change this to go elsewhere
74 return './contact_thanks';
77 # otherwise, we display the form again. We've got the form field
78 # values in $data and will put those back in the filds below. You
79 # should add some message asking people to fix their entry in
80 # whatever way you require.
82 # form not submitted, you can set default values like so:
83 #$data = array('name' => 'Yes');
87 tem_set('form', $data);