Little bits of info about CMFFormController

One thing the documentation doesn't clearly state: you can set the status to a value and have that value defined as an action in the metadata file, basically redirecting the flow of the controller sequence to that action.

To make things clear, I'll paste some code. In the login_initial.cpy.metadata file from CMFPlone we have this bit of code:

[actions]
action.success=traverse_to:string:login_next
action.login_change_password=traverse_to:string:login_password

So basically we have two actions defined, depending on the type of status returned.

In the login_initial.cpy file there's this snippet:

# afterwards, change the password if necessary
if state.getKwargs().get('must_change_password',0):
    state.set(status='login_change_password')
return state

So, if the there's a 'must_change_password' in the state, the next action will be login_password.

Another method to achieve this would have been using the setNextAction method, something like this:

state.setNextAction('redirect_to:string:%s/createObject?type_name=ServiceProviderHome' % home.absolute_url())
return state

NOTE: to use setNextAction you shouldn't define any action in the metadata file. According to the documentation, 'As with the .metadata file, the default action specified in the script can be overridden via the ZMI. This allows site managers to override post-script actions without having to customize your code.'

Comments