Arc Forumnew | comments | leaders | submitlogin
Question on using (arg req "x") with defop
2 points by thaddeus 5971 days ago | 5 comments
So I'm having a little trouble.

Here's the code:

    (defop test req
	   (pr (arg req "parm"))
	   (br)
           (if (is (arg req "parm") nil)
	       (= url "test")    
               (= url (string "test?parm=" (arg req "parm"))))
        (do-it url)
    )

    (def do-it (url)      
	 (form url (textarea "stuff" 10 50)
         (br)(submit))
    )
So when I run:

    http://localhost:8080/test?parm=324342
It prints 324342, then runs "do-it" creating the textarea.... which I expect. Upon entering text, clicking submit it re-directs to the correct url, but no longer prints 324342, but rather "nil"....

Any idea on what I am doing wrong?

Thanks, T.



1 point by CatDancer 5971 days ago | link

form expands into

  <form method=post action= ...
So the form is being submitted with a http POST method. With POST, the values are passed in the body of the request, instead of added to the URL using the ?a=1&b=2 syntax. When then POST comes into the Arc server, it pulls the arguments from the request body, ignoring the URL.

What you want is to include a hidden input value in your form:

    (gentag input type 'hidden name 'parm value 324342)
That way you'll get the parm value passed along in the form values.

Your use of "url" as a global variable is a bad idea if two users happened to request "test" at the same time. By the time "(do-it url)" is called, "url" might have been set to the other value by the other invocation of "test".

-----

1 point by thaddeus 5971 days ago | link

I see, thanks.

and... I agree, I just start using globals to start then after I have it working I change 'em (bad habit).

    (defop test req
	   (let parm (arg req "parm")
	   (prn parm)
	   (br)	
           (if (is parm nil)
	       (do-it "test" url parm))   
               (do-it (string "test?parm=" parm) parm)    
    ))

    (def do-it (url parm)  
        (form url (gentag input type 'hidden name 'parm   value parm)
        (textarea "stuff" 10 50)
        (br)(submit))
    )
Works like a charm!

:)

T.

-----

1 point by thaddeus 5971 days ago | link

This could be the same issue I was looking into here...

http://arclanguage.org/item?id=9145

, but isn't this a bug in arc ? this can't be by design, correct ?

T.

-----

1 point by conanite 5971 days ago | link

It might be that the "parm" parameter is not parsed (or not sent by the browser) because it is not defined in the html as an input within the form.

-----

1 point by thaddeus 5971 days ago | link

thank you too.

-----