[Bese-devel] TAL und yaclml (Form actions and javascript)

ran at setq.net ran at setq.net
Tue Jul 26 17:58:49 UTC 2005


Greetings,

Friedrich Dominicus wrote:
> Now if I use a ucw:button I will be left with JavaScript. This is not
[...]

It seems that <button> and <input type="button"> do not cause form submission,
and really are to be used with javascript, but your sample uses a submit button.

Here is a way to have form actions without javascript, by patching <ucw:input
and adding a new function (setf get-parameter) to whatever backend you are using.

It works by setting the action parameter, ("a"), to what it would be set to by javascript,
in a callback for the parameter of the input tag's name attribute.
This means that you can not use the :name attribute with <ucw:input

I would write your form like this:
(<ucw:form
 (<:p (<ucw:input :type "submit" :value "Yes" :action (call 'shop-login :message "You...")
      (<ucw:input :type "submit" :value "No" :action (call 'info-message :message "Not...")))

I guess this is what you would already be doing if you liked javascript.

Below is the patch and (setf get-parameter) methods for araneida and mod-lisp/httpd
Wash hands thoroughly after applying.
It might be cleaner if the action could be selected through means other than
the "a" parameter.
for example allowing callbacks to select the action, like:
(make-new-callback (context.current-frame *context*)
  (lambda (value)
    (push action (context.requested-actions *context*)))

Ryan

;; Sorry, no patches for (setf get-parameter)
;; araneida: src/backend/araneida.lisp
;; WARNING: this will only set a POST parameter
(defmethod (setf get-parameter) (value (request araneida-request) parameter-name)
  (let ((cons (assoc parameter-name (araneida:request-body (request request)) :test #'string-equal)))
    (when cons (setf (cadr cons) value))))

;; httpd/mod-lisp: src/backend/httpd.lisp
(defmethod (setf get-parameter) (value (request httpd-request) name)
  (let ((cons (assoc name (parameters request) :test #'string=)))
    (when cons (setf (cdr cons) (copy-seq value)))))

diff -ur /src/marco/ucw/src/yaclml/ucw-tags.lisp ./src/yaclml/ucw-tags.lisp
--- /src/marco/ucw/src/yaclml/ucw-tags.lisp	2005-07-20 15:06:49.000000000 +0900
+++ ./src/yaclml/ucw-tags.lisp	2005-07-27 01:12:52.000000000 +0900
@@ -31,7 +31,7 @@
 ;;;; *** Form tags
 
 (deftag-macro <ucw:button (&attribute action &allow-other-attributes others &body body)
-  "Presents an butten tag which executes ACTION when clicked."
+  "Presents a button tag which executes ACTION when clicked."
   (unless action
     (error "Must specify :ACTION attribute in button tags (or use a simple <:button tag)"))  
   `(<:button :onclick (concatenate 'string
@@ -149,13 +149,22 @@
 			 `(:checked ,value))
 		     , at others)))))
     (action
-     `(<:input , at others
-               :onclick (concatenate 'string
-                                     "javascript: "
-                                     "this.form." +action-parameter-name+ ".value ='"
-                                     (make-new-action (context.current-frame *context*)
-                                                      (lambda () ,action)) "';"
-                                     "return true;")))
+     `(let ((action (make-new-action (context.current-frame *context*)
+				      (lambda () ,action))))
+	 (<:input , at others
+		  :name (make-new-callback (context.current-frame *context*)
+					   (lambda (value)
+					     (declare (ignore value))
+					     (setf (get-parameter
+						    (context.request *context*)
+						    +action-parameter-name+)
+						   action)))
+		  :onclick (concatenate 'string
+					"javascript: "
+					"this.form." +action-parameter-name+ ".value ='"
+					action
+					"';"
+					"return true;"))))
     (t
      (error "Must specify either :ACTION or :ACCESSOR (or use a regular <:input tag.)"))))
 



More information about the bese-devel mailing list