Here is an application that does that:

https://w2p001.pythonanywhere.com/selection/default/index


*here is the Model (db.py):*

*db = DAL('sqlite://storage.sqlite')*
*
*
*
*
*db.define_table("metals",*
*    Field("choice"),*
*    )*


*here is the Controller (default.py):*

*
*
*def index():*
*    form = FORM(*
*                TABLE(*
*                        TR("Metal Selection: ",INPUT(_type = "text", _name 
= "field1", *
*                                requires = IS_IN_DB(db, 
db.metals.choice))),*
*                        TR("Confirm Metal Selection: ", INPUT(_type = 
"text", _name = "field2", *
*                                requires = [IS_IN_DB(db, 
db.metals.choice), IS_IN_SET([request.vars.field1])])),*
*                        TR("", INPUT(_type = "submit", _value = "Submit")),
*
*                        )*
*                )*
*    choice_rec = db(db.metals.id > 0).select()*
*    options = TABLE()*
*    for x in choice_rec:*
*        options.append(TR(x.choice))*
*    if form.accepts(request.vars,session):*
*        redirect("success")*
*    return dict(form = form, options = options)*
*def success():*
*    home = A("Home",_href = URL(a = "selection", c = "default", f = 
"index"))*
*    return dict(home = home)*



*here are the Views (layout.html, index.html, success.html):*


layout.html:

*<html>*

*    {{include}}*

*</html>*


index.html:

*{{extend 'layout.html'}}*

*<br><br>*

*<center>*

*{{=form}}*

*</center>*

*<br><br>*

*{{=options}}*


success.html:

*{{extend 'layout.html'}}*

*<br><br>*

*<h1>Successful form submission!</h1>*

*<br><br>*

*{{=home}}*



On Saturday, June 15, 2013 7:36:49 PM UTC-5, webpypy wrote:
>
>
>
>
>       I am looking for an example for validating input (using requires = 
>> IS_IN_DB) against form.vars before submit.
>>
>
>       You mean you want to test an html form values to match a set of db 
> values client-side?
>
> I am trying to have a form with three fields,
> the first one needs to to validated against data base (this can be done in 
> the controller by field1.requires = IS_IN_DB(...)) , 
> the second one needs to be validated against data base and the entered 
> value of field1 ( field2.requires = IS_IN_DB(.....form.vars.field1.....))
>
> I am generating the form using SQLFORM.
>
>
>
>
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to