From f6fdd9deec6c7815f5877270e746e1bd1201a726 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Sat, 28 Mar 2015 16:38:53 -0400 Subject: [PATCH] metaform: new syntax for options, fix radio --- metaform.php | 27 ++++++++++++++++++++++++++- metaform/main.html | 10 ++++++++-- metaform/template.html | 6 +++--- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/metaform.php b/metaform.php index bf90466..a0dce78 100644 --- a/metaform.php +++ b/metaform.php @@ -175,13 +175,24 @@ function get_fields() { $fields_str = rtrim($fields_str); $fields = split("\n", $fields_str); foreach($fields as $field) { + $first_char = substr($field, 0, 1); $field = trim($field); + if ($first_char === ' ' || $first_char === "\t") { + $i = count($GLOBALS['gotten_fields']); + if($i > 0) { + $i -= 1; + if (!$GLOBALS['gotten_fields'][$i]['options']) { + $GLOBALS['gotten_fields'][$i]['options'] = array(); + } + $GLOBALS['gotten_fields'][$i]['options'][] = $field; + continue; + } + } if(substr($field, -1) == '{') { $caption = trim(substr($field, 0, -1)); $name = format_varname($caption); $type = '{'; $options = null; - # FIXME restore parsing of option lists for pulldowns } else { $options = null; $type = null; @@ -317,6 +328,20 @@ function make_html($whole_file = true) { 'caption' => $field['caption'] ) ); + if($field['type'] == 'radio') { + $i = 0; + $opts = array(); + foreach ($field['options'] as $row) { + if (is_array($row)) { + $cap = $row[1]; + } else { + $cap = $row; + } + $opts[] = array('i' => $i, 'option_caption' => $cap); + $i += 1; + } + $visible_fields[count($visible_fields) - 1]['options'] = $opts; + } } if($field['input'] == 'image' || $field['input'] == 'file') { diff --git a/metaform/main.html b/metaform/main.html index 0103f65..6454440 100644 --- a/metaform/main.html +++ b/metaform/main.html @@ -39,12 +39,18 @@

You can start a labeled fieldset by putting a { at the end of a line with the caption. Then end the fieldset with a } on a line by itself

+

Pulldown/radio options can be specified (one per line) indented below the field

+

Example:

 email
 contact info (all required) {
-  name
-  phone
+name
+phone
 }
+pulldown color
+	Red
+	Blue
+	Black
 textarea comments
 yesno agree
 

diff --git a/metaform/template.html b/metaform/template.html index 1aa7759..5121acc 100644 --- a/metaform/template.html +++ b/metaform/template.html @@ -111,9 +111,9 @@
~caption html~
- ~~~name~ radio_caption_0 html~~
- ~~~name~ radio_caption_1 html~~
- ~~~name~ radio_caption_2 html~~ + + ~option_caption html~
+
-- 1.7.10.4