How to Create Ez Publish Forms / Articles / Developer / Ez.No - Content Management System Ez Publish (Open Source CMS)
Total Page:16
File Type:pdf, Size:1020Kb
How to Create eZ Publish Forms / Articles / Developer / ez.no - Content Management System eZ Publish (Open Source CMS) How to Create eZ Publish Forms Paul Wilson Friday 14 December 2007 10:35:00 pm This article is part of the eZ Publish “How to” series and provides a step-by-step guide to creating a custom form for an eZ Publish website. To integrate with other examples in this series, this article focuses on the creation of a membership application form for the “eZ Tennis Club” website. The procedures in this article apply to eZ Publish 3.10.0 with the Website Interface, although the overall principles should also apply to other versions of eZ Publish with and without the Website Interface. We assume that you are familiar with or have a basic understanding of the following three concepts, which we explored in the previous two articles in this series: the layout of the Administration Interface; the configuration system and INI settings files; and the template system. The first article in this series - How to Configure an eZ Publish Site - explained how to set up the site for the fictional eZ Tennis Club. The second article in this series - How to Use eZ Publish Extensions: Google Analytics - gave you some practical experience on installing and configuring an extension. Objects and information collection There are two methods in eZ Publish to collect and process information from site visitors: Information collection: creating forms using objects with attributes marked as information collectors This method uses the “information collection” features of eZ Publish. The most obvious example of this is the contact form (see below) present in a standard Website Interface installation. With this approach, you create an eZ Publish object that displays as a form to visitors. When visitors fill in the form, new eZ Publish objects are not created. Instead, the information is stored in a separate part of the system and, if configured to do so, emailed to a recipient. This tends to be the method of choice when the user’s input is not made public (for example, in contact forms); and when user responses are collected together for display purposes (for example, in polls). 1 of 21 This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License Copyright © 1999-2007 eZ Systems AS How to Create eZ Publish Forms / Articles / Developer / ez.no - Content Management System eZ Publish (Open Source CMS) Contact form, based on the Feedback form object This article goes through an example with the information collection method. The image below (click to view the full-size image) is a road map for the collected information form functions. It is a useful outline to consult when creating your own forms and when following along in this article. Collected information form functions road map 2 of 21 This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License Copyright © 1999-2007 eZ Systems AS How to Create eZ Publish Forms / Articles / Developer / ez.no - Content Management System eZ Publish (Open Source CMS) Enabling users to create objects Under this method, the user’s input becomes part of the website as an object in the eZ Publish content node tree. An example of this is creating a new Comment object beneath an existing Article object (to be displayed when visitors view the article). For this to happen, the user must have the appropriate permissions to create the object at a given location within the content structure. Some other examples of this method are the Forum topic and Forum reply objects within an eZ Publish forum. This approach may use eZ Publish workflows so that a site administrator must approve the user's object before it is visible on the website. The table below outlines some of the characteristics of each method and is useful for readers who want to explore eZ Publish's features a bit more. Enabling users to create objects Information collection Concept User fills in a form that becomes a new User fills in a form, but this does not become object in the eZ Publish content structure. a new object in the eZ Publish content structure - instead, the form is handled by eZ Publish's information collection modules and features. Examples - Article comments - Feedback forms ("contact us" forms) basic functions - Forum topics and replies - Polls Datatypes Class for the object does not use Class for the object uses information information collector datatypes. This collector datatypes. This means: (see the Reference means: - Limited datatype options documentation on - More datatype options - Use of custom datatypes is more difficult. datatypes) - Possible to use custom datatypes One method for dealing with this limitation is to pre-process form input in a custom edit template and then encode the input into a Text line datatype. Permissions Set via user and user group permissions in May use permissions, although anonymous the Administration Interface. access can also be defined in settings in collect.ini. What happens A new object (or object awaiting approval) No new object is created in the content node within eZ Publish? is created in the content node tree. tree. Instead, a new entry is made in the collected information area under the Setup tab in the Administration Interface. Actions Can be used in workflow processes. Option to send email showing information collected (set in collect.ini). 3 of 21 This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License Copyright © 1999-2007 eZ Systems AS How to Create eZ Publish Forms / Articles / Developer / ez.no - Content Management System eZ Publish (Open Source CMS) Fetch functions - Normal eZ Publish content fetch functions - A limited range of fetch functions: how can I access a rich range of access and sorting - collected_info_collection and use the data possibilities. - collected_info_count collected? - collected_info_count_list Some of the typical object access and (see the Reference sorting possibilities are unavailable in fetch documentation on functions for collected information. fetch functions) Templates Standard eZ methods, using edit and view Expect to have to make your own template templates, or create your own custom edit to view and edit the form. This can be done and view templates. using elements from the Poll and Feedback form templates. Creating a custom form In this article, I will walk you through creating a custom membership application form on the eZ Tennis Club website. The form will collect the following information from site visitors, storing it on the site and emailing it to a specified email address: Given name Surname Date of birth Phone number Email address Postal address Opt-in specifications about receiving certain club information Open-ended questions or comments When we are done creating the form, it should look like this: 4 of 21 This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License Copyright © 1999-2007 eZ Systems AS How to Create eZ Publish Forms / Articles / Developer / ez.no - Content Management System eZ Publish (Open Source CMS) Final membership application form Creating a new form class The first step in creating the membership application form is to create a class for the object that will collect the information from visitors. To do this, log in to the Administration Interface and click on the Setup tab. In the left menu, click the Classes link: 5 of 21 This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License Copyright © 1999-2007 eZ Systems AS How to Create eZ Publish Forms / Articles / Developer / ez.no - Content Management System eZ Publish (Open Source CMS) Click on the Classes link Then, in the Class groups window, click the Content link. Our form will appear in the Content branch of the site's node tree and thus be under this group: "Content" class group You are then presented with a list of all the existing classes in the Content class group. At the bottom of this list, click the New class button: New class button This will then display the Class edit interface: Class edit interface In our example, the name of the form is “Membership Application Form”, its identifier is “membership_application_form” and the object name pattern is “<form_name>”. To add an attribute, select the datatype from the dropdown list at the bottom of the page and click the adjacent Add attribute button. Then, fill in the necessary information for the attribute. Repeat this in order to add subsequent attributes: 6 of 21 This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License Copyright © 1999-2007 eZ Systems AS How to Create eZ Publish Forms / Articles / Developer / ez.no - Content Management System eZ Publish (Open Source CMS) Add attribute Note that the attributes that will collect information (through form fields presented to the visitor) need to have the Information collector checkbox marked: Information collector checkbox Rather than repeating the explanation of the steps to add each attribute, the information for all the attributes is summarized in the table below: Name Identifier Datatype Required Searchable Information collector Form Name form_name Text line Yes Yes No Form form_introduction XML No Yes No Introduction block Given Name given_name Text line Yes No Yes Family Name family_name Text line Yes No Yes Date of Birth date_of_birth Date Yes No Yes Contact Phone contact_phone_number Text line Yes No Yes Number Email Address email_address E-mail Yes No Yes Postal