JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
revamp metaform so php holds db/form data as hash
authorJason Woofenden <jason@jasonwoof.com>
Tue, 6 Apr 2010 03:30:21 +0000 (23:30 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Tue, 6 Apr 2010 03:39:26 +0000 (23:39 -0400)
TODO
metaform.php
metaform/template.html
metaform/template.php

diff --git a/TODO b/TODO
index 54dc266..7ce467f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,4 +1,3 @@
        db_reposition(): add parameter for "where clause" so it can work on any subset of the rows
        db_reposition(): add parameter for "where clause" so it can work on any subset of the rows
-       metaform: change php so it stores/passes form/db data in hashes instead of locals
        finish and test "delete" checkbox for images
        test db stuff with images
        finish and test "delete" checkbox for images
        test db stuff with images
index ee5b942..a4a7872 100644 (file)
@@ -301,7 +301,6 @@ function make_html($whole_file = true) {
 
        if($GLOBALS['opt_display'] == 'Yes') {
                $tem->show('opt_display_1');
 
        if($GLOBALS['opt_display'] == 'Yes') {
                $tem->show('opt_display_1');
-               $tem->show('opt_display_2');
        }
 
        if($GLOBALS['opt_email'] == 'Yes' && $GLOBALS['opt_db'] != 'Yes') {
        }
 
        if($GLOBALS['opt_email'] == 'Yes' && $GLOBALS['opt_db'] != 'Yes') {
@@ -358,7 +357,6 @@ function make_php() {
        $tem->set('plural', $GLOBALS['plural']);
        $fields = get_fields();
        $db_fields = '';
        $tem->set('plural', $GLOBALS['plural']);
        $fields = get_fields();
        $db_fields = '';
-       $php_fields = '';
        $always_field = find_always_field($fields);
        $image_included_yet = false;
        foreach($fields as $field) {
        $always_field = find_always_field($fields);
        $image_included_yet = false;
        foreach($fields as $field) {
@@ -370,8 +368,6 @@ function make_php() {
                        if($sql != 'n/a') {
                                if($db_fields != '') $db_fields .= ',';
                                $db_fields .= $name;
                        if($sql != 'n/a') {
                                if($db_fields != '') $db_fields .= ',';
                                $db_fields .= $name;
-                               if($php_fields != '') $php_fields .= ', ';
-                               $php_fields .= '$' . $name;
                        }
                        if($input == 'image') {
                                if($type == 'thumb') {
                        }
                        if($input == 'image') {
                                if($type == 'thumb') {
@@ -396,7 +392,6 @@ function make_php() {
                                }
                                $tem->show('formats');
                        }
                                }
                                $tem->show('formats');
                        }
-                       $tem->show('tem_sets');
                }
 
                if($GLOBALS['opt_listing'] == 'Yes') {
                }
 
                if($GLOBALS['opt_listing'] == 'Yes') {
@@ -413,7 +408,6 @@ function make_php() {
 
        $tem->set('always_field', $always_field);
        $tem->set('db_fields', $db_fields);
 
        $tem->set('always_field', $always_field);
        $tem->set('db_fields', $db_fields);
-       $tem->set('php_fields', $php_fields);
        $tem->set('metaform_url', edit_url());
        if($GLOBALS['opt_listing'] == 'Yes') {
                $tem->show('opt_listing_1');
        $tem->set('metaform_url', edit_url());
        if($GLOBALS['opt_listing'] == 'Yes') {
                $tem->show('opt_listing_1');
@@ -424,7 +418,6 @@ function make_php() {
                $tem->show('opt_display_2');
        } else {
                $tem->show('opt_display_1_else');
                $tem->show('opt_display_2');
        } else {
                $tem->show('opt_display_1_else');
-               $tem->show('opt_display_2_else');
        }
        if($GLOBALS['opt_db'] == 'Yes') {
                $tem->show('opt_db_1');
        }
        if($GLOBALS['opt_db'] == 'Yes') {
                $tem->show('opt_db_1');
index 07b55e6..93702c3 100644 (file)
 <body>
 <!--~~main_body show {~~-->
 
 <body>
 <!--~~main_body show {~~-->
 
-    <!--~~wfpl_messages {~~-->
-      <!--~~ first {~~-->
-        <div style="border: 2px solid red; background: #fbb; padding: 5px; margin: 20px 0px">
-      <!--~~}~~-->
-          <p style="font-size: 120%; padding: 5px; margin: 0px">~~data html~~</p>
-      <!--~~ sep {~~-->
-          <hr />
-      <!--~~}~~-->
-      <!--~~ last {~~-->
-        </div>
-      <!--~~}~~-->
+  <!--~~wfpl_messages {~~-->
+    <!--~~ first {~~-->
+      <div style="border: 2px solid red; background: #fbb; padding: 5px; margin: 20px 0px">
     <!--~~}~~-->
     <!--~~}~~-->
-<!--~opt_display_1 {~-->
-<!--~~display_body {~~-->
-  <h2>~singular cap~ details</h2>
+        <p style="font-size: 120%; padding: 5px; margin: 0px">~~data html~~</p>
+    <!--~~ sep {~~-->
+        <hr />
+    <!--~~}~~-->
+    <!--~~ last {~~-->
+      </div>
+    <!--~~}~~-->
+  <!--~~}~~--><!--~opt_display_1 {~-->
+
+  <!--~~display {~~-->
+    <h2>~singular cap~ details</h2>
 
     <p><a href="~file_name~?~file_name~_edit_id=~~id attr~~">Edit</a></p>
 
 
     <p><a href="~file_name~?~file_name~_edit_id=~~id attr~~">Edit</a></p>
 
     </table>
 
     <p><a href="~file_name~?~file_name~_edit_id=~~id attr~~">Edit</a></p>
     </table>
 
     <p><a href="~file_name~?~file_name~_edit_id=~~id attr~~">Edit</a></p>
-<!--~~}~~-->
+  <!--~~}~~--><!--~}~-->
 
 
-<!--~~edit_body {~~-->
-<!--~}~-->
-<!--~~form {~~--><!--~form {~-->
-  <h2><!--~opt_db_1 {~--><!--~~new_msg {~~-->Add a new ~singular~<!--~~}~~--><!--~~edit_msg {~~-->Edit ~singular~ "~~~always_field~ html~~"<!--~~}~~--><!--~}~--><!--~opt_db_1_else {~-->Submit a ~singular~<!--~}~--></h2>
+  <!--~~form {~~--><!--~form {~-->
+    <h2><!--~opt_db_1 {~--><!--~~new_msg {~~-->Add a new ~singular~<!--~~}~~--><!--~~edit_msg {~~-->Edit ~singular~ "~~~always_field~ html~~"<!--~~}~~--><!--~}~--><!--~opt_db_1_else {~-->Submit a ~singular~<!--~}~--></h2>
 
 
-  <form action="~file_name~" method="post~enctype_attr~"><!--~opt_db_2 {~--><!--~~editing {~~--><div style="display: none"><input type="hidden" name="~file_name~_edit_id" value="~~~file_name~_edit_id attr~~" /></div><!--~~}~~--><!--~}~--><!--~uploads {~--><input type="hidden" name="MAX_FILE_SIZE" value="~~upload_max_filesize~~" /><!--~}~-->
+    <form action="~file_name~" method="post~enctype_attr~"><!--~opt_db_2 {~--><!--~~editing {~~--><div style="display: none"><input type="hidden" name="~file_name~_edit_id" value="~~~file_name~_edit_id attr~~" /></div><!--~~}~~--><!--~}~--><!--~uploads {~--><input type="hidden" name="MAX_FILE_SIZE" value="~~upload_max_filesize~~" /><!--~}~-->
 <!--~row {~--><!--~image {~-->
 <!--~row {~--><!--~image {~-->
-    <div class="caption">~caption html~</div>
-    <div class="field"><input type="file" name="~name~" /><input type="hidden" name="old_~name~" value="~~~name~ attr~~" /></div><!--~}~--><!--~textbox {~-->
-    <div class="caption">~caption html~</div>
-    <div class="field"><input type="text" name="~name~" value="~~~name~ attr~~" /></div><!--~}~--><!--~date {~-->
-    <div class="caption">~caption html~</div>
-    <div class="field"><input type="text" name="~name~" value="~~~name~ mmddyyyy attr~~" /> mm/dd/yyyy</div><!--~}~--><!--~password {~-->
-    <div class="caption">~caption html~</div>
-    <div class="field"><input type="password" name="~name~" value="~~~name~ attr~~" /></div><!--~}~--><!--~textarea {~-->
-    <div class="caption">~caption html~</div>
-    <div class="field"><textarea rows="9" cols="22" name="~name~">~~~name~ html~~</textarea></div><!--~}~--><!--~html {~-->
-    <div class="caption">~caption html~</div>
-    <div class="field"><textarea class="html_editor" rows="20" cols="50" name="~name~">~~~name~ html~~</textarea></div><!--~}~--><!--~pulldown {~-->
-    <div class="caption">~caption html~</div>
-    <div class="field"><select name="~name~"><option value="">Choose One:</option><!--~~~name~ options~~--></select></div><!--~}~--><!--~states {~-->
-    <div class="caption">~caption html~</div>
-    <div class="field"><select name="~name~"><option value="">Choose One:</option><!--~~~name~ states~~--></select></div><!--~}~--><!--~radio {~-->
-    <div class="caption">~caption html~</div>
-    <div class="field"><input type="radio" name="~name~~~~name~ checked~~" /></div><!--~}~--><!--~checkbox {~-->
-    <div class="caption"><input type="checkbox" name="~name~~~~name~ checked~~" /> ~caption html~</div>
-    <div class="field"></div><!--~}~--><!--~submit {~-->
-    <div class="field"><input type="submit" name="~name~" value="~caption attr~" /></div><!--~}~-->
+      <div class="caption">~caption html~</div>
+      <div class="field"><input type="file" name="~name~" /><input type="hidden" name="old_~name~" value="~~~name~ attr~~" /></div><!--~}~--><!--~textbox {~-->
+      <div class="caption">~caption html~</div>
+      <div class="field"><input type="text" name="~name~" value="~~~name~ attr~~" /></div><!--~}~--><!--~date {~-->
+      <div class="caption">~caption html~</div>
+      <div class="field"><input type="text" name="~name~" value="~~~name~ mmddyyyy attr~~" /> mm/dd/yyyy</div><!--~}~--><!--~password {~-->
+      <div class="caption">~caption html~</div>
+      <div class="field"><input type="password" name="~name~" value="~~~name~ attr~~" /></div><!--~}~--><!--~textarea {~-->
+      <div class="caption">~caption html~</div>
+      <div class="field"><textarea rows="9" cols="22" name="~name~">~~~name~ html~~</textarea></div><!--~}~--><!--~html {~-->
+      <div class="caption">~caption html~</div>
+      <div class="field"><textarea class="html_editor" rows="20" cols="50" name="~name~">~~~name~ html~~</textarea></div><!--~}~--><!--~pulldown {~-->
+      <div class="caption">~caption html~</div>
+      <div class="field"><select name="~name~"><option value="">Choose One:</option><!--~~~name~ options~~--></select></div><!--~}~--><!--~states {~-->
+      <div class="caption">~caption html~</div>
+      <div class="field"><select name="~name~"><option value="">Choose One:</option><!--~~~name~ states~~--></select></div><!--~}~--><!--~radio {~-->
+      <div class="caption">~caption html~</div>
+      <div class="field"><input type="radio" name="~name~~~~name~ checked~~" /></div><!--~}~--><!--~checkbox {~-->
+      <div class="caption"><input type="checkbox" name="~name~~~~name~ checked~~" /> ~caption html~</div>
+      <div class="field"></div><!--~}~--><!--~submit {~-->
+      <div class="caption">&nbsp;</div>
+      <div class="field"><input type="submit" name="~name~" value="~caption attr~" /></div><!--~}~-->
 <!--~}~-->
 <!--~}~-->
-    </table>
-  </form>
-<!--~}~--><!--~~}~~-->
-<!--~opt_listing_1 {~--><!--~~listings {~~-->
-  <h2>~plural cap~ Listing</h2>
+    </form>
+  <!--~}~--><!--~~}~~--><!--~opt_listing_1 {~-->
 
 
-  <!--~~populated_listing {~~-->
-  <p><a href="~file_name~?~file_name~_new=1">[Add a new ~singular~]</a></p>
+  <!--~~listings {~~-->
+    <h2>~plural cap~ Listing</h2>
 
 
-  <table cellspacing="0" cellpadding="4" border="1" summary="">
-    <!--~listing_head_col {~--><th>~caption~</th><!--~}~--><th>&nbsp;</th><!--~~listing_row {~~-->
-    <tr><!--~listing_row_col {~-->
-      <td class="listing"><a href="~file_name~?~file_name~_<!--~opt_display_a_else {~-->edit_<!--~}~-->id=~~id~~"><!--~listing_value_enc {~-->~~~name~ ~listing_enc~~~<!--~}~--><!--~listing_value_thumb {~--><img src="~~~name~ thumb_src~~" width="~~~name~ thumb_width~~" height="~~~name~ thumb_height~~" alt="" /><!--~}~--></a></td><!--~}~-->
-      <td><a href="~file_name~?~file_name~_delete_id=~~id~~" onclick="return confirm('Permanently delete?')">[delete this ~singular~]</a></td>
-    </tr><!--~~}~~-->
+    <!--~~populated_listing {~~-->
+      <p><a href="~file_name~?~file_name~_new=1">[Add a new ~singular~]</a></p>
 
 
-  </table>
-  <!--~~}~~-->
-  <!--~~empty_listing {~~-->
-    <p>No ~plural~ in database.</p>
-  <!--~~}~~-->
+      <table cellspacing="0" cellpadding="4" border="1" summary="">
+        <!--~listing_head_col {~--><th>~caption~</th><!--~}~--><th>&nbsp;</th><!--~~rows {~~-->
+        <tr><!--~listing_row_col {~-->
+          <td class="listing"><a href="~file_name~?~file_name~_<!--~opt_display_a_else {~-->edit_<!--~}~-->id=~~id~~"><!--~listing_value_enc {~-->~~~name~ ~listing_enc~~~<!--~}~--><!--~listing_value_thumb {~--><img src="~~~name~ thumb_src~~" width="~~~name~ thumb_width~~" height="~~~name~ thumb_height~~" alt="" /><!--~}~--></a></td><!--~}~-->
+          <td><a href="~file_name~?~file_name~_delete_id=~~id~~" onclick="return confirm('Permanently delete?')">[delete this ~singular~]</a></td>
+        </tr><!--~~}~~-->
 
 
-  <p><a href="~file_name~?~file_name~_new=1">[Add a new ~singular~]</a></p>
-<!--~~}~~--><!--~}~-->
-<!--~opt_display_2 {~-->
+      </table>
+    <!--~~}~~-->
+    <!--~~empty_listing {~~-->
+      <p>No ~plural~ in database.</p>
+    <!--~~}~~-->
+
+    <p><a href="~file_name~?~file_name~_new=1">[Add a new ~singular~]</a></p>
+  <!--~~}~~--><!--~}~-->
 
 
-<!--~~}~~-->
-<!--~}~-->
 <!--~~}~~-->
 </body>
 </html>
 <!--~~}~~-->
 </body>
 </html>
index 520ca57..6ae0602 100644 (file)
@@ -40,69 +40,57 @@ require_once('code/wfpl/email.php');<!--~opt_db_2 {~-->
 require_once('code/db_connect.php');<!--~}~--><!--~image_include {~-->
 require_once('code/wfpl/upload.php');<!--~}~-->
 
 require_once('code/db_connect.php');<!--~}~--><!--~image_include {~-->
 require_once('code/wfpl/upload.php');<!--~}~-->
 
-function ~file_name~_get_fields() {<!--~formats {~-->
-       $~name~ = format_~format~($_REQUEST['~name~']<!--~pulldown_format_extra {~-->, '~name~'<!--~}~-->);<!--~}~--><!--~image_upload {~-->
+function ~file_name~_get_fields() {
+       $data = array();
+<!--~formats {~-->
+       $data['~name~'] = format_~format~($_REQUEST['~name~']<!--~pulldown_format_extra {~-->, '~name~'<!--~}~-->);<!--~}~--><!--~image_upload {~-->
        if($_FILES['~name~'] && $_FILES['~name~']['error'] == 0) {
        if($_FILES['~name~'] && $_FILES['~name~']['error'] == 0) {
-               $~name~ = convert_uploaded_image('~name~', $GLOBALS['upload_directory'] . $GLOBALS['~name~_file_name'], $GLOBALS['~name~_max_width'], $GLOBALS['~name~_max_height']<!--~thumb_upload_params {~-->, $GLOBALS['~name~_thumb_max_width'], $GLOBALS['~name~_thumb_max_height']<!--~}~-->);
+               $data['~name~'] = convert_uploaded_image('~name~', $GLOBALS['upload_directory'] . $GLOBALS['~name~_file_name'], $GLOBALS['~name~_max_width'], $GLOBALS['~name~_max_height']<!--~thumb_upload_params {~-->, $GLOBALS['~name~_thumb_max_width'], $GLOBALS['~name~_thumb_max_height']<!--~}~-->);
        } else {
                if($_REQUEST['delete_~name~'] == 'Yes') {
        } else {
                if($_REQUEST['delete_~name~'] == 'Yes') {
-                       $~name~ = '';
+                       $data['~name~'] = '';
                } else {
                } else {
-                       $~name~ = format_image_w_h<!--~thumb_w_h {~-->_thumb_w_h<!--~}~-->($_REQUEST['old_~name~']);
+                       $data['~name~'] = format_image_w_h<!--~thumb_w_h {~-->_thumb_w_h<!--~}~-->($_REQUEST['old_~name~']);
                }
        }<!--~}~-->
 
                }
        }<!--~}~-->
 
-       ~file_name~_tem_sets(~php_fields~);
-
-       return array(~php_fields~);
+       return $data;
 }
 
 }
 
-function ~file_name~_tem_sets(~php_fields~) {<!--~tem_sets {~-->
-       tem_set('~name~', $~name~);<!--~}~-->
-}
 <!--~opt_listing_2 {~-->
 # You may pass a "where clause" for the db query.
 function ~file_name~_display_listing($where = 'order by ~always_field~ limit 100') {
 <!--~opt_listing_2 {~-->
 # You may pass a "where clause" for the db query.
 function ~file_name~_display_listing($where = 'order by ~always_field~ limit 100') {
-       $rows = db_get_rows('~table_name~', 'id<!--~listing_fields_1 {~-->,~name~<!--~}~-->', $where);
+       $rows = db_get_assocs('~table_name~', 'id<!--~listing_fields_1 {~-->,~name~<!--~}~-->', $where);
        if($rows == false || count($rows) == 0) {
        if($rows == false || count($rows) == 0) {
-               tem_show('empty_listing');
-               tem_show('listings');
-               return false;
+               tem_set('listings', array('empty_listing' => true));
+               return;
        }
 
        }
 
-       foreach($rows as $row) {
-               list($id<!--~listing_fields_2 {~-->, $~name~<!--~}~-->) = $row;
-               tem_set('id', $id);
-               if($~always_field~ == '') {
-                       $~always_field~ = '--';
+       # make sure there's something clickable
+       foreach($rows as &$row) {
+               if($row['~always_field~'] == '') {
+                       $row['~always_field~'] = '--';
                }
                }
-               ~file_name~_tem_sets(~php_fields~);
-               tem_show('listing_row');
        }
        }
-       tem_show('populated_listing');
-       tem_show('listings');
+       tem_set('listings', array(
+               'populated_listing' => true,
+               'rows' => $rows));
        return true;
 }
 <!--~}~-->
        return true;
 }
 <!--~}~-->
-function ~file_name~_main() {<!--~opt_display_1 {~-->
+function ~file_name~_main() {<!--~opt_pass {~-->
+       if(!logged_in_as_admin()) {
+               $GLOBALS['url'] = this_url();
+               return 'admin_login';
+       }
+<!--~}~--><!--~opt_display_1 {~-->
        if(isset($_REQUEST['~file_name~_id'])) {
        if(isset($_REQUEST['~file_name~_id'])) {
-               $ret = ~file_name~_display_main();
-               if($ret) {
-                       return $ret;
-               }
-               tem_show('display_body');
+               return ~file_name~_display_main();
        } else {
        } else {
-               $ret = ~file_name~_edit_main();
-               if($ret) {
-                       return $ret;
-               }
-               tem_show('edit_body');
+               return ~file_name~_edit_main();
        }
 <!--~}~--><!--~opt_display_1_else {~-->
        }
 <!--~}~--><!--~opt_display_1_else {~-->
-       $ret = _~file_name~_main();
-       if($ret) {
-               return $ret;
-       }
+       return ~file_name~_edit_main();
 <!--~}~-->
 }<!--~opt_display_2 {~-->
 
 <!--~}~-->
 }<!--~opt_display_2 {~-->
 
@@ -113,25 +101,15 @@ function ~file_name~_display_main() {
                message('Error: Broken link');
                return './~file_name~';
        }
                message('Error: Broken link');
                return './~file_name~';
        }
-       $row = db_get_row('~table_name~', ~file_name upper~_DB_FIELDS, 'where id=%i', $id);
+       $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~';
        }
        if(!$row) {
                message('Error: ~singular cap~ not found');
                return './~file_name~';
        }
-       list(~php_fields~) = $row;
-       ~file_name~_tem_sets(~php_fields~);
-       tem_set('id', $id);
-}
+       tem_set('display', $row);
+}<!--~}~-->
 
 
-function ~file_name~_edit_main() {<!--~}~--><!--~opt_display_2_else {~-->
-
-
-function _~file_name~_main() {<!--~}~--><!--~opt_pass {~-->
-       if(!logged_in_as_admin()) {
-               $GLOBALS['url'] = this_url();
-               return 'admin_login';
-       }
-<!--~}~--><!--~pulldowns {~-->
+function ~file_name~_edit_main() {<!--~pulldowns {~-->
        pulldown('~name~', array('option 1', 'option 2', 'option 3'));
 <!--~}~--><!--~opt_db_3 {~-->
        $edit_id = format_int($_REQUEST['~file_name~_edit_id']);
        pulldown('~name~', array('option 1', 'option 2', 'option 3'));
 <!--~}~--><!--~opt_db_3 {~-->
        $edit_id = format_int($_REQUEST['~file_name~_edit_id']);
@@ -139,7 +117,8 @@ function _~file_name~_main() {<!--~}~--><!--~opt_pass {~-->
        if($edit_id) {
                # add hidden field for database id of row we're editing
                tem_set('~file_name~_edit_id', $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_show('editing');
+               tem_set('editing', 'show');
+               tem_set('edit_msg', 'show');
        }
 
        $delete_id = format_int($_REQUEST['~file_name~_delete_id']);
        }
 
        $delete_id = format_int($_REQUEST['~file_name~_delete_id']);
@@ -157,18 +136,18 @@ function _~file_name~_main() {<!--~}~--><!--~opt_pass {~-->
                        return;
                }
 <!--~}~-->
                        return;
                }
 <!--~}~-->
-               tem_show('new_msg');
+               tem_set('new_msg', 'show');
        }<!--~}~-->
 
        if(isset($_POST['~always_field~'])) {
        }<!--~}~-->
 
        if(isset($_POST['~always_field~'])) {
-               list(~php_fields~) = ~file_name~_get_fields();
+               $data = ~file_name~_get_fields();
 
                if("you're happy with the POSTed values") {<!--~opt_db_4 {~-->
                        if($edit_id) {
 
                if("you're happy with the POSTed values") {<!--~opt_db_4 {~-->
                        if($edit_id) {
-                               db_update('~table_name~', ~file_name upper~_DB_FIELDS, ~php_fields~, 'where id=%i', $edit_id);
+                               db_update_assoc('~table_name~', $data, 'where id=%i', $edit_id);
                                message('~singular cap~ updated.');
                        } else {
                                message('~singular cap~ updated.');
                        } else {
-                               db_insert('~table_name~', ~file_name upper~_DB_FIELDS, ~php_fields~);
+                               db_insert_assoc('~table_name~', $data);
                                message('~singular cap~ saved.');
                        }<!--~}~--><!--~opt_email_2 {~-->
                        if($GLOBALS['~file_name~_form_recipient'] != 'fixme@example.com') {
                                message('~singular cap~ saved.');
                        }<!--~}~--><!--~opt_email_2 {~-->
                        if($GLOBALS['~file_name~_form_recipient'] != 'fixme@example.com') {
@@ -182,7 +161,10 @@ function _~file_name~_main() {<!--~}~--><!--~opt_pass {~-->
                                        }
                                }
                                $subject = '~plural cap~ form submitted';
                                        }
                                }
                                $subject = '~plural cap~ form submitted';
-                               $message = tem_run('~file_name~.email.txt');
+                               $email_template = new tem();
+                               $email_template->load('~file_name~.email.txt');
+                               $email_template->sets($data);
+                               $message = $email_template->run();
                                $cc = '';
                                $bcc = '';
                                if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
                                $cc = '';
                                $bcc = '';
                                if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
@@ -202,22 +184,17 @@ function _~file_name~_main() {<!--~}~--><!--~opt_pass {~-->
                # fix their entry in whatever way you require.<!--~opt_db_5 {~-->
        } elseif($edit_id) {
                # we've recieved an edit id, but no data. So we grab the values to be edited from the database
                # fix their entry in whatever way you require.<!--~opt_db_5 {~-->
        } elseif($edit_id) {
                # we've recieved an edit id, but no data. So we grab the values to be edited from the database
-               list(~php_fields~) = db_get_row('~table_name~', ~file_name upper~_DB_FIELDS, 'where id=%i', $edit_id);
-               ~file_name~_tem_sets(~php_fields~);<!--~}~-->
+               $data = db_get_assoc('~table_name~', ~file_name upper~_DB_FIELDS, 'where id=%i', $edit_id);<!--~}~-->
        } else {
                # form not submitted, you can set default values like so:
        } else {
                # form not submitted, you can set default values like so:
-               #tem_set('~always_field~', 'Yes');
+               #$data = array('~always_field~' => 'Yes');
+               $data = array();
        }<!--~upload_max {~-->
 
        tem_set('upload_max_filesize', upload_max_filesize());<!--~}~-->
 
        }<!--~upload_max {~-->
 
        tem_set('upload_max_filesize', upload_max_filesize());<!--~}~-->
 
-       # this has to be later in the file because it requres that ~always_field~ be set already
-       if($edit_id) {
-               tem_show('edit_msg');
-       }
-
-       tem_show('form');<!--~show_extra_headers {~-->
-       tem_show('extra_headers');<!--~}~-->
+       tem_set('form', $data);<!--~show_extra_headers {~-->
+       tem_set('extra_headers', 'show');<!--~}~-->
 }
 
 ?>
 }
 
 ?>