looks helpful.  adapting now. thanks.

On Fri, Mar 2, 2012 at 06:32, Wikus van de Merwe <[email protected]
> wrote:

> I think the easiest is to add your validation code in the controller and
> then process
> the data after successful validation. I don't know how your data looks
> like but here
> is a simple example of a controller code with custom validation and db
> insert:
>
> def validate_add(form):
>   pattern = re.compile("[0-9a-z]+")
>   for line in form.vars.data:
>     if not pattern.match(line):
>       form.errors.data = "only alphanumeric characters are accepted"
>
> def add():
>   form = SQLFORM.factory(
>     Field("data", "text", label="names", comment="list of names (1 per
> line)"),
>       submit_button="Add to library")
>
>   if form.process(session=None, onvalidation=validate_add).accepted:
>     for name in form.vars.data.split():
>       id = db.my_table.insert(name=name)
>     redirect(URL("status"))
>
>   return {"form":form}
>

Reply via email to