hvelarde
hvelarde

Reputation: 2876

Adding a confirmation form before the add form of a content type

One of our customers wants to add a terms of service page that has to be shown every time a user adds some specific content type, before the add form.

Any suggestions on how to implement this?

Upvotes: 1

Views: 101

Answers (4)

Mathias
Mathias

Reputation: 6839

As mentioned in the comment of the question. I would advise adding a checkbox to the content.

For AT content you can add a BooleanField

...

atapi.BooleanField(
    name='acceptConditions',
    schemata='default',
    required=False,
    default=False,
    validators=('acceptConditions', ),
    widget=atapi.BooleanWidget(
        label=_(u'label_accept_conditions', default='Conditions'),
        description=_(
            u'help_accept_conditions',
            default='Please accept the <a target="_blank" '
                    'href="./conditions_view">'
                    'conditions<a/>.')
    ),
)
...

With a condition on the widget (In this case a browser view, which checks if the boolean field should be visible or not).

YourSchema['acceptConditions'].widget.setCondition(
    'python: here.restrictedTraverse("@@show_condition_field").show()')

Upvotes: 1

David Glick
David Glick

Reputation: 5432

If it's a Dexterity content type, you can do this:

Create a custom form with your terms of service. In the form's button handler, redirect to the add form:

self.request.response.redirect(self.context.absolute_url() + '/++add++name.of.content.type')

Now in your type's factory info in portal_types, set the add_view_expr like this:

<property name="add_view_expr">string:${folder_url}/@@terms-of-service</property>

so it goes to the custom TOS form when you click the type in the factory menu, instead of directly to the add form.

(Note: a downside of this approach is that if the user enters the URL of the add form directly, they can bypass the TOS form.)

Upvotes: 2

keul
keul

Reputation: 7819

An idea: when you are adding new content types (AT based content types, this will not work for Dexterity ones) you are calling

http://something/createObject?type_name=Document

You can transform the createObject script into an view that display you disclaimer form, with validation on submit.

When user accept the disclaimer you will redirect the use to something like

http://plone4.gest.unipd.it:8080/gest/it/realCreateObject?type_name=Document

where realCreateObject is a copy/paste of the original Plone createObject script.

However: the suggestion of Mathias above is really good: just add a fake checkbox field with a validation.

Upvotes: 1

gforcada
gforcada

Reputation: 2558

A possible solution could be to use a cookie/session_data_manager/token/you-name-it that on the custom AddForm for that content type checks if exists.

If it doesn't redirect to that Terms of Service form that redirects back to the Addform where, now it will accept to proceed becuase the cookie/session_data_manager/token/you-name-it will be there.

Upvotes: 1

Related Questions