Hello,

The solution explained here is based on specific schemas and layouts to 
generate the join form. I'm sure there can be an easier (but not so flexible) 
solution. This is the way I took:

1.- Add the fields and widgets to portal_schemas->members and 
portal_layouts->members respectively.
2.- Create a new layout and a new schema both called "members_join" based on a 
copy of their respective "members". Remove those fields and widgets that you 
don't want to show in the registration form.
3.- Modify the form tag of join_form.pt to look like this:

{{{
    <form action="register" method="post" tal:attributes="action 
string:${here/portal_url}/register">
      <tal:block define="res res|here/renderJoinForm"
                   content="structure res/rendered_form" />
      <p class="buttonArea">
        <input type="hidden" name="last_visit:date" value=""
               tal:attributes="value here/ZopeTime" />
        <input type="hidden" name="prev_visit:date" value=""
               tal:attributes="value here/ZopeTime" />
        <input i18n:attributes="value" class="standalone"
               type="submit" name="submit" value="button_register" />
      </p>
    </form>
}}}
4.- renderJoinForm.py will render the new layouts and schemas in edit mode and 
should look like this:
{{{
## Script (Python) "renderJoinForm"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=REQUEST=None
##title=
res = {'rendered_form': '',
       'status': '',
       'psm': '',
       'valid_form': 0,
       }

# manage form action
if REQUEST is not None:
    form = REQUEST.form
    if form.has_key('submit'):
        mapping = form
    else:
        mapping = None
else:
    mapping = None
    
ob = {}

ltool = context.portal_layouts
(res['rendered_form'], res['status'], ds) = ltool.renderLayout(
    layout_id='members_join', schema_id='members', layout_mode='edit',
    context=context, mapping=mapping, ob=ob)

if mapping is not None:
    # search
    if res['status'] == 'valid':        
        res['valid_form'] = 1
    else:
        res['psm'] = 'psm_content_error'
        #raise '%s invalid ' % res['status'] + str(ds.getErrors())        
##      raise "Items_per_page attribute found.", "%" % res['items_per_page']

return res
}}}

5.- Modify the register.py script to look like this, where we do the render of 
the form and a mapping of "widget__xxxx" to "xxxx":
{{{
## Script (Python) "register"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=widget__password='password', widget__confirm='confirm'
##title=
##
"""
 $Id$
"""

# FIXME AT: to refactor, this script is prehistoric and buggy
# - REQUEST must be clearly set as script parameter, required or not
# - ever heard of layouts and widgets to control data validity?

from re import match
from AccessControl import Unauthorized
from Products.CMFCore.utils import getToolByName

request = context.REQUEST
portal_registration = getToolByName(context, 'portal_registration')

if not portal_registration.enable_portal_joining:
    raise Unauthorized("Joining has been disabled at the portal level")

# Map widget values to a dicctionary. This will let us access 
# values without using 'widget__' prefix.
res = {'rendered_form': '',
       'status': '',
       'psm': '',
       'valid_form': 0,
       }
       
if request is not None:
    form = request.form
    if form.has_key('submit'):
        mapping = form
    else:
        mapping = None
else:
    mapping = None
    
props = {}

ltool = context.portal_layouts
(res['rendered_form'], res['status'], ds) = ltool.renderLayout(
    layout_id='members_join', schema_id='members', layout_mode='edit',
    context=context, mapping=mapping, ob=props)

props['username'] = props['id']
props['password'] = widget__password
props['confirm'] = widget__confirm
password = props['password']
confirm = props['confirm']
# Fields identifiers with and without 'widget__' prefix are now available in 
request.form.
request.form.update(props)

# converts CMFDefault/RegistrationTool.py sentences into msgids
conversion = {
    'Your password must contain at least 5 characters.':
        'psm_join_password_too_short',
    'Your password and confirmation did not match. Please try again.':
        'psm_join_password_mismatch',
    'You must enter a valid name.':
        'psm_join_invalid_name',
    'The login name you selected is already '
        'in use or is not valid. Please choose another.':
            'psm_join_login_already_used',
    'You must enter a valid email address.':
        'psm_join_invalid_email',
}

# Does the corresponding homeFolder exists ? If it does the given login cannot
# be used because it could be used to access someone else's home folder.
allowed = portal_registration.isMemberIdAllowed(props['username'])
if not allowed:
    failMessage = 'psm_join_login_already_used'
    if failMessage and request is not None:
        request.set('portal_status_message',
                    conversion.get(failMessage, failMessage))
        return context.join_form(context, request)

# password checking
if not portal_registration.validate_email:
    failMessage = portal_registration.testPasswordValidity(password, confirm)
    if failMessage and request is not None:
        request.set('portal_status_message',
                    conversion.get(failMessage, failMessage))
        return context.join_form(context, request)

# other fields checking
failMessage = portal_registration.testPropertiesValidity(request)
if failMessage:
    request.set('portal_status_message',
                conversion.get(failMessage, failMessage))
    return context.join_form(context, request)

# email validity checking
email = props['email']
if not match(r'^(\w(\.|\-)?)+@(\w(\.|\-)?)+\.[A-Za-z]{2,4}$', email):
    request.set('portal_status_message', 'psm_join_invalid_email')
    return context.join_form(context, request)

# now adds the member
password = request.get('widget__password') or 
portal_registration.generatePassword()
username = request['widget__username']
password = props['password']
username = props['username']

try:
    portal_registration.addMember(username, password, properties=request.form)
except ValueError:
    request.set('portal_status_message',
                conversion.get(failMessage, failMessage))
    return context.join_form(context, request)

# asked for email sending
if portal_registration.validate_email:
    portal_registration.registeredNotify(username)

return context.registered(context, request)
}}}

Don't hesitate to ask if something is not clear.

Regards.

JoseLuis de la Rosa Triviño 
Becario Área de Sistemas de Información 
FUNDACIÓN IAVANTE 
[EMAIL PROTECTED] 
Tel. 951 015 300 


Este correo electrónico y, en su caso, cualquier fichero anexo, contiene 
información confidencial exclusivamente dirigida a su(s) destinatario(s). Toda 
copia o divulgación deberá ser autorizada por IAVANTE.

This e-mail and any attachments are confidential and exclusively directed to 
its adressee(s). Any copy or distribution will have to be authorized by IAVANTE.



-----Mensaje original-----
De: CLIFFORD ILKAY [mailto:[EMAIL PROTECTED] 
Enviado el: jueves, 13 de abril de 2006 7:46
Para: CPS List
Asunto: [CPS-users] Modifying join_form

Hello,

I want to collect postal addresses of portal members when they 
register. How would I add those fields to join_form and make them 
mandatory?
-- 
Regards,

Clifford Ilkay
Dinamis Corporation
3266 Yonge Street, Suite 1419
Toronto, ON
Canada  M4N 3P6

+1 416-410-3326
_______________________________________________
cps-users mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/cps-users
_______________________________________________
cps-users mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/cps-users

Reply via email to