Return to Snippet

Revision: 9850
at November 25, 2008 19:09 by wackysalut

Initial Code

import formencode
from formencode import validators
from formencode import htmlfill

class Valid(formencode.Schema):
    allo = validators.UnicodeString(not_empty=True)
    num = validators.Int()
    num2 = validators.Int(not_empty=True)
    pouet = validators.UnicodeString(not_empty=True)
    gna = validators.String(not_empty=True)

a = """
<form action="pouet" method="post">
  <input type="text" name="pouet" />
  <form:error name="pouet" />

  <input type="password" name="allo" />
  <input type="text" name="num" />
  <form:error name="num"  />

  <input type="text" name="num2" />
  <form:error name="num2"  />

  <textarea name="gna"></textarea>
  <form:iferror name="gna">Horrible horror message</form:iferror>
  <form:error name="gna"  />

  <textarea name="gna2"></textarea>
  <form:iferror name="gna2">Horrible horror message</form:iferror>
  <form:error name="gna2"  />



inp = {'allo': 'salut', 'pouet': 's', 'num': '123', 'num2': "123", 'gna': ''}

ok = None
    ok = Valid.to_python(inp)
except validators.Invalid, e:
    print e.value
    print htmlfill.render(a, {'gna2': 'salutataion'}, e.error_dict or {})

print ok

Initial URL

Initial Description
This simple example tests and shows off a fully working FormEncode (v1.2) example. I've had a hard time finding an example, so I now give it to you.

Initial Title
Full FormEncode + htmlfill example, with form and test values

Initial Tags

Initial Language