3 # This form requires wfpl. If you didn't recieve wfpl along with this file,
4 # see: http://jasonwoof.org/wfpl
6 # This form was auto-generated. If you would like to alter the parameters and
7 # generate a new one try this URL:
11 # This code can send form results by e-mail and/or save them to a database. See
12 # the next two comments to enable either or both.
14 # To send results by e-mail, all you have to do is set your e-mail address here:
15 $GLOBALS['~form_name~_form_recipient'] = "fixme@example.com";
16 <!--~upload_settings start~-->
17 # Set this to the path to your uploads directory. It can be relative to the
18 # location of this script. IT MUST END WITH A SLASH
19 $GLOBALS['upload_directory'] = 'uploads/';
21 # To save results to a database, you'll need to create the ~form_name~ table
22 # (the file ~form_name~.sql should help with this), and create a file called
23 # 'db_connect.php' which calls db_connect() see:
24 # code/wfpl/examples/db_connect.php
26 if(!file_exists('code/wfpl/template.php')) { die('This form requires <a href="http://jasonwoof.org/wfpl">wfpl</a>.'); }
27 require_once('code/wfpl/template.php');
28 require_once('code/wfpl/format.php');
29 require_once('code/wfpl/email.php');
30 require_once('code/wfpl/db.php');<!--~image_include start~-->
31 require_once('code/wfpl/upload.php');<!--~end~-->
33 function ~form_name~_get_fields() {
35 <!--~formats start~-->
36 $~name~ = format_~format~($_REQUEST['~name~']);<!--~end~--><!--~image_upload start~-->
37 $~name~ = save_uploaded_image('~name~', $GLOBALS['upload_directory']);<!--~end~-->
38 <!--~tem_sets start~-->
39 tem_set('~name~', $~name~);<!--~end~-->
41 return array(~php_fields~);
44 function ~form_name~() {
45 $edit_id = format_int($_REQUEST['~form_name~_edit_id']);
47 # add hidden field for database id of row we're editing
48 tem_set('~form_name~_edit_id', $edit_id);
52 $delete_id = format_int($_REQUEST['~form_name~_delete_id']);
54 db_delete('~form_name~', 'id = %"', $delete_id);
56 # FIXME: what to do after delete?
60 if(isset($_REQUEST['~always_field~'])) {
61 list(~php_fields~) = ~form_name~_get_fields();
63 if("you're happy with the POSTed values") {
64 # to enable saving to a database, create a file called 'db_connect.php'
65 # see: code/wfpl/examples/db_connect.php
66 if(file_exists('db_connect.php')) {
67 require_once('db_connect.php');
68 if($edit_id) {<!--~image_db start~-->
69 # uploading nothing means leaving it as is.
70 if(!$~name~ && $delete_~name~ != 'Yes') {
71 $~name~ = db_get_value('~form_name~', '~name~', 'id = %"', $edit_id);
74 db_update('~form_name~', '~db_fields~', ~php_fields~, 'id = %"', $edit_id);
75 tem_set('did', 'updated');
77 db_insert('~form_name~', '~db_fields~', ~php_fields~);
78 tem_set('did', 'saved');
81 if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
82 $to = $GLOBALS['~form_name~_form_recipient'];
83 if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
84 $from = $_REQUEST['email'];
85 if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
86 $from = "$_REQUEST[name] <$from>";
91 $subject = '~form_name~ form submitted';
92 $message = tem_run('~form_name~.email.txt');
95 if(email($from, $to, $subject, $message, $cc, $bcc)) {
96 tem_set('error_message', 'Due to an internal error, your message could not be sent. Please try again later.');
101 if($error !== true) {
102 tem_load('~form_name~.html');
108 # otherwise, we display the form again. ~form_name~_get_fields() has
109 # already put the posted values back into the template engine, so they will
110 # show up in the form fields. You should add some message asking people to
111 # fix their entry in whatever way you require.
113 # we've recieved an edit id, but no data. So we grab the values to be edited from the database
114 list(~php_fields~) = db_get_row('~form_name~', '~db_fields~', 'id = %"', $edit_id);
117 # form not submitted, you can set default values like so:
118 #tem_set('~always_field~', 'Yes');
119 }<!--~upload_max start~-->
121 tem_set('upload_max_filesize', upload_max_filesize());<!--~end~-->
126 # emulate run.php if it's not being used
127 if(!function_exists('run_php')) {
128 tem_load('~form_name~.html');