3 # This form requires wfpl. See: http://jasonwoof.org/wfpl
5 # This code can send form results by e-mail and/or save them to a database. See
6 # the next two comments to enable either or both.
8 # To send results by e-mail, all you have to do is set your e-mail address here:
9 $GLOBALS['~form_name~_form_recipient'] = "fixme@example.com";
11 # To save results to a database, you'll need to create the ~form_name~ table
12 # (the file ~form_name~.sql should help with this), and create a file called
13 # 'db_connect.php' which calls db_connect() see:
14 # code/wfpl/examples/db_connect.php
16 if(!file_exists('code/wfpl/template.php')) { die('This form requires <a href="http://jasonwoof.org/wfpl">wfpl</a>.'); }
17 require_once('code/wfpl/template.php');
18 require_once('code/wfpl/format.php');
19 require_once('code/wfpl/email.php');
20 require_once('code/wfpl/db.php');
22 function ~form_name~_get_fields() {
24 <!--~formats start~-->
25 $~name~ = format_~format~($_REQUEST['~name~']);<!--~end~-->
26 <!--~tem_sets start~-->
27 tem_set('~name~', $~name~);<!--~end~-->
29 return array(~php_fields~);
32 function ~form_name~() {
33 $edit_id = format_int($_REQUEST['~form_name~_edit_id']);
35 # add hidden field for database id of row we're editing
36 tem_set('~form_name~_edit_id', $edit_id);
40 $delete_id = format_int($_REQUEST['~form_name~_delete_id']);
42 db_delete('~form_name~', 'id = %"', $delete_id);
44 # FIXME: what to do after delete?
48 if(isset($_REQUEST['~always_field~'])) {
49 list(~php_fields~) = ~form_name~_get_fields();
51 if("you're happy with the POSTed values") {
52 # to enable saving to a database, create a file called 'db_connect.php'
53 # see: code/wfpl/examples/db_connect.php
54 if(file_exists('db_connect.php')) {
55 require_once('db_connect.php');
57 db_update('~form_name~', '~db_fields~', ~php_fields~, 'id = %"', $edit_id);
58 tem_set('did', 'updated');
60 db_insert('~form_name~', '~db_fields~', ~php_fields~);
61 tem_set('did', 'saved');
64 if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
65 $to = $GLOBALS['~form_name~_form_recipient'];
66 if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
67 $from = $_REQUEST['email'];
68 if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
69 $from = "$_REQUEST[name] <$from>";
74 $subject = '~form_name~ form submitted';
75 $message = tem_run('~form_name~.email.txt');
78 email($from, $to, $subject, $message, $cc, $bcc);
80 tem_load('~form_name~.html');
85 # otherwise, we display the form again. ~form_name~_get_fields() has
86 # already put the posted values back into the template engine, so they will
87 # show up in the form fields. You should add some message asking people to
88 # fix their entry in whatever way you require.
90 # we've recieved an edit id, but no data. So we grab the values to be edited from the database
91 list(~php_fields~) = db_get_row('~form_name~', '~db_fields~', 'id = %"', $edit_id);
94 # form not submitted, you can set default values like so
95 #tem_set('~always_field~', 'Yes');
101 # emulate run.php if it's not being used
102 if(!function_exists('run_php')) {
103 tem_load('~form_name~.html');