JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
metaform capitalizes default captions, added tem::load_str()
authorJason Woofenden <jason183@herkamire.com>
Fri, 15 Jun 2007 07:53:30 +0000 (03:53 -0400)
committerJason Woofenden <jason183@herkamire.com>
Fri, 15 Jun 2007 07:53:30 +0000 (03:53 -0400)
metaform preview is passed through template engine properly

format.php
metaform.php
template.php

index 055e66d..8979b26 100644 (file)
 
 # This file contains basic encodings
 
+function format_caption($str) {
+       $str = ucwords($str);
+       return str_replace('Email', 'E-mail', $str);
+}
+
 function format_int($str) {
        $str = ereg_replace('[^0-9]', '', $str);
        return ereg_replace('^0*([1-9])', '\1', $str);
index 1119d0c..c8bb395 100644 (file)
@@ -187,7 +187,7 @@ function make_html($whole_file = true) {
        foreach($fields as $field) {
                list($name, $type, $input, $format, $sql) = $field;
                $tem->set('name', $name);
-               $tem->set('caption', $name); # fixme
+               $tem->set('caption', format_caption($name));
                $tem->sub($input);
                if($input != 'hidden') {
                        $tem->sub('row');
@@ -345,7 +345,11 @@ function preview() {
        tem_set('form_name', $GLOBALS['form_name']);
        tem_set('fields', $_REQUEST['fields']);
        $preview_tem = new tem();
-       $preview = $preview_tem->run(make_html(false));
+       $preview_tem->load_str(make_html(false));
+       if($GLOBALS['opt_db'] == 'Yes') {
+               $preview_tem->sub('new_msg');
+       }
+       $preview = $preview_tem->run();
        unset($preview_tem);
        tem_set('preview', $preview);
        set_form_action();
index e386fe2..28b4814 100644 (file)
@@ -130,16 +130,20 @@ class tem {
                } #repeat
        }
 
+       # like load() except you pass a string instead of a filename
+       function load_str($str) {
+               $this->template = '';
+               $parents = array('top_level_subs' => array());
+               $parent = 'top_level_subs';
+               $this->_load($str, $this->template, $parents, $parent);
+       }
+
        # This is useful when you have sub-templates that you want to mess with
        # before the main template is run. But can also be used to simply specify
        # the filename ahead of time.
        function load($filename) {
                $this->filename = $filename;
-               $tmp = read_whole_file($filename);
-               $this->template = '';
-               $parents = array('top_level_subs' => array());
-               $parent = 'top_level_subs';
-               $this->_load($tmp, $this->template, $parents, $parent);
+               $this->load_str(read_whole_file($filename));
        }
                
        # Run the template. Pass a filename, or a string, unless you've already