- if(isset($_REQUEST['~always_field~'])) {
- list(~php_fields~) = ~form_name~_get_fields();
-
- if("you're happy with the POSTed values") {
- # to enable saving to a database, create a file called 'db_connect.php'
- # see: code/wfpl/examples/db_connect.php
- if(file_exists('db_connect.php')) {
- require_once('db_connect.php');
- if($edit_id) {<!--~image_db start~-->
- # uploading nothing means leaving it as is.
- if(!$~name~ && $delete_~name~ != 'Yes') {
- $~name~ = db_get_value('~form_name~', '~name~', 'id = %"', $edit_id);
- }
- <!--~end~-->
- db_update('~form_name~', '~db_fields~', ~php_fields~, 'id = %"', $edit_id);
- tem_set('did', 'updated');
- } else {
- db_insert('~form_name~', '~db_fields~', ~php_fields~);
- tem_set('did', 'saved');
- }
- }
- if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
- $to = $GLOBALS['~form_name~_form_recipient'];
+ $id = _REQUEST_cut('~file_name~_delete_id');
+ if($id) {
+ return ~file_name~_main_delete($id);
+ }
+
+ if(_REQUEST_cut('new')) {
+ return ~file_name~_main_form();
+ }
+~}~~opt_listing {~
+ if(_REQUEST_cut('list')) {
+ return ~file_name~_main_listing();
+ }
+~}~~opt_display {~
+ $id = _REQUEST_cut('id');
+ if($id) {
+ return ~file_name~_main_display($id);
+ }
+~}~~opt_listing {~
+ if(isset($_POST['~always_field~'])) {
+ return ~file_name~_main_form();
+ }
+
+ # default action:
+ return ~file_name~_main_listing();~}~~opt_listing unset {~
+ return ~file_name~_main_form();~}~
+}~opt_display {~
+
+function ~file_name~_main_display($id) {
+ $data = db_get_assoc('~table_name~', 'id,'.~file_name upper~_DB_FIELDS, 'where id=%i', $id);
+ if(!$data) {
+ message("Error: Broken Link (~singular cap~ #$id not found)");~opt_public_something {~
+ return './' . $GLOBALS['wfpl_basename'];~}~~opt_public_something unset {~
+ return './~file_name~';~}~
+ }
+ tem_set('display', $data);
+}~}~~opt_db {~
+
+function ~file_name~_main_delete($id) {
+ db_delete('~table_name~', 'where id=%i', $id);
+ message('~singular cap~ deleted.');
+ return './~file_name~';
+}~}~~opt_listing {~
+
+function ~file_name~_main_listing() {
+ $listing_rows = db_get_assocs('~table_name~', 'id~listing_fields_1 {~,~name~~}~', 'order by ~always_field~ limit 100');
+ tem_set('listings', $listing_rows);
+}~}~
+
+function ~file_name~_main_form($id = false) {~pulldowns {~
+ pulldown('~name~', ~pulldown_options~);~}~~has_pulldowns {~
+~}~~opt_db {~
+ if($id) {
+ # add hidden field for database id of row we're editing
+ tem_set('id', $id);
+ tem_set('editing');
+ tem_set('edit_msg');
+ } else {
+ tem_set('new_msg');
+ }
+~}~
+ if(isset($_POST['~always_field~'])) {
+ $data = ~file_name~_get_fields();
+
+ if("you're happy with the POSTed values") {~opt_db {~
+ if($id) {
+ db_update_assoc('~table_name~', $data, 'where id=%i', $id);
+ message('~singular cap~ updated.');
+ } else {
+ db_insert_assoc('~table_name~', $data);
+ message('~singular cap~ saved.');
+ }~}~~opt_email {~
+ if($GLOBALS['~file_name~_form_recipient'] != 'fixme@example.com') {
+ $to = $GLOBALS['~file_name~_form_recipient'];
+ $from = 'noreply@~this_domain~';
+ $reply_to = $to;