This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new ded0e169 Add submit button to forms utility
ded0e169 is described below

commit ded0e1695dae405566e8be66caddac0110b0a0c9
Author: Sebb <[email protected]>
AuthorDate: Wed Feb 1 11:59:19 2023 +0000

    Add submit button to forms utility
    
    Use utility routines where possible
---
 lib/whimsy/asf/forms.rb |  6 ++++++
 www/test/example.cgi    | 17 ++++-------------
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/lib/whimsy/asf/forms.rb b/lib/whimsy/asf/forms.rb
index b702583d..52c27cc2 100644
--- a/lib/whimsy/asf/forms.rb
+++ b/lib/whimsy/asf/forms.rb
@@ -179,6 +179,12 @@ class Wunderbar::HtmlMarkup
     end
   end
 
+  def _whimsy_forms_submit(value: 'submit')
+    _div.col_sm_offset_3.col_sm_9 do
+      _input.btn.btn_default type: 'submit', value: value
+    end
+  end
+
   # Gather POST form data into submission Hash
   # @returns {field: 'string', field2: ['array', 'only for', 'multivalue'] ...}
   def _whimsy_params2formdata(params)
diff --git a/www/test/example.cgi b/www/test/example.cgi
index c1f4ad62..e8c54d0d 100755
--- a/www/test/example.cgi
+++ b/www/test/example.cgi
@@ -35,9 +35,7 @@ talktitle = get_svn_data()
 def emit_form(title, prev_data)
   _whimsy_panel(title, style: 'panel-success') do
     _form.form_horizontal method: 'post' do
-      _div.form_group do
-        _label.col_sm_offset_3.col_sm_9.strong.text_left 'Example Form Section'
-      end
+      _whimsy_forms_subhead(label: 'Example Form Section')
       field = 'text1'
       _whimsy_forms_input(label: 'Example Text Field', name: field, id: field,
         value: prev_data[field], helptext: 'Enter some text, keep it polite!'
@@ -53,9 +51,7 @@ def emit_form(title, prev_data)
       _whimsy_forms_input(label: 'A multi-line Text Field', name: field, id: 
field, rows: 10,
         value: prev_data[field], helptext: 'Pretty boring form example, huh?'
       )
-      _div.col_sm_offset_3.col_sm_9 do
-        _input.btn.btn_default type: 'submit', value: 'PUSH ME!'
-      end
+      _whimsy_forms_submit(value: 'PUSH ME!')
     end
   end
 end
@@ -156,7 +152,7 @@ _html do
       # IF YOUR SCRIPT ONLY EMITS SIMPLE DATA
       _h2 "Simple Data Can Just Use A List"
       _ul do
-        [1,2,3].each do |row|
+        [1, 2, 3].each do |row|
           _li "This is row number #{row}."
         end
       end
@@ -192,12 +188,7 @@ _html do
       # IF YOU WANT TO DISPLAY A FORM and handle the POST
       _div id: 'example-form' do
         if _.post?
-          # Use magic _. callouts to CGI class to gather POST data into 
submission hash
-          submission = {}
-          keyz = _.keys
-          keyz.each do |k|
-            submission[k] = _.params[k] # Always as ['val'] or ['one', 'two', 
...]
-          end
+          submission = _whimsy_params2formdata(params)
           if validate_form(formdata: submission)
             if process_form(formdata: submission)
               _p.lead "Thanks for Submitting This Form!"

Reply via email to