JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
add contact form
authorJason Woofenden <jason@jasonwoof.com>
Thu, 19 Jun 2014 19:15:48 +0000 (15:15 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 19 Jun 2014 19:15:48 +0000 (15:15 -0400)
contact.email.txt [new file with mode: 0644]
contact.html [new file with mode: 0644]
contact.php [new file with mode: 0644]

diff --git a/contact.email.txt b/contact.email.txt
new file mode 100644 (file)
index 0000000..0eaa22c
--- /dev/null
@@ -0,0 +1,3 @@
+New message from ~name nonempty {~~name~~email nonempty {~ <~email~>~}~~}~~name empty {~~email nonempty {~~email~~}~~email empty {~someone~}~~}~ via your contact form at ~$host~:
+
+~comments~
diff --git a/contact.html b/contact.html
new file mode 100644 (file)
index 0000000..11e1fb5
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+
+<html lang="en">
+<head>
+       <meta charset="utf-8" />
+       <title><!--~$title show {~-->Messages<!--~}~--></title>
+       <link rel="stylesheet" href="style.css">
+</head>
+
+<body>
+<!--~$body show {~-->
+
+       <!--~form {~-->
+               <h2>Submit a message</h2>
+
+               <form action="contact" method="post">
+
+                       <div class="caption">Name</div>
+                       <div class="field"><input type="text" name="name" value="~name attr~"></div>
+
+                       <div class="caption">Email</div>
+                       <div class="field"><input type="email" name="email" value="~email attr~"></div>
+
+                       <div class="caption">Robot Barrier (Required)</div>
+                       <div class="field_notes">Enter (below) the number between ~robot_minus_one~ and ~robot_plus_one~</div>
+                       <div class="field"><input type="text" name="robot" value="~robot attr~"></div>
+
+                       <div class="caption">Comments</div>
+                       <div class="field"><textarea rows="9" cols="22" name="comments">~comments html~</textarea></div>
+
+                       <div class="caption"></div>
+                       <div class="field"><input type="submit" name="save" value="Save"></div>
+
+               </form>
+       <!--~}~-->
+
+<!--~}~-->
+</body>
+</html>
diff --git a/contact.php b/contact.php
new file mode 100644 (file)
index 0000000..769b2c5
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+
+# This form requires wfpl. See: http://jasonwoof.org/wfpl
+
+# SETUP
+
+# To send results by e-mail, all you have to do is set your e-mail address here:
+$GLOBALS['contact_form_recipient'] = 'fixme@example.com';
+$GLOBALS['contact_robot_answer'] = 1002;
+
+
+require_once('code/wfpl/format.php');
+require_once('code/wfpl/email.php');
+
+function contact_get_fields() {
+       $data = array();
+
+       $data['name'] = format_oneline(_REQUEST_cut('name'));
+       $data['email'] = format_email(_REQUEST_cut('email'));
+       $data['robot'] = format_oneline(_REQUEST_cut('robot'));
+       $data['comments'] = format_unix(_REQUEST_cut('comments'));
+
+       return $data;
+}
+
+
+function contact_main() {
+       return contact_main_form();
+}
+
+function contact_main_form($id = false) {
+       if(isset($_POST['name'])) {
+               $data = contact_get_fields();
+
+               $robot_correct = "" . $GLOBALS['contact_robot_answer'];
+               $robot_minus_one = "" . ($GLOBALS['contact_robot_answer'] - 1);
+               $robot_plus_one = "" . ($GLOBALS['contact_robot_answer'] + 1);
+               tem_set('robot_minus_one', $robot_minus_one);
+               tem_set('robot_plus_one', $robot_plus_one);
+               $host = this_host();
+
+               if(!$data['name'] && !$data['email'] && !$data['comments']) {
+                       // message("you didn't fill anything out")
+               } elseif($data['robot'] !== $robot_correct) {
+                       message("Please type $robot_correct into the Robot Barrier field");
+               } else {
+                       if($GLOBALS['contact_form_recipient'] != 'fixme@example.com') {
+                               $to = $GLOBALS['contact_form_recipient'];
+                               $from = "$host/contact <noreply@cmstest.com>";
+                               $reply_to = $to;
+                               if(isset($data['email']) and valid_email($data['email'])) {
+                                       $reply_to = $data['email'];
+                                       if($data['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $data['name']) !== false) {
+                                               $reply_to = "$data[name] <$reply_to>";
+                                       }
+                               }
+                               $subject = "Your message via $host/contact";
+                               $email_template = new tem();
+                               $email_template->load('contact.email.txt');
+                               $email_template->sets($data);
+                               $email_template->set('$host', this_host());
+                               $message = $email_template->run();
+                               $cc = '';
+                               $bcc = '';
+                               if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
+                                       message('Due to an internal error, your message could not be sent. Please try again later.');
+                                       $error = true;
+                               } else {
+                                       message('Message sent');
+                               }
+                       }
+                       if($error !== true) {
+                               # FIXME create this page or change this to go elsewhere
+                               return './contact_thanks';
+                       }
+               }
+               # otherwise, we display the form again. We've got the form field
+               # values in $data and will put those back in the filds below. You
+               # should add some message asking people to fix their entry in
+               # whatever way you require.
+       } else {
+               # form not submitted, you can set default values like so:
+               #$data = array('name' => 'Yes');
+               $data = array();
+       }
+
+       tem_set('form', $data);
+}