Hello Fabio,

I understand what you mean... I will try to be clearer as I give you all
the keys already. But I am not sure if both form are included into the same
page or not... But even then there surely a way to pass vars in your URL.

If both are include in the same page you can't set both 1 and 2 in the same
variable as you just replace one by the other as the line get execute that
why you end with only 1 or 2 in any case... Session vrariable is not the
way to workaround your problem.

If both form are embed into the same page... I will suggest you use the
web2py component... To do so you have to read the doc here :
http://web2py.com/books/default/chapter/29/12/components-and-plugins?search=load#Components--LOAD-and-Ajax

{{=LOAD('controller_name', 'function_name', vars='dict(profile_type=1
or 2)', extention='load', ajax=True)}}


Then you will have to modify the default/user function and add this at the
top :

if request.vars.profile_type == '1':
    db.auth_user.default.profile_type = 1
elif request.vars.profile_type == '2':
    db.auth_user.default.profile_type = 2

Thay way you should end up with discriminated records...

Richard




On Mon, Nov 27, 2017 at 6:02 AM, Fabio Ceccarani <[email protected]>
wrote:

> Hi Richard and thanks for answer.
>
> The real problem is how controller can know wich profile I choose in view.
>
> I want to hide profile_type field in form because I have TWO forms in
> view: one for register as PERSONAL profile, and one for register ad
> ORGANIZATION profile.
>
> But in view I have {{=form}} in any of two form.
> Is the same form=auth() but in case PERSONAL it must write "1" in
> profile_type field, and in case ORGANIZATION it must write "2" in
> profile_type field.
>
> The problem is how to pass "1" or "2" from view to controller?
> is for this reason I try to store it in session.profile_type...but last
> session.profile_type assignment ("2") in view subscribe the first ("1")
> then in controller the variable is always "2".
>
> I can't past args or vars in form submit because it is out of my control
> since it is created by auth()....or maybe yes but I did not find how to do
> it...
>
> Obviously the simplest way is show profile_type and use a single form, but
> it's most nice and easer to understand for users...and I like to complicate
> my life!!
>
> Thanks
> Fabio
>
>
> Il giorno venerdì 24 novembre 2017 16:50:17 UTC+1, Richard ha scritto:
>>
>> If you reuse the user function you can add an if statement :
>>
>> if request.args(1-2-3) or request.vars.somevarname == something
>> particular in your url depending of the context of your form:
>>     db.auth_user.profile_type.default = PROFILE_TYPE_YOU_PREFER
>> elif ...
>>
>> Richard
>>
>> On Fri, Nov 24, 2017 at 10:47 AM, Richard Vézina <[email protected]>
>> wrote:
>>
>>> Does removing writable=False in your extra_fields help? It you set this
>>> to false it means the field is neither readable or writable it you want it
>>> to be include in the form put it to writable=True so form will include the
>>> field... I am not sure what you try to achieve with session variable, but
>>> you may consider using the default or update field attributes to set
>>> "default" profile_type depending of the context of your form...
>>>
>>> You can set this in the controller of you form like so :
>>>
>>> db.auth_user.profile_type.default = PROFILE_TYPE_YOU_PREFER
>>>
>>> default is for create form and update is in context of an record update
>>> obviously...
>>>
>>> Richard
>>>
>>> On Fri, Nov 24, 2017 at 10:09 AM, Fabio Ceccarani <[email protected]>
>>> wrote:
>>>
>>>> Hi all,
>>>> I have a double registration form (one in controller, two in view):
>>>>
>>>>
>>>> IN DB.PY
>>>> auth.settings.extra_fields['auth_user']= [
>>>>    Field('profile_type', readable=False, writable=False, label='Profile
>>>> type', requires=IS_IN_SET({1:'Person',2:'Organization'})),
>>>> ...
>>>> ]
>>>>
>>>>
>>>>
>>>> IN USER.HTML
>>>>
>>>> ...
>>>> <div>
>>>> <h1>profile type1</h1>
>>>> ....
>>>> {{session.profile_type = 1}}
>>>> {{=form}}
>>>>
>>>> </div>
>>>> ...
>>>> <div>
>>>> <h1>profile type2</h1>
>>>> {{session.profile_type = 2}}
>>>> {{=form}}
>>>> </div>
>>>> ...
>>>>
>>>>
>>>>
>>>> IN DEFAULT.PY
>>>>
>>>> def user():
>>>> ...
>>>> return dict(form=auth())
>>>>
>>>>
>>>> How can I write the field auth_user.profile_type = session.profile_type
>>>> from controller?
>>>> I tried in 100 way, but nothing!
>>>>
>>>> Thanks!
>>>> Fabio
>>>>
>>>> --
>>>> Resources:
>>>> - http://web2py.com
>>>> - http://web2py.com/book (Documentation)
>>>> - http://github.com/web2py/web2py (Source code)
>>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>>> ---
>>>> 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/d/optout.
>>>>
>>>
>>>
>> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> 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/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.

Reply via email to