Form framework

62 views
Skip to first unread message

Charlie

unread,
Jun 3, 2010, 6:05:35 AM6/3/10
to Express
Can anyone recommend a good form framework or library for easily
creating and validating forms with node and express?

Aaron Heckmann

unread,
Jun 3, 2010, 10:45:32 AM6/3/10
to expre...@googlegroups.com
I've been creating simple classes for these types of things. For example, to create/edit a Person...

In my views:

%form{ action: "/person/new", method: "post" }
  %input{ name: "person[name]", value: person.name }
  %input{ name: "person[age]", value: person.age }

Routes:

get("/person/new", function(){
  this.render("person.html.haml", {
    locals: { person: new Person() }
  })
})
post("/person/new", function(){
  var person = new Person(this.param('person'))
  if (!person.valid())
    return this.render("person.html.haml", {
      locals: { person: person }
    })
  person.save() ...... etc
})

I create an instance of Person passing in the person object from the form. My Person class has validation and error message methods built in. If there were errors from failed validation you could get them with person.errors('age') etc.

Simple and works for me.



On Thu, Jun 3, 2010 at 6:05 AM, Charlie <cha...@powmedia.co.uk> wrote:
Can anyone recommend a good form framework or library for easily
creating and validating forms with node and express?

--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.




--
Aaron
http://clickdummy.net
Reply all
Reply to author
Forward
0 new messages