I am using PloneFormGen 1.7.12 in Plone 4.3.3. I have a large selection field that contains about 20 names. It is required. If the user picks one of the names, it should send them to a Plone Page template that has instructions for them. If it picks any other page, it should send the user an email with their form results and takes them to a thank you page.
I have tried doing this with a python script, but what I am doing doesn't work. The code in the script is:
REDIRECT = context.REQUEST.RESPONSE.redirect
URL=context.REQUEST.URL1 + '/'
FORM=context.REQUEST.form
school_name = context.REQUEST.form['school_name']
member = context.portal_membership.getAuthenticatedMember()
roles=member.getRolesInContext(context)
if school_name <> "Other-School not Listed":
return False
else:
return REDIRECT(URL + 'not_listed')
I put python:here.school_redirect() in the Custom Form Action override, but the URL displays:
python:here.school_redirect()
and the page displays "The address wasn't understood"
school_redirect is the id of the python script not_listed is the id of the Plone page template school_name is the id of the select field
Any suggestions are greatly appreciated.
Joe Bigler
The Custom Form Action
is a simple StringField, no a TALES expression field.
This means you can add ./school_redirect
to the Custom Form Action
, but then you got other issues like returning False
will not work, you need to redirect anyway. You also bypasses all validators and success handlers.
So imho another approach may be better:
1. Override the success handler
Custom Success Action
Field on FormFolder. You may add a single expression or a python script, which returns the right value.
Field description:
Use this field in place of a thanks-page designation to determine final action after calling your action adapter (if you have one). You would usually use this for a custom success template or script. Leave empty if unneeded. Otherwise, specify as you would a CMFFormController action type and argument, complete with type of action to execute (e.g., "redirect_to" or "traverse_to") and a TALES expression. For example, "redirect_to:string:thanks-page" would redirect to 'thanks-page'.
Your ./school_redirect
needs only small changes to fit for this solution. Do not redirect yourself, just return the right id (of a page template/view/etc.)
2. Do not trigger the mail adapter
For this purpose the Mail-Adapter provides a field called Execution Condition
.
A TALES expression that will be evaluated to determine whether or not to execute this action. Leave empty if unneeded, and the action will be executed. Your expression should evaluate as a boolean; return True if you wish the action to execute. PLEASE NOTE: errors in the evaluation of this expression will cause an error on form display.
Add a script or expression, which evaluates if the email needs to be triggered or not.
You may reuse the ./school_redirect
script to compose the expression: python: here.school_redirect() != 'not_listed'