Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Forms dialect

 [1/2] from: al::bri::xtra::co::nz at: 3-Jul-2002 16:12


Hi, everybody! I've been working on a forms dialect for Rebol, that automatically generates HTML code from a basic description of the form. At the moment, I've got the forms generation part working, and I've still got the checking and post/get -ing to work. Here's what I've got so far. (Watch out for broken line!) #! C:\Rebol\View\rebol.exe -cs [ Rebol [ Name: 'Forms Title: "Forms" File: %Forms.r Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Date: 3/July/2002 Purpose: { Forms is a dialect for HTML forms. } ] Forms: function [ Rebol_Forms [block!] Instance [object!] ] [ Block Form_Element Get_Value Label Name Value Size Choices ] [ Block: make block! 1000 Form_Element: func [Label [string!] ML [block!]] [ append Block compose/deep [ label [ span/class "Label" (join Label ": ") (ML) ] ] ] Get_Value: does [ get in Instance to-word Name ] parse Rebol_Forms [ any [ 'Logic set Label string! set Name refinement! ( Form_Element Label compose either Get_Value [ [ input/type/name/checked "checkbox" (to-string Name) checked ] ] [ [ input/type/name "checkbox" (to-string Name) ] ] ) | 'Field set Label string! set Name refinement! set Size integer! ( Form_Element Label compose [ input/type/name/size/value "text" (to-string Name) (Size) (any [Get_Value ""]) ] ) | 'Secret set Label string! set Name refinement! set Size integer! ( Form_Element Label compose [ input/type/name/size "password" (to-string Name) (Size) ] ) | 'Area set Label string! set Name refinement! set Size pair! ( Form_Element Label compose [ textarea/name/wrap/cols/rows (to-string Name) "virtual" (Size/X) (Size/Y) (any [Get_Value ""]) ] ) | 'SelectOne set Label string! set Name refinement! set Choices block! ( Form_Element Label compose/deep [ select/name (to-string Name) [ ( use [Block Selected] [ Selected: Get_Value Block: make block! 20 foreach [Value Label] Choices [ append Block compose either Value Selected [ [option/value/selected (Value) selected (Label)] ] [ [option/value (Value) (Label)] ] ] ] ) ] ] ) | 'Output set Label string! set Name refinement! ( Form_Element Label compose [(any [Get_Value ""])] ) | 'Submit set Label string! ( Form_Element Label compose [ input/type/name "submit" (Label) ] ) | 'Date set Label string! set Name refinement! ( use [Date Block] [ Date: any [Get_Value now] Form_Element Label compose/deep [ select/name (join to-string Name "/Day") [ ( Block: make block! 31 * 3 + 1 repeat Day 31 [ append Block compose either Day Date/Day [ [option/value/selected (Day) selected (Day)] ] [ [option/value (Day) (Day)] ] ] ) ] select/name (join to-string Name "/Month") [ ( Block: make block! 12 * 3 + 1 repeat Month 12 [ append Block compose either Month Date/Month [ [ option/value/selected (Month) selected (pick system/locale/months Month) ] ] [ [ option/value (Month) (pick system/locale/months Month) ] ] ] ) ] select/name (join to-string Name "/Year") [ ( Block: make block! 100 * 3 * 2 + 4 for Year -100 + Date/Year 100 + Date/Year 1 [ append Block compose either Year Date/Year [ [option/value/selected (Year) selected (Year)] ] [ [option/value (Year) (Year)] ] ] ) ] ] ] ) ] end ] Block ] X: Forms [ Logic "Truth?" /Truth Logic "Falsey?" /Falsey Field "Line" /Line 10 Secret "Password" /Password 10 Area "Paragraphs" /Paragraphs 40x4 SelectOne "Gender" /Gender [ #"F" "Female" #"M" "Male" ] SelectOne "Relationship" /Relationship [ #"F" "Father" #"G" "Guardian" #"M" "Mother" ] SelectOne "Invoices" /Invoices? [ #"N" "No" #"Y" "Yes" ] Date "Birth" /DoB Output "Age" /Age Output "Total" /Total Submit "Enter" ] make object! [ Truth: true Falsey: false Line: "string!" Password: none Paragraphs: trim {A long line of text, that is several lines long. It has several lines indeed! And here's another!} Gender: #"F" Relationship: #"M" Invoices?: #"Y" DoB: 25/10/1960 Age: has [YMD] [ YMD: system/words/Age now DoB rejoin [ YMD/1 "y " YMD/2 "m " YMD/3 "d approximately." ] ] Total: $123.45 ] content-type text/html print ML compose/deep [ ?xml/version/encoding "1.0" "UTF-8" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11-frameset.dtd"> html [ title "Test" link/rel/type/href "stylesheet" "text/css" %/Pupils.css ] body [ form/method "GET" [ (X) ] ] ] ] I'm still working on the dialect and what it can handle. Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [2/2] from: oliva:david:seznam:cz at: 3-Jul-2002 23:42


Hello Andrew, Wednesday, July 3, 2002, 6:12:31 AM, you wrote: AM> Hi, everybody! AM> I've been working on a forms dialect for Rebol, that automatically generates AM> HTML code from a basic description of the form. At the moment, I've got the hmm... I was thinkeng about form dialect two days ago, will have to look at this one:-) thanks andrew for posting it Oldes