3 # This form requires wfpl. See: http://jasonwoof.org/wfpl
5 # This form was initially auto-generated. If you would like to alter the
6 # parameters and generate a new one try this URL:
12 <!--~opt_email_1 start~-->
13 # To send results by e-mail, all you have to do is set your e-mail address here:
14 $GLOBALS['~form_name~_form_recipient'] = "fixme@example.com";
15 <!--~end~--><!--~opt_db_1 start~-->
16 # To save results to a database, you'll need to create the ~form_name~ table
17 # (the file ~form_name~.sql should help with this), and create the file
18 # 'code/db_connect.php' which calls db_connect() see:
19 # code/wfpl/examples/db_connect.php
21 # if you rename any of the database fields, you'll need to update this:
23 define('~form_name.upper~_DB_FIELDS', '~db_fields~');
24 <!--~end~--><!--~upload_settings start~-->
25 # Set this to the path to your uploads directory. It can be relative to the
26 # location of this script. IT MUST END WITH A SLASH
27 $GLOBALS['upload_directory'] = 'uploads/';
28 <!--~end~--><!--~opt_http_pass_1 start~-->
29 # Define the username and password required to view this form:
30 define('AUTH_REALM', '~form_name~ administration area');
31 define('AUTH_USER', 'fixme');
32 define('AUTH_PASS', 'fixme');
35 require_once('code/wfpl/template.php');
36 require_once('code/wfpl/format.php');
37 require_once('code/wfpl/messages.php');
38 require_once('code/wfpl/email.php');<!--~opt_db_2 start~-->
39 require_once('code/db_connect.php');<!--~end~--><!--~image_include start~-->
40 require_once('code/wfpl/upload.php');<!--~end~-->
42 function ~form_name~_get_fields() {<!--~formats start~-->
43 $~name~ = format_~format~($_REQUEST['~name~']<!--~pulldown_format_extra start~-->, '~name~'<!--~end~-->);<!--~end~--><!--~image_upload start~-->
44 if($_FILES['~name~'] && $_FILES['~name~']['error'] == 0) {
45 $~name~ = substr(save_uploaded_image('~name~', $GLOBALS['upload_directory']), strlen($GLOBALS['upload_directory']));
47 if($_REQUEST['delete_~name~'] == 'Yes') {
50 $~name~ = format_filename($_REQUEST['old_~name~']);
54 ~form_name~_tem_sets(~php_fields~);
56 return array(~php_fields~);
59 function ~form_name~_tem_sets(~php_fields~) {<!--~tem_sets start~-->
60 tem_set('~name~', $~name~);<!--~end~-->
62 <!--~opt_listing_2 start~-->
63 # You may pass a "where clause" for the db query.
64 function ~form_name~_display_listing($where = 'order by ~always_field~ limit 100') {
65 $rows = db_get_rows('~form_name~', 'id,~always_field~', $where);
66 if($rows == false || count($rows) == 0) {
67 tem_show('empty_listing');
72 foreach($rows as $row) {
73 list($id, $~always_field~) = $row;
75 if($~always_field~ == '') {
76 $~always_field~ = '--';
78 tem_set('~always_field~', $~always_field~);
79 tem_show('listing_row');
81 tem_show('populated_listing');
86 function ~form_name~_main() {<!--~opt_display_1 start~-->
87 if(isset($_REQUEST['~form_name~_id'])) {
88 $ret = ~form_name~_display_main();
92 tem_show('display_body');
94 $ret = ~form_name~_edit_main();
98 tem_show('edit_body');
100 <!--~end~--><!--~opt_display_1_else start~-->
101 $ret = _~form_name~_main();
106 # sections displayed with tem_show() will be coppied to the main template if you have one.
107 tem_show('main_body');
108 }<!--~opt_display_2 start~-->
110 function ~form_name~_display_main() {
111 $id = format_int($_REQUEST['~form_name~_id']);
112 unset($_REQUEST['~form_name~_id']);
114 message('Error: Broken link');
115 return './~form_name~';
117 $row = db_get_row('~form_name~', ~form_name.upper~_DB_FIELDS, 'where id=%i', $id);
119 message('Error: ~singular.cap~ not found');
120 return './~form_name~';
122 list(~php_fields~) = $row;
123 ~form_name~_tem_sets(~php_fields~);
127 function ~form_name~_edit_main() {<!--~end~--><!--~opt_display_2_else start~-->
130 function _~form_name~_main() {<!--~end~--><!--~opt_http_pass_2 start~-->
131 # To remove password protection, just delete this block:
132 if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != AUTH_USER || $_SERVER['PHP_AUTH_PW'] != AUTH_PASS) {
133 header('WWW-Authenticate: Basic realm="' . AUTH_REALM . '"');
134 header('HTTP/1.0 401 Unauthorized');
135 echo '401 Unauthorized';
138 <!--~end~--><!--~pulldowns start~-->
139 pulldown('~name~', array('option 1', 'option 2', 'option 3'));
140 <!--~end~--><!--~opt_db_3 start~-->
141 $edit_id = format_int($_REQUEST['~form_name~_edit_id']);
142 unset($_REQUEST['~form_name~_edit_id']);
144 # add hidden field for database id of row we're editing
145 tem_set('~form_name~_edit_id', $edit_id);
149 $delete_id = format_int($_REQUEST['~form_name~_delete_id']);
150 unset($_REQUEST['~form_name~_delete_id']);
152 db_delete('~form_name~', 'where id=%i', $delete_id);
153 message('~singular.cap~ deleted.');
155 return './~form_name~';
158 if(!$edit_id) {<!--~opt_listing_1 start~-->
159 if(!isset($_REQUEST['~form_name~_new']) && !isset($_REQUEST['~always_field~'])) {
160 ~form_name~_display_listing();
167 if(isset($_REQUEST['~always_field~'])) {
168 list(~php_fields~) = ~form_name~_get_fields();
170 if("you're happy with the POSTed values") {<!--~opt_db_4 start~-->
172 db_update('~form_name~', ~form_name.upper~_DB_FIELDS, ~php_fields~, 'where id=%i', $edit_id);
173 message('~singular.cap~ updated.');
175 db_insert('~form_name~', ~form_name.upper~_DB_FIELDS, ~php_fields~);
176 message('~singular.cap~ saved.');
177 }<!--~end~--><!--~opt_email_2 start~-->
178 if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
179 $to = $GLOBALS['~form_name~_form_recipient'];
182 if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
183 $reply_to = $_REQUEST['email'];
184 if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
185 $reply_to = "$_REQUEST[name] <$reply_to>";
188 $subject = '~form_name~ form submitted';
189 $message = tem_run('~form_name~.email.txt');
192 if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
193 message('Due to an internal error, your message could not be sent. Please try again later.');
196 message('Message sent');
199 if($error !== true) {
200 return './~form_name~'; # FIXME is this the page you want to go to after successful form submission?
203 # otherwise, we display the form again. ~form_name~_get_fields() has
204 # already put the posted values back into the template engine, so they will
205 # show up in the form fields. You should add some message asking people to
206 # fix their entry in whatever way you require.<!--~opt_db_5 start~-->
208 # we've recieved an edit id, but no data. So we grab the values to be edited from the database
209 list(~php_fields~) = db_get_row('~form_name~', ~form_name.upper~_DB_FIELDS, 'where id=%i', $edit_id);
210 ~form_name~_tem_sets(~php_fields~);<!--~end~-->
212 # form not submitted, you can set default values like so:
213 #tem_set('~always_field~', 'Yes');
214 }<!--~upload_max start~-->
216 tem_set('upload_max_filesize', upload_max_filesize());<!--~end~-->
218 # this has to be later in the file because it requres that ~always_field~ be set already
220 tem_show('edit_msg');