Ahh ok, thanks Anthony. If the form is being processed before adding the 
extra element to the DOM, then is it possible to add an error like 

form.errors.confirm_password = "Must enter correct password"

This would usually cause the error message to appear below the input row, 
but the confirm_password field does not display the error in this case. 
Would I have to manually check for an error and add an error div, or is 
there still a way to use the builtin error messages?

On Friday, September 6, 2013 6:42:40 AM UTC-7, Anthony wrote:
>
> You are adding an element to the form DOM after the form has been 
> processed, so the new field will not get added to form.vars. However, in 
> your onvalidation function, you should be able to replace 
> form.vars.confirm_password with request.vars.confirm_password.
>
> Anthony
>
> On Friday, September 6, 2013 2:17:49 AM UTC-4, Mark Li wrote:
>>
>> Thanks Massimo. However, using 
>> auth.settings.profile_onvalidation.append(reauthenticate_user)
>>
>> has presented a problem of its own.
>>
>> I insert an extra field ("confirm_password"), to recheck in the 
>> onvalidation method. However, the form.vars does not contain 
>> form.vars.confirm_password, which worked before when I was using form.
>> process(onvalidation=reauthenticate_user)
>>
>>
>> Here is the relevant code:
>>
>> auth.settings.profile_onvalidation.append(reauthenticate_user)
>> form=auth.profile()
>> my_extra_element = TR(LABEL('Confirm Password'),INPUT(_type="password",
>> _name="confirm_password", _class="string"))
>> form[0].insert(-1,my_extra_element)
>>
>>
>> def reauthenticate_user(form):
>>     #recheck the user password
>>     plain_password = form.vars.confirm_password
>>     if db.auth_user.password.validate(plain_password) != (db(db.auth_user
>> .id==auth.user.id).select().first().password, None):
>>         form.errors.confirm_password = "Must enter correct password"
>>
>>
>> The form passed into reauthenticate_user does not contain 
>> form.vars.confirm_password variable. Any ideas on why this happens now, but 
>> not before?
>>
>>
>> On Thursday, September 5, 2013 4:46:11 PM UTC-7, Massimo Di Pierro wrote:
>>>
>>> This
>>>
>>> form = auth.profile()
>>> form.process(onvalidation=reauthenticate_user)
>>>
>>> is wrong because auth.profile() already calls process inside. Instead 
>>> you should do:
>>>
>>> auth.settings.profile_onvalidation.append(reauthenticate_user)
>>> form = auth.profile()
>>>
>>> On Thursday, 5 September 2013 17:42:18 UTC-5, Mark Li wrote:
>>>>
>>>> Currently I am creating a form with auth.profile()
>>>>
>>>> I have an onvalidation method to perform some extra checks.
>>>>
>>>> form = auth.profile()
>>>> if form.process(onvalidation=reauthenticate_user).accepted:
>>>>
>>>>     response.flash = "Changes Saved"
>>>> elif form.errors:
>>>>
>>>>     response.flash = "Errors found
>>>>
>>>>
>>>>
>>>> This prevented auth.user object from being updated, which 
>>>> auth.profile() usually takes care of.
>>>>
>>>> I also tried it with the following:
>>>>
>>>> form = auth.profile()
>>>> form.process(onvalidation=reauthenticate_user)
>>>>
>>>>
>>>>
>>>> but the default accepts method that usually updates auth.user doesn't 
>>>> work either
>>>>
>>>> For now, I've just added the following to the accepted method:
>>>> auth.user.update(db.auth_user._filter_fields(form.vars)) 
>>>>
>>>> But I'm interested in knowing if it's possible to specify an 
>>>> onvalidation method for auth.profile(), while still using the built-in 
>>>> accepts method.
>>>>
>>>

-- 

--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to