JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
metaform supports password and hidden fields
[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
13 function ~form_name~_get_fields() {
14         $fields = array();
15         <!--~formats start~-->
16         $~name~ = format_~format~($_REQUEST['~name~']);
17         tem_set('~name~', $~name~);
18         <!--~end~-->
19         return array(~php_fields~);
20 }
21
22 function ~form_name~() {
23         if(isset($_REQUEST['~always_field~'])) {
24                 list(~php_fields~) = ~form_name~_get_fields();
25
26                 if("you're happy with the POSTed values") {
27                         # uncomment the following lines to save the values recieved to the
28                         # database. You can use ~form_name~.sql to create the database table.
29                         #require_once('db_connect.php');
30                         #db_insert('~form_name~', '~db_fields~', ~php_fields~);
31                         if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
32                                 $to = $GLOBALS['~form_name~_form_recipient'];
33                                 if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
34                                         $from = $_REQUEST['email'];
35                                         if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
36                                                 $from = "$_REQUEST[name] <$from>";
37                                         }
38                                 } else {
39                                         $from = $to;
40                                 }
41                                 $subject = '~form_name~ form submitted';
42                                 $message = tem_run('~form_name~.email.txt');
43                                 $cc = '';
44                                 $bcc = '';
45                                 email($from, $to, $subject, $message, $cc, $bcc);
46                         }
47                         tem_load('~form_name~.html');
48                         tem_sub('thankyou');
49                         tem_output();
50                         exit();
51                 }
52                 # otherwise, we display the form again. ~form_name~_get_fields() has
53                 # already put the posted values back into the template engine, so they will
54                 # show up in the form fields. You should add some message asking people to
55                 # fix their entry in whatever way you require.
56         }
57
58         tem_sub('form');
59 }
60
61 # emulate run.php if it's not being used
62 if(!function_exists('run_php')) {
63         tem_load('~form_name~.html');
64         ~form_name~();
65         tem_output();
66 }
67
68 ?>