JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
metaform actually sends e-mails now. and presents thankyou message
authorJason Woofenden <jason183@herkamire.com>
Mon, 11 Dec 2006 23:03:40 +0000 (18:03 -0500)
committerJason Woofenden <jason183@herkamire.com>
Mon, 11 Dec 2006 23:03:40 +0000 (18:03 -0500)
metaform.php
metaform/template.html
metaform/template.php

index 74ec74f..9bd36cb 100644 (file)
@@ -159,11 +159,11 @@ function make_template($whole_file = true) {
        $tem->set('name', 'save');
        $tem->set('caption', 'Save');
        $tem->sub('submit');
-       $tem->sub('body');
+       $tem->sub('form');
        if($whole_file) {
                return $tem->run();
        } else {
-               return $tem->get('body');
+               return $tem->get('form');
        }
 }
 
index 426be60..edff985 100644 (file)
@@ -6,7 +6,7 @@
 </head>
 
 <body>
-<!--~body start~-->
+<!--~~form start~~--><!--~form start~-->
   <h2>~form_name~ entry form</h2>
 
   <form action="~form_name~.php" method="post">
@@ -17,6 +17,9 @@
 <!--~end~--><!--~submit start~-->      <tr><td class="submit_row" colspan="2"><input type="submit" name="~name~" value="~caption.attr~" /></td></tr>
 <!--~end~-->    </table>
   </form>
-<!--~end~-->
+<!--~end~--><!--~~end~~-->
+<!--~~thankyou start~~-->
+  <p>Thank you for taking the time to fill out this form.</p>
+<!--~~end~~-->
 </body>
 </html>
index 06a184b..8cbc9e9 100644 (file)
@@ -2,9 +2,13 @@
 
 # This form requires wfpl. See: http://jasonwoof.org/wfpl
 
+# You'll need to set the following to a valid email address:
+$GLOBALS['~form_name~_form_recipient'] = "fixme@example.com";
+
 if(!file_exists('code/wfpl/template.php')) { die('This form requires <a href="http://jasonwoof.org/wfpl">wfpl</a>.'); }
 require_once('code/wfpl/template.php');
 require_once('code/wfpl/format.php');
+require_once('code/wfpl/email.php');
 #require_once('code/wfpl/db.php'); # fixme
 
 function ~form_name~_get_fields() {
@@ -19,15 +23,37 @@ function ~form_name~_get_fields() {
 if(isset($_REQUEST['~always_field~'])) {
        ~form_name~_get_fields();
 
-       if("you're happy with the values") {
+       if("you're happy with the POSTed values") {
                #db_insert('~form_name~', '~db_fields~', $GLOBALS['~form_name~_fields']); # fixme
-               header('Content-type: text/plain');
-               print "e-mailing this: \n\n";
-               tem_output('~form_name~.email.txt');
+               if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
+                       $to = $GLOBALS['~form_name~_form_recipient'];
+                       if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
+                               $from = $_REQUEST['email'];
+                               if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
+                                       $from = "$_REQUEST[name] <$from>";
+                               }
+                       } else {
+                               $from = $to;
+                       }
+                       $subject = '~form_name~ form submitted';
+                       $message = tem_run('~form_name~.email.txt');
+                       $cc = '';
+                       $bcc = '';
+                       email($from, $to, $subject, $message, $cc, $bcc);
+               }
+               tem_load('~form_name~.html');
+               tem_sub('thankyou');
+               tem_output();
                exit();
        }
+       # otherwise, we display the form again. ~form_name~_get_fields() has
+       # already put the posted values back into the template engine, so they will
+       # show up in the form fields. You should add some message asking people to
+       # fix their entry in whatever way you require.
 }
 
-tem_output('~form_name~.html');
+tem_load('~form_name~.html');
+tem_sub('form');
+tem_output();
 
 ?>