No, the code should look like this:
 
def create_fvte():
    table = request.args(0)
    crud.settings.formstyle='divs'
    form = crud.create(db[table])
    form.update(_class='no_trap', 
_action=URL('default','create_fvte.html',args=request.args))
    if form.accepts(request.vars, session):
        session.flash = T('form accepted')
        if table == 'ref_fnaregistry':
            redirect(URL(request.application,c='default',f='index'))
        elif table == 'ref_vregistry':
            redirect(URL(request.application,c='default', 
f='creation',args=2))
        elif table == 'ref_tregistry':
            redirect(URL(request.application,c='default', 
f='creation',args=3))
    elif form.errors:
        response.flash = T('form has errors')
    return dict(form=form)
 
The above works fine for me, but there's still one problem -- if the form 
has errors, it isn't able to re-display the form with error messages 
(because it submits to create_fvte, which loads at the top level instead of 
within the creation page). We might be able to handle that by putting things 
in the session, but that's starting to get a bit too complicated. So 
instead, let's try redirecting from the client side via javascript. Try 
this:
 
def create_fvte():
    table = request.args(0)
    crud.settings.formstyle='divs'
    form = crud.create(db[table])
    if form.accepts(request.vars, session):
        if table == 'ref_fnaregistry':
            next = URL('default', 'index', extension=False, host=True)
        elif table == 'ref_vregistry':
            next = URL('default', 'creation', args=2, extension=False, 
host=True)
        elif table == 'ref_tregistry':
            next = URL('default', 'creation', args=3, extension=False, 
host=True)
        session.flash = T('form accepted')
        response.js = 'window.location.replace("%s")' % next
    elif form.errors:
        response.flash = T('form has errors')
    return dict(form=form)
 
 
Instead of redirecting on the server side, the above sends a javascript 
command back to the client that redirects to the appropriate URL. In this 
case, because the redirect happens on the client side after the returned 
page loads, you will briefly see the original page with a blank form before 
the redirect happens.
 
Anthony
 

On Thursday, June 30, 2011 8:32:01 AM UTC-4, Richard wrote:

> Still nop! 
>
> I also try to put it in the if table == like this :
>
>          if table == 'ref_fnaregistry':
>             #redirect(URL(request.application,c='default',f='index.html'))
>             form.update(_class='no_trap', 
> _action=URL('default','creation.html'),args=1)
>             return dict(form=form)
>             #URL(request.application,c='default', f='creation.html',args=1)
>
> I don't think changing the action for 'create_fvte.html' is logic... I mean 
> my create_fvte is a component function and it serves to load all the 2 
> components ref_fnaregistry and ref_vregistry...
>
> Maybe I should drop this function and create 2 functions one for each 
> component or form...
>
> Anyway using your line of code directly give a empty page theres is no 
> shell for the component I mean no Tabs plugin and no code at all in the 
> create_fvte.hml view...
>
> Richard
>
> On Wed, Jun 29, 2011 at 11:38 PM, Anthony <abas...@gmail.com> wrote:
>
>> OK, I forgot the underscore before 'action' (I also forgot to include 
>> request.args in the form action URL) -- I think this should do it:
>>  
>> form.update(_class='no_trap', 
>> _action=URL('default','create_fvte.html',args=request.args))
>>  
>>  
>> Note, adding the .html extension to create_fvte above ensures that when 
>> the form is submitted back to this function, the extension will be .html, 
>> which is the extension that will be passed to the redirects.
>>  
>> Also, you should remove the following from create_fvte:
>>  
>> else:
>>     response.flash = T('please fill out the form')
>>  
>>  
>> The problem with that is that when you redirect to the /creation URL, it 
>> reloads your components, and the response.flash from the components 
>> overrides the session.flash that was passed to the /creation page. Instead, 
>> put the following in the creation() function:
>>  
>> if not request.args:
>>     response.flash = T('please fill out the form')
>>  
>>  
>> That will flash 'please fill out the form' when the /creation page is 
>> loaded without any arguments, but not otherwise.
>>  
>> With those small changes, I believe it all works as you want now.
>>  
>> Anthony
>>   
>>
>> On Wednesday, June 29, 2011 9:57:09 PM UTC-4, Richard wrote:
>>
>>> It clear validator if they trigger and don't know why the redirection 
>>> don't works neither... 
>>>
>>> Maybe pbreit is right and I should just forget about redirection... It's 
>>> probably what I will do for now, cause I can't spend any longer on this 
>>> picky stuff for now. It's part of the 20% percent stuff...
>>>
>>> Thanks anyway, I really appreciate your help.
>>>
>>> ;-)
>>>
>>> Richard 
>>>
>>>
>>> On Wed, Jun 29, 2011 at 6:54 PM, Anthony <aba...@gmail.com> wrote:
>>>
>>>> Sorry, the **dict() isn't really needed -- you can just do:
>>>>  
>>>> form.element('form').update(**_**class='no_trap', 
>>>> action=URL('default','create_**f**vte'))
>>>>  
>>>>  
>>>> Actually, in the URL() call above, you might be better off doing 
>>>> 'create_fvte.html' to ensure it doesn't use the .load extension, which 
>>>> would 
>>>> then propagate to the redirect (unless you explicitly specify .hmtl in the 
>>>> redirect).
>>>>  
>>>> Anthony
>>>>   
>>>> On Wednesday, June 29, 2011 6:02:42 PM UTC-4, Anthony wrote:
>>>>
>>>>> Try this:
>>>>>  
>>>>>     form = crud.create(db[table])
>>>>>     form.element('form').update(******dict(_class='no_trap', 
>>>>> action=URL('default','create_**f**vte')))
>>>>>  
>>>>>  
>>>>> The _class='no_trap' should turn off the trapping of the form, and the 
>>>>> action=URL('default','create_**f**vte') should ensure that the 
>>>>> untrapped form gets submitted back to the create_fvte function rather 
>>>>> than 
>>>>> the parent page (i.e., the index function). Because the form will not be 
>>>>> submitted via ajax, the redirect should work as usual and reload the 
>>>>> entire 
>>>>> page.
>>>>>  
>>>>> Anthony
>>>>>
>>>>
>>>
>

Reply via email to