Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form generator #1

Open
fukamachi opened this issue Apr 22, 2011 · 4 comments
Open

Form generator #1

fukamachi opened this issue Apr 22, 2011 · 4 comments

Comments

@fukamachi
Copy link
Owner

No description provided.

@m2ym
Copy link
Collaborator

m2ym commented Apr 25, 2011

A famous form generator on Rails:

https://github.com/justinfrench/formtastic

@sfsekaran
Copy link

I like simpleform, in addition to formtastic.

https://github.com/plataformatec/simple_form

@libre-man
Copy link

What is an acceptable way to implement this? I don't think we can achieve the same way of integration as those rails plugins can. Because the templating system less integrated with the framework as is the ORM.

An example of how you would create forms using ruby

In ruby you have the form_for method that creates a form. You use this method within a view, this view is coupled to a Controller and to a method of a controller. So app/views/users/new.html.rb is coupled to UsersController#new.

This form_for method takes at least one arguments, a record. So in our example form_for(@user) would use the @user instance variable of UsersController after calling UsersController#new. It now checks if this user exists using the #persisted? method. After all this it creates the form with a optional input field for key method which is set to patch. If this form is uploaded it is routed to the correct method once again using the action table. Now we can simple use the model class to create a new user (with filtered params of course). If this failed we can simply render new again.

Because the ORM is embedded in rails the creation will only fail if certain 'model validations' failed. These also fill the error hash-table for the user with Error objects. These validations also contain an error message (by default of specified) and these are shown to the user if wanted.

So in conclusion: this is very hard with caveman. Caveman is not tightly integrated with an ORM or templating engine. The ORM it has does do any form of validations, so easy creation of objects using a form generator is hard. Also caveman does not force the use of controllers, so generating a form and using this on many webpages is also harder, as we don't know what fields to add because we don't know with what kind of class/struct/model we are working. And finally how should we pass the forms to the templates? Using variables will be very slow if a website has many forms (all forms have to be generated for each request), and other ways (custom djula tags) will mean that using other templating engines will become harder.

I think to only way to have a nice form generator is to chose a real ORM and a default templating engine and become more opinionated about how applications should be formed and routed. However this would probably break compatibility, so doing this for caveman2 would be impossible.

@vindarel
Copy link
Sponsor Contributor

Linking to some CL web form validators that I didn't find easily:

Automatically validating formlets for Hunchentoot + cl-who

Although it is potentially framework agnostic, it runs on top of Hunchentoot at the moment.

It can be used with various Common Lisp web servers and web frameworks such as caveman2. 1forms uses CLOS and is extensible by design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants