mmontone / cl-forms

Web forms handling library for Common lisp
http://mmontone.github.io/cl-forms
MIT License
43 stars 5 forks source link

[Help] djula howto #1

Closed rnfn closed 5 years ago

rnfn commented 5 years ago

How to use cl-form with djula? i've tried to understand it from djula test file, but i get

{# Error: Unknown tag FORM #} {# Error: Unknown tag FORM-START #} {# Error: Unknown tag FORM-ROW #} {# Error: Unknown tag FORM-ROW #} {# Error: Unknown tag FORM-ROW #} {# Error: Unknown tag FORM-ROW #} {# Error: Unknown tag FORM-END #}

Thank you.

mmontone commented 5 years ago

Have you loaded :cl-forms.djula ?

rnfn commented 5 years ago

Have you loaded :cl-forms.djula ?

Sorry, I have not ~_~ But, after I have load :cl-forms.djula now i get another error:

{# Error: There was an error rendering the token (TAG FORM-ROW FORM USERNAME) : Field USERNAME not found in #<FORM LOGIN-FORM /login {1003DDD303}> #}.

this is the template:

`{% form form %}

{% form-start form %} {% form-row form username %} {% form-row form password %} {% form-row form submit %} {% form-end form %}`

this is the test file:

`(defparameter +test-form+ (djula:compile-template* (asdf:system-relative-pathname :cl-microblog "templates/testform.html")))

(forms:defform login-form (:action "/login" ) ((username :string :value "") (password :password :value "") (submit :submit :label "Sign In")))

(defroute "/testform" () (let ((form (forms::get-form 'login-form))) (djula:render-template* +test-form+ nil :form form)))`

I'm sure I have missing something obvious here.

mmontone commented 5 years ago

What you are doing looks correct. Give me some time to check.

mmontone commented 5 years ago

Can you try adding {% set-package :cl-microblog %} at the top of your testform.html template? (or set the package in which the form is defined, instead of :cl-microblog)

mmontone commented 5 years ago

Explanation:

The field symbol is looked for in the *djula-execute-package*. If that's not set correctly, the form field won't be found. This is how the field is extracted from the template and the form:

(let ((field-symbol (intern (string-upcase field-name) *djula-execute-package*)))
        (let ((field (forms::get-field form field-symbol)))
...

Perhaps I should relax that, and implement being able to find form fields by string, instead of symbol. But try that for now...

rnfn commented 5 years ago

Can you try adding {% set-package :cl-microblog %} at the top of your testform.html template? (or set the package in which the form is defined, instead of :cl-microblog)

Thank you, that fix it.

But, now I'm having trouble with handle-request, I"m using Caveman, and this is the handler:

(defroute ("/testform" :method :post) () (let ((form (forms:get-form 'login-form))) (forms::handle-request form) (forms::validate-form form) ...... ))

forms::handle-request form generate this error:

`The value

<FLEXI-STREAMS:FLEXI-IO-STREAM {1003D85663}>

is not of type SEQUENCE [Condition of type TYPE-ERROR]

Restarts: 0: [ABORT] abort thread (#<THREAD "hunchentoot-worker-127.0.0.1:35444" RUNNING {1003BBF8A3}>)

Backtrace: 0: (LENGTH #<FLEXI-STREAMS:FLEXI-IO-STREAM {1003D85663}>) 1: (CL-PPCRE:SPLIT #<CLOSURE (LAMBDA (STRING CL-PPCRE::START CL-PPCRE::END) :IN CL-PPCRE::CREATE-SCANNER-AUX) {10079E7C8B}> #<FLEXI-STREAMS:FLEXI-IO-STREAM {1003D85663}> :START 0 :END #<unavailable argum.. 2: (HUNCHENTOOT::MAYBE-READ-POST-PARAMETERS :REQUEST #<HUNCHENTOOT:REQUEST {1003D81E13}> :FORCE T :EXTERNAL-FORMAT NIL) .....`

I'm sorry if i keep on bothering you, thank you for your help.

mmontone commented 5 years ago

Hi. I don't have access to a computer now. But I implemented cl forms on hanchentoot. No explicit caveman support

El 29 de agosto de 2019 2:16:59 GMT-03:00, RNFN notifications@github.com escribió:

Can you try adding {% set-package :cl-microblog %} at the top of your testform.html template? (or set the package in which the form is defined, instead of :cl-microblog)

Thank you, that fix it.

But, now I'm having trouble with handle-request, I"m using Caveman, and this is the handler:

(defroute ("/testform" :method :post) () (let ((form (forms:get-form 'login-form))) (forms::handle-request form) (forms::validate-form form) ...... ))

forms::handle-request form generate this error:

`The value

<FLEXI-STREAMS:FLEXI-IO-STREAM {1003D85663}>

is not of type SEQUENCE [Condition of type TYPE-ERROR]

Restarts: 0: [ABORT] abort thread (#<THREAD "hunchentoot-worker-127.0.0.1:35444" RUNNING {1003BBF8A3}>)

Backtrace: 0: (LENGTH #<FLEXI-STREAMS:FLEXI-IO-STREAM {1003D85663}>) 1: (CL-PPCRE:SPLIT #<CLOSURE (LAMBDA (STRING CL-PPCRE::START CL-PPCRE::END) :IN CL-PPCRE::CREATE-SCANNER-AUX) {10079E7C8B}>

<FLEXI-STREAMS:FLEXI-IO-STREAM {1003D85663}> :START 0 :END

<unavailable argum..

2: (HUNCHENTOOT::MAYBE-READ-POST-PARAMETERS :REQUEST

<HUNCHENTOOT:REQUEST {1003D81E13}> :FORCE T :EXTERNAL-FORMAT NIL)

.....`

I'm sorry if i keep on bothering you, thank you for your help.

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/mmontone/cl-forms/issues/1#issuecomment-526026417

rnfn commented 5 years ago

Ok, thank you for your help. I'll try to dig deeper.