[REBOL] Re: I am Master of Overcomplification.. Can this be simplified?
From: Izkata::Comcast::net at: 10-Jan-2005 6:13
Note the "do rejoin" lines - I hate using that. But it's all I could think
of when I wrote this.
Also, last night while trying to sleep, I thuoght up a far better way to do
this - so please
-don't bother even messing around until I test it out- - I want to send this
before I forget
just in case the idea doesn't work and I woulda needed to send it later - I
guaruntee I'd
forget.
Here's a test form I was using: (Note: I am not even bothering with
type=reset)
<FORM action="Levels2.html" method="Post">
<P>
Experience for Level: <INPUT type="text" name="Level"><BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</P>
</FORM>
Here's the lines that MakeForm adds to the layout:
F1P1: field ""
button "Send" [LoadPage/post (to-url "Levels2.html") ( to-string compose
load to-block rejoin Form1)]
And what Form1 ends up looking like (when 'mold is used)
["Level=" "(F1P1/text)"]
MakeForm: func [
FormTag [tag!]
Page
][
Tag: mold FormTag
parse (mold Page/1) [
thru {action=} copy ToPage to { }
thru {method=} copy Method to {>}
]
while [string? (Load ToPage)][ToPage: load ToPage]
while [string? (Load Method)][Method: load Method]
FormCount: FormCount + 1
FormPart: 0
append Forms rejoin [{Form} FormCount]
do rejoin [{Form} FormCount {: copy []}] ;this would create the block
Form1, as I used in my last example
while [true][
Page: next Page
if find Page/1 {INPUT} [
parse (mold Page/1) [
thru {type=} copy Type to { } ;this'll find whether it's
a field, checkbox, or other
thru {name=} copy Name to {>}
]
while [string? (Load Type)][Type: load Type]
while [string? (Load Name)][Name: load Name]
FormPart: FormPart + 1
if (Type = "text") [
if (FormPart > 1) [do rejoin [{append Form} FormCount { "&"}]]
;add an "&" if it's not the first item in the form
do rejoin [{append Form} FormCount { "} Name {="}]
;now add the "Something=" part..
do rejoin [{append Form} FormCount { "(F} FormCount {P} FormPart
{/text)"}] ;and add the Rebol script that makes it work
write/append %TMP.txt rejoin [newline { F} FormCount {P}
FormPart {: field ""}]
]
if (Type = "checkbox") [
if (FormPart > 1) [do rejoin [{append Form} FormCount { "&"}]]
;same comments as in "Type="text""
do rejoin [{append Form} FormCount { "} Name {="}]
do rejoin [{append Form} FormCount { "(F} FormCount {P} FormPart
{/text)"}]
write/append %TMP.txt rejoin [newline { F} FormCount {P}
FormPart {: check-mark ""}]
]
]
if Page/1 = </form> [break] ;If it found the end form tag, get out of
the loop because it's done
]
if (Method = "Post") [
write/append %TMP.txt rejoin [
newline { button "Send" [LoadPage/post (to-url "} ToPage {") (
to-string compose load to-block rejoin } rejoin [{Form} FormCount] {)]}
;Add "Send" button
newline {;} mold Form1 ;I added this line to test it and see what
was happening. This is what gave me the idea last night.
]
]
if (Method = "Get") [
write/append %TMP.txt rejoin [
newline { button "Send" [LoadPage/get (to-url "} ToPage {") (
to-string compose load to-block rejoin } mold do rejoin [{? Form} FormCount]
{)]} ;Sedd "Send" button
newline {;} mold Form1 ;I added this line to test it and see what
was happening. This is what gave me the idea last night.
]
]
]