-function ~form_name~() {
- if(isset($_REQUEST['~always_field~'])) {
- list(~php_fields~) = ~form_name~_get_fields();
-
- if("you're happy with the POSTed values") {
- # uncomment the following lines to save the values recieved to the
- # database. You can use ~form_name~.sql to create the database table.
- #require_once('db_connect.php');
- #db_insert('~form_name~', '~db_fields~', ~php_fields~);
- if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
- $to = $GLOBALS['~form_name~_form_recipient'];
+function ~file_name~_display_main() {
+ $id = format_int($_REQUEST['~file_name~_id']);
+ unset($_REQUEST['~file_name~_id']);
+ if(!$id) {
+ message('Error: Broken link');
+ return './~file_name~';
+ }
+ $row = db_get_assoc('~table_name~', 'id,'.~file_name upper~_DB_FIELDS, 'where id=%i', $id);
+ if(!$row) {
+ message('Error: ~singular cap~ not found');
+ return './~file_name~';
+ }
+ tem_set('display', $row);
+}
+
+function ~file_name~_edit_main() {<!--~}~--><!--~pulldowns {~-->
+ pulldown('~name~', array('option 1', 'option 2', 'option 3'));
+<!--~}~--><!--~opt_db {~-->
+ $edit_id = format_int($_REQUEST['~file_name~_edit_id']);
+ unset($_REQUEST['~file_name~_edit_id']);
+ if($edit_id) {
+ # add hidden field for database id of row we're editing
+ tem_set('~file_name~_edit_id', $edit_id);
+ tem_set('editing', 'show');
+ tem_set('edit_msg', 'show');
+ }
+
+ $delete_id = format_int($_REQUEST['~file_name~_delete_id']);
+ unset($_REQUEST['~file_name~_delete_id']);
+ if($delete_id) {
+ db_delete('~table_name~', 'where id=%i', $delete_id);
+ message('~singular cap~ deleted.');
+
+ return './~file_name~';
+ }
+
+ if(!$edit_id) {<!--~opt_listing {~-->
+ if(!isset($_REQUEST['~file_name~_new']) && !isset($_REQUEST['~always_field~'])) {
+ ~file_name~_display_listing();
+ return;
+ }
+<!--~}~-->
+ tem_set('new_msg', 'show');
+ }
+<!--~}~-->
+ if(isset($_POST['~always_field~'])) {
+ $data = ~file_name~_get_fields();
+
+ if("you're happy with the POSTed values") {<!--~opt_db {~-->
+ if($edit_id) {
+ db_update_assoc('~table_name~', $data, 'where id=%i', $edit_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;