JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
8cbc9e94e49c0003e11be30772a2ee06b83ab5c3
[wfpl.git] / metaform / template.php
1 <?php
2
3 # This form requires wfpl. See: http://jasonwoof.org/wfpl
4
5 # You'll need to set the following to a valid email address:
6 $GLOBALS['~form_name~_form_recipient'] = "fixme@example.com";
7
8 if(!file_exists('code/wfpl/template.php')) { die('This form requires <a href="http://jasonwoof.org/wfpl">wfpl</a>.'); }
9 require_once('code/wfpl/template.php');
10 require_once('code/wfpl/format.php');
11 require_once('code/wfpl/email.php');
12 #require_once('code/wfpl/db.php'); # fixme
13
14 function ~form_name~_get_fields() {
15         $GLOBALS['~form_name~_fields'] = array();<!--~formats start~-->
16
17         $value = format_~format~($_REQUEST['~name~']);
18         tem_set('~name~', $value);<!--~db_field start~-->
19         $GLOBALS['~form_name~_fields'][] = $value;<!--~end~--><!--~end~-->
20 }
21         
22
23 if(isset($_REQUEST['~always_field~'])) {
24         ~form_name~_get_fields();
25
26         if("you're happy with the POSTed values") {
27                 #db_insert('~form_name~', '~db_fields~', $GLOBALS['~form_name~_fields']); # fixme
28                 if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
29                         $to = $GLOBALS['~form_name~_form_recipient'];
30                         if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
31                                 $from = $_REQUEST['email'];
32                                 if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
33                                         $from = "$_REQUEST[name] <$from>";
34                                 }
35                         } else {
36                                 $from = $to;
37                         }
38                         $subject = '~form_name~ form submitted';
39                         $message = tem_run('~form_name~.email.txt');
40                         $cc = '';
41                         $bcc = '';
42                         email($from, $to, $subject, $message, $cc, $bcc);
43                 }
44                 tem_load('~form_name~.html');
45                 tem_sub('thankyou');
46                 tem_output();
47                 exit();
48         }
49         # otherwise, we display the form again. ~form_name~_get_fields() has
50         # already put the posted values back into the template engine, so they will
51         # show up in the form fields. You should add some message asking people to
52         # fix their entry in whatever way you require.
53 }
54
55 tem_load('~form_name~.html');
56 tem_sub('form');
57 tem_output();
58
59 ?>