Re: [web2py] Validating form fields manually

2012-09-04 Thread Bruno Rocha
this:

def validate_my_form(form)
if form.vars.channel == "foo":
form.errors.channel = "This channel is not valid"

if form.process(onvalidation=validate_my_form).accepted:
# do whatever here




*Bruno Cezar Rocha** - @rochacbruno*
rochacbr...@gmail.com | Mobile: +55 (11) 99210-8821
www.CursoDePython.com.br | www.rochacbruno.com.br
Blog: Using Python to get all the external links from a
webpage
  Get a signature like this.

Click
here.



On Tue, Sep 4, 2012 at 4:09 PM, Daniel Gonzalez  wrote:

> Something like this:
>
> if form.process().accepted:
> if request.var.channel == 'voicemail': validate requests.var.destination
> as a mail address.
> elif request.var.channel == 'sipaddress' validate requests.var.destination
> as a sip address.
> elfi request.var.channel == 'phone' validate requests.var.destination
> as a telephone number
>
>
> I have two questions:
>

-- 





Re: [web2py] Validating form fields manually

2012-09-13 Thread Mandar Vaze
Hi,

I have two scenario that require manual validation - Adding a new record 
and updating existing record.
Record only has two fields. It is an associative table for many-to-many 
relationship. I need to ensure that this pair is unique (I considered using 
primarykey=['task', 'owner'] - but it has other problems) 

Since the validation is same, i thought I could use the same function for 
both new/update.
The validation works for "new" but doesn't work for update. 
I allow only 'owner' to be modified - 'task' is shown on the form but it is 
read-only.

After some digging I found that, form.vars does not have 'task' -read-only 
field from the form.
Is there a way get the read-only field from "form" object ?

Any other suggestions for ensuring that task/owner pair is unique during 
update ?

-Mandar


On Wednesday, September 5, 2012 12:50:28 AM UTC+5:30, rochacbruno wrote:
>
> this:
>
> def validate_my_form(form)
> if form.vars.channel == "foo":
> form.errors.channel = "This channel is not valid"
>
> if form.process(onvalidation=validate_my_form).accepted:
> # do whatever here
> 
>
>
>
> *Bruno Cezar Rocha** - @rochacbruno*
> rocha...@gmail.com  | Mobile: +55 (11) 99210-8821
> www.CursoDePython.com.br | www.rochacbruno.com.br
> Blog: Using Python to get all the external links from a 
> webpage
>   Get a signature like this. 
> 
>  Click 
> here.
>
>
>
>
> On Tue, Sep 4, 2012 at 4:09 PM, Daniel Gonzalez 
> 
> > wrote:
>
>> Something like this:
>>
>> if form.process().accepted:
>> if request.var.channel == 'voicemail': validate requests.var.destination 
>> as a mail address.
>> elif request.var.channel == 'sipaddress' validate 
>> requests.var.destination 
>> as a sip address.
>> elfi request.var.channel == 'phone' validate requests.var.destination 
>> as a telephone number
>>
>>
>> I have two questions:
>>
>
>
>

-- 





Re: [web2py] Validating form fields manually

2012-09-13 Thread Bruno Rocha
You can read the read-only or hidden fields from the form directly on
request.vars, instead of form.vars use request.vars and it should work.

--