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";
10 <!--~upload_settings start~-->
11 # Set this to the path to your uploads directory. It can be relative to the
12 # location of this script. IT MUST END WITH A SLASH
13 $GLOBALS['upload_directory'] = 'uploads/';
15 # To save results to a database, you'll need to create the ~form_name~ table
16 # (the file ~form_name~.sql should help with this), and create a file called
17 # 'db_connect.php' which calls db_connect() see:
18 # code/wfpl/examples/db_connect.php
20 if(!file_exists('code/wfpl/template.php')) { die('This form requires <a href="http://jasonwoof.org/wfpl">wfpl</a>.'); }
21 require_once('code/wfpl/template.php');
22 require_once('code/wfpl/format.php');
23 require_once('code/wfpl/email.php');
24 require_once('code/wfpl/db.php');<!--~image_include start~-->
25 require_once('code/wfpl/upload.php');<!--~end~-->
27 function ~form_name~_get_fields() {
29 <!--~formats start~-->
30 $~name~ = format_~format~($_REQUEST['~name~']);<!--~end~--><!--~image_upload start~-->
31 $~name~ = save_uploaded_image('~name~', $GLOBALS['upload_directory']);<!--~end~-->
32 <!--~tem_sets start~-->
33 tem_set('~name~', $~name~);<!--~end~-->
35 return array(~php_fields~);
38 function ~form_name~() {
39 $edit_id = format_int($_REQUEST['~form_name~_edit_id']);
41 # add hidden field for database id of row we're editing
42 tem_set('~form_name~_edit_id', $edit_id);
46 $delete_id = format_int($_REQUEST['~form_name~_delete_id']);
48 db_delete('~form_name~', 'id = %"', $delete_id);
50 # FIXME: what to do after delete?
54 if(isset($_REQUEST['~always_field~'])) {
55 list(~php_fields~) = ~form_name~_get_fields();
57 if("you're happy with the POSTed values") {
58 # to enable saving to a database, create a file called 'db_connect.php'
59 # see: code/wfpl/examples/db_connect.php
60 if(file_exists('db_connect.php')) {
61 require_once('db_connect.php');
62 if($edit_id) {<!--~image_db start~-->
63 # uploading nothing means leaving it as is.
64 if(!$~name~ && $delete_~name~ != 'Yes') {
65 $~name~ = db_get_value('~form_name~', '~name~', 'id = %"', $edit_id);
68 db_update('~form_name~', '~db_fields~', ~php_fields~, 'id = %"', $edit_id);
69 tem_set('did', 'updated');
71 db_insert('~form_name~', '~db_fields~', ~php_fields~);
72 tem_set('did', 'saved');
75 if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
76 $to = $GLOBALS['~form_name~_form_recipient'];
77 if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
78 $from = $_REQUEST['email'];
79 if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
80 $from = "$_REQUEST[name] <$from>";
85 $subject = '~form_name~ form submitted';
86 $message = tem_run('~form_name~.email.txt');
89 email($from, $to, $subject, $message, $cc, $bcc);
91 tem_load('~form_name~.html');
96 # otherwise, we display the form again. ~form_name~_get_fields() has
97 # already put the posted values back into the template engine, so they will
98 # show up in the form fields. You should add some message asking people to
99 # fix their entry in whatever way you require.
101 # we've recieved an edit id, but no data. So we grab the values to be edited from the database
102 list(~php_fields~) = db_get_row('~form_name~', '~db_fields~', 'id = %"', $edit_id);
105 # form not submitted, you can set default values like so
106 #tem_set('~always_field~', 'Yes');
107 }<!--~upload_max start~-->
109 tem_set('upload_max_filesize', upload_max_filesize());<!--~end~-->
114 # emulate run.php if it's not being used
115 if(!function_exists('run_php')) {
116 tem_load('~form_name~.html');