JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
metaform supports password and hidden fields
authorJason Woofenden <jason183@herkamire.com>
Sun, 31 Dec 2006 06:11:45 +0000 (01:11 -0500)
committerJason Woofenden <jason183@herkamire.com>
Sun, 31 Dec 2006 06:11:45 +0000 (01:11 -0500)
varibles from form are much more accessible
now set up to be used from run.php if available

metaform.php
metaform/template.html
metaform/template.php

index d8cc07e..2adf13b 100644 (file)
@@ -36,6 +36,8 @@ $GLOBALS['types'] = array(
        'money' =>      array('textbox',     'money',      'varchar(32)'),
        'dollars' =>    array('textbox',     'dollars',    'varchar(32)'),
        'url' =>        array('textbox',     'url',        'varchar(200)'),
+       'hidden' =>     array('hidden',      'unix',       'varchar(200)'),
+       'password' =>   array('password',    'oneline',    'varchar(200)'),
        'textarea' =>   array('textarea',    'unix',       'text'),
        'pulldown' =>   array('pulldown',    'options',    'int'),
        'checkbox' =>   array('checkbox',    'yesno',      'int'),
@@ -156,7 +158,9 @@ function make_template($whole_file = true) {
                $tem->set('name', $name);
                $tem->set('caption', $name); # fixme
                $tem->sub($input);
-               $tem->sub('row');
+               if($input != 'hidden') {
+                       $tem->sub('row');
+               }
        }
        $tem->set('name', 'save');
        $tem->set('caption', 'Save');
@@ -182,6 +186,7 @@ function make_php() {
        $tem->set('form_name', $GLOBALS['form_name']);
        $fields = get_fields();
        $db_fields = '';
+       $php_fields = '';
        $always_field = false;
        foreach($fields as $field) {
                list($name, $type, $input, $format, $sql) = $field;
@@ -190,9 +195,10 @@ function make_php() {
                        $tem->set('name', $name);
                        $tem->set('db_field', ''); # we don't want to use the value from last time
                        if($sql != 'n/a') {
-                               $tem->sub('db_field');
                                if($db_fields != '') $db_fields .= ',';
                                $db_fields .= $name;
+                               if($php_fields != '') $php_fields .= ', ';
+                               $php_fields .= '$' . $name;
                        }
                        $tem->sub('formats');
                        if(!$always_field and $input != 'checkbox' and $input != 'radio') {
@@ -203,6 +209,7 @@ function make_php() {
        # always_field is a form field that always submits (unlike say, checkboxes). It's used to detect if the form has submitted or not.
        $tem->set('always_field', $always_field);
        $tem->set('db_fields', $db_fields);
+       $tem->set('php_fields', $php_fields);
        return $tem->run();
 }
 
index 8445292..d334cd6 100644 (file)
@@ -12,9 +12,11 @@ td.caption { text-align: right; font-weight: bold; }
 <!--~~form start~~--><!--~form start~-->
   <h2>~form_name~ entry form</h2>
 
-  <form action="~form_name~.php" method="post">
+  <form action="~form_name~.php" method="post"><!--~hidden start~--><input type="hidden" name="~name~" value="~~~name~.attr~~" /><!--~end~-->
     <table cellspacing="0" cellpadding="4" border="0" summary=""><!--~row start~-->
-      <tr><!--~textbox start~--><td class="caption">~caption.html~: </td><td><input type="text" name="~name~" value="~~~name~.attr~~" /></td><!--~end~--></tr><!--~textarea start~--><td class="caption">~caption.html~: </td><td><textarea name="~name~">~~~name~.html~~</textarea></td><!--~end~--><!--~checkbox start~--><td class="caption">~caption.html~: </td><td><input type="checkbox" name="~name~~~~name~.checked~~" /></td><!--~end~--><!--~submit start~--><tr><td class="submit_row" colspan="2"><input type="submit" name="~name~" value="~caption.attr~" /></td><!--~end~--></tr><!--~end~-->
+
+      <tr><!--~textbox start~--><td class="caption">~caption.html~: </td><td><input type="text" name="~name~" value="~~~name~.attr~~" /></td><!--~end~--><!--~password start~--><td class="caption">~caption.html~: </td><td><input type="password" name="~name~" value="~~~name~.attr~~" /></td><!--~end~--><!--~textarea start~--><td class="caption">~caption.html~: </td><td><textarea name="~name~">~~~name~.html~~</textarea></td><!--~end~--><!--~checkbox start~--><td class="caption">~caption.html~: </td><td><input type="checkbox" name="~name~~~~name~.checked~~" /></td><!--~end~--><!--~submit start~--><td class="submit_row" colspan="2"><input type="submit" name="~name~" value="~caption.attr~" /></td><!--~end~--></tr><!--~end~-->
+
     </table>
   </form>
 <!--~end~--><!--~~end~~-->
index 8cbc9e9..2ee09ee 100644 (file)
@@ -9,51 +9,60 @@ if(!file_exists('code/wfpl/template.php')) { die('This form requires <a href="ht
 require_once('code/wfpl/template.php');
 require_once('code/wfpl/format.php');
 require_once('code/wfpl/email.php');
-#require_once('code/wfpl/db.php'); # fixme
 
 function ~form_name~_get_fields() {
-       $GLOBALS['~form_name~_fields'] = array();<!--~formats start~-->
-
-       $value = format_~format~($_REQUEST['~name~']);
-       tem_set('~name~', $value);<!--~db_field start~-->
-       $GLOBALS['~form_name~_fields'][] = $value;<!--~end~--><!--~end~-->
+       $fields = array();
+       <!--~formats start~-->
+       $~name~ = format_~format~($_REQUEST['~name~']);
+       tem_set('~name~', $~name~);
+       <!--~end~-->
+       return array(~php_fields~);
 }
-       
-
-if(isset($_REQUEST['~always_field~'])) {
-       ~form_name~_get_fields();
-
-       if("you're happy with the POSTed values") {
-               #db_insert('~form_name~', '~db_fields~', $GLOBALS['~form_name~_fields']); # fixme
-               if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
-                       $to = $GLOBALS['~form_name~_form_recipient'];
-                       if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
-                               $from = $_REQUEST['email'];
-                               if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
-                                       $from = "$_REQUEST[name] <$from>";
+
+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'];
+                               if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
+                                       $from = $_REQUEST['email'];
+                                       if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
+                                               $from = "$_REQUEST[name] <$from>";
+                                       }
+                               } else {
+                                       $from = $to;
                                }
-                       } else {
-                               $from = $to;
+                               $subject = '~form_name~ form submitted';
+                               $message = tem_run('~form_name~.email.txt');
+                               $cc = '';
+                               $bcc = '';
+                               email($from, $to, $subject, $message, $cc, $bcc);
                        }
-                       $subject = '~form_name~ form submitted';
-                       $message = tem_run('~form_name~.email.txt');
-                       $cc = '';
-                       $bcc = '';
-                       email($from, $to, $subject, $message, $cc, $bcc);
+                       tem_load('~form_name~.html');
+                       tem_sub('thankyou');
+                       tem_output();
+                       exit();
                }
-               tem_load('~form_name~.html');
-               tem_sub('thankyou');
-               tem_output();
-               exit();
+               # otherwise, we display the form again. ~form_name~_get_fields() has
+               # already put the posted values back into the template engine, so they will
+               # show up in the form fields. You should add some message asking people to
+               # fix their entry in whatever way you require.
        }
-       # otherwise, we display the form again. ~form_name~_get_fields() has
-       # already put the posted values back into the template engine, so they will
-       # show up in the form fields. You should add some message asking people to
-       # fix their entry in whatever way you require.
+
+       tem_sub('form');
 }
 
-tem_load('~form_name~.html');
-tem_sub('form');
-tem_output();
+# emulate run.php if it's not being used
+if(!function_exists('run_php')) {
+       tem_load('~form_name~.html');
+       ~form_name~();
+       tem_output();
+}
 
 ?>