From f6ad488445b33f4eda0fca1fedcb230e03fd2721 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 15 Sep 2008 17:44:54 -0400 Subject: [PATCH] changed metaform's checkbox to use 0/1 in php and mysql --- encode.php | 12 ++++++++++++ format.php | 10 +++++++++- metaform.php | 4 +++- metaform/template.email.txt | 3 ++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/encode.php b/encode.php index d37d1fa..f93387b 100644 --- a/encode.php +++ b/encode.php @@ -106,6 +106,18 @@ function enc_checked($str) { } } +# checkboxe values are stored in the db and handled in php as 0 or 1. When you +# want it displayed as "Yes" or "No" use this: +# Example: (displaying values from a form submission) Over 60?: ~over_60.yesno~ +function enc_yesno($str) { + if($str && $str !== 'No' && $str !== 'False' && $str !== 'false') { + return 'Yes'; + } else { + return 'No'; + } +} + + # add a tab at the begining of each non-empty line function enc_tab($str) { $lines = explode("\n", $str); diff --git a/format.php b/format.php index f63dfba..de45928 100644 --- a/format.php +++ b/format.php @@ -124,8 +124,16 @@ function format_unix($str) { return unix_newlines($str); } +function format_bool($str) { + if($str && $str !== 'No' && $str !== 'False' && $str !== 'false') { + return 'Yes'; + } else { + return 'No'; + } +} + function format_yesno($str) { - if($str && $str != 'No') { + if($str && $str !== 'No' && $str !== 'False' && $str !== 'false') { return 'Yes'; } else { return 'No'; diff --git a/metaform.php b/metaform.php index ab4b305..f7a5740 100644 --- a/metaform.php +++ b/metaform.php @@ -50,7 +50,7 @@ $GLOBALS['types'] = array( 'pulldown' => array('pulldown', 'options', 'varchar(100)'), 'radio' => array('radio', 'oneline', 'varchar(200)'), 'leftcheck' => array('leftcheck', 'yesno', 'varchar(3)'), - 'checkbox' => array('checkbox', 'yesno', 'varchar(3)'), + 'checkbox' => array('checkbox', 'bool', 'int(1)'), 'yesno' => array('checkbox', 'yesno', 'varchar(3)'), 'delete' => array('checkbox', 'yesno', 'n/a'), 'image' => array('image', 'oneline', 'varchar(200)'), @@ -370,6 +370,8 @@ function make_email() { $tem->set('caption', $name); # fixme if($type == 'textarea') { $tem->show('multi_line'); + } elseif($type == 'checkbox') { + $tem->show('checkbox'); } else { $tem->show('normal'); } diff --git a/metaform/template.email.txt b/metaform/template.email.txt index 0a3f287..c61be5f 100644 --- a/metaform/template.email.txt +++ b/metaform/template.email.txt @@ -1,5 +1,6 @@ ~form_name~ form submitted with the following: -~caption~: ~~~name~~~ +~caption~: ~~~name~~~ +~caption~: ~~~name~.yesno~~ ~caption~: ~~~name~.tab~~ -- 1.7.10.4