创建自定义表单-Create Custom Forms
Deprecated: This module is deprecated as of v1.9. We recommend you use the
Orchard.DynamicForms
module instead.不推荐使用:自v1.9起,该模块已弃用。我们建议您使用
Orchard.DynamicForms
模块。
The Custom Forms module is used to capture information from site visitors on the front end. Custom Forms works in combination with a Content Type. Custom Forms can be used to create Contact Us and Subscribe widgets/pages to name a couple. The information is then stored in Orchard and can be exported later.
自定义表单模块用于从前端的站点访问者捕获信息。自定义表单与内容类型结合使用。自定义表单可用于创建联系我们和订阅小部件/页面来命名一对。然后将信息存储在Orchard中,以后可以导出。
Enable the Custom Forms Module
启用自定义表单模块###
The Custom Forms module works in combination with a Content Type to capture input on the front-end. The information submitted is stored and can be exported using the Import-Export-Module. Let's start by enabling the Custom Forms module that is shipped with Orchard by going to the Modules section in the admin.
自定义表单模块与内容类型结合使用以捕获前端的输入。提交的信息已存储,可以使用Import-Export-Module导出。让我们首先启用Orchard附带的Custom Forms模块,方法是转到admin中的Modules部分。
Once the module has been enabled the feature can be browsed to in the admin with the new Forms link in the left hand navigation.
启用模块后,可以使用左侧导航中的新 Forms 链接在管理员中浏览该功能。
As stated before, the Custom Forms module works with a content type in order to create submission forms on the front-end of the site. In the Forms section of the admin, if the button Add a new Custom Form were selected, a drop-down list in the next screen for the content types will show all of the default content types that exist currently in the CMS. However, let's say we are looking to add a new widget that will live in the right rail (AsideSecond zone) that is a call for visitors to join a mailing list. The only input that will be captured will be the users email address.
如前所述,自定义表单模块使用内容类型,以便在站点的前端创建提交表单。在管理员的 Forms 部分中,如果选择了按钮添加新的自定义表单,则下一个屏幕中的内容类型的下拉列表将显示当前在CMS中存在的所有默认内容类型。但是,假设我们正在寻找一个新的小部件,它将生活在正确的轨道(AsideSecond区域)中,这是一个访问者加入邮件列表的呼叫。将捕获的唯一输入将是用户电子邮件地址。
Create a New Content Type
创建新的内容类型###
In order for Custom Forms to capture and save an email address from a visitor we need to create a new content type in Orchard. In the admin, browse to the Content Types tab and select the Create new type button in the upper right. (NOTE: the Content Types tab is located in the content area for version 1.6 and lower or by selecting the Content Definition link in the admin for version 1.7 and higher. Let's call the new type 'Subscribe Form'.
为了使自定义表单能够从访问者捕获和保存电子邮件地址,我们需要在Orchard中创建新的内容类型。在管理员中,浏览到内容类型选项卡,然后选择右上角的创建新类型按钮。 (注意:内容类型选项卡位于版本1.6及更低版本的内容区域中,或者通过在版本1.7及更高版本的管理员中选择内容定义链接。让我们调用新类型“订阅表单”。
The next screen asks if we'd like to save any Parts to the new Subscribe Form content type. Since all we are looking to capture is an email address, click on the save button without selecting any of these options. Now that we have our new content type we'll want to add an input field for the email.
下一个屏幕询问我们是否要将任何部件保存到新的订阅表单内容类型。由于我们要捕获的所有内容都是电子邮件地址,因此请单击“保存”按钮,而不选择任何这些选项。现在我们有了新的内容类型,我们想要为电子邮件添加输入字段。
After adding and saving the input field with the name 'Email' we can now customize the type of validation the new input field should have by selecting an input type of 'Email'. Feel free to fill in the other information for the field as well.
在添加并保存名为“Email”的输入字段后,我们现在可以通过选择“电子邮件”的输入类型来自定义新输入字段应具有的验证类型。随意填写该领域的其他信息。
At this point we have all the pieces we need to create out new widget in the right rail (AsideSecond zone). We've enabled the Custom Forms module and we've created a new content type (Subscribe Form) that will be used to capture the email address of visitors looking to enroll in the mailing list. All that's left is to create the Widget.
在这一点上,我们拥有在右侧轨道(AsideSecond区域)中创建新小部件所需的所有部分。我们启用了 Custom Forms 模块,我们创建了一个新的内容类型(订阅表单),用于捕获希望注册邮件列表的访问者的电子邮件地址。剩下的就是创建Widget。
Create a Custom Forms Widget
创建自定义窗体小部件###
Select Widgets in the left menu of the admin and find the appropriate Add button for the AsideSecond zone and add a Custom Forms Widget.
在admin的左侧菜单中选择 Widgets ,找到AsideSecond区域的相应 Add 按钮并添加Custom Forms Widget。
The only thing left to do is to adjust the settings on our new Custom Forms Widget. In this example, the layer is set to 'Default' and the position is set to '1'. This will render the widget on the top of the right rail (AsideSecond zone) for all pages. These are some example settings:
剩下要做的就是调整我们的新自定义窗体小部件的设置。在此示例中,[layer](Managing-widgets#AddingaLayer)设置为“Default”,位置设置为“1”。这将使窗口小部件在所有页面的右侧轨道(AsideSecond区域)的顶部呈现。这些是一些示例设置:
After saving the widget browse to a page on the site and check out the new feature!
保存小部件后浏览到网站上的页面并查看新功能!
NOTE: If the input field for the owner is visible remove it by un-checking the 'Show editor for owner' option under the Common part of the Subscribe Form content type.
注意:如果所有者的输入字段可见,则通过取消选中“订阅表单”内容类型的“公共”部分下的“为所有者显示编辑器”选项将其删除。
View Submitted Custom Forms Data
查看提交的自定义表单数据###
At this point, we have enabled the Custom Forms module, created a new content type for the Custom Forms to use and added a Custom Forms widget to draw the Subscribe Form content type in the right rail (AsideSecond zone) of all the pages. The submissions are being saved in Orchard because the option in the Custom Forms widget 'Save the item once the form is submitted' was checked. So where are they being saved? There are two ways to see the submissions in the CMS. The first is to select the 'Forms' link on the left in the admin section of Orchard.
此时,我们启用了自定义表单模块,为自定义表单创建了一个新的内容类型,并添加了自定义表单窗口小部件,以在所有页面的右侧轨道(AsideSecond区域)中绘制“订阅表单”内容类型。提交将保存在Orchard中,因为选中了自定义窗体小部件中的选项“提交表单后保存项目”。那么他们在哪里得救?有两种方法可以在CMS中查看提交内容。第一个是选择Orchard管理部分左侧的“表单”链接。
The second being to view the Subscribe Form content type.
第二个是查看订阅表单内容类型。
Export Custom Forms Data
导出自定义表单数据###
The only thing left to do is to export our list of submissions so that the email addresses can be used by services like Publicaster, Campaign Monitor, MailChimp and the like. The easiest way to export anything and everything from the Orchard CMS is to use the Import/Export module. The Import/Export module is shipped with Orchard by default in version 1.6 and on but is not enabled by default. Let's enable the Import/Export module.
剩下要做的唯一事情是导出我们的提交列表,以便电子邮件地址可以被Publicaster,Campaign Monitor,MailChimp等服务使用。从Orchard CMS导出任何内容和最新内容的最简单方法是使用“导入/导出”模块。默认情况下,导入/导出模块在版本1.6及更高版本中随Orchard一起提供,但默认情况下未启用。让我们启用导入/导出模块。
The Import/Export functions are now available in the admin via the left navigation. Selecting the 'Export' tab at the top of the Import/Export section of the admin shows all of the available content types in Orchard. To export the list of emails that have been submitted check the box next to the Subscribe Form content type. Towards the bottom of the page there are a few options for export. The first option, Metadata, will include the definition of the content type. One use for this option would be an easy way to copy a content type and it's records from one Orchard CMS site to another. A prime example of this would be to move a new content type and data from a development site to a production site. When importing an XML file that contains both the metadata and data, Orchard will create the content type copy in the included data.
导入/导出功能现在可通过左侧导航在管理员中使用。选择管理员导入/导出部分顶部的“导出”选项卡可显示Orchard中的所有可用内容类型。要导出已提交的电子邮件列表,请选中订阅表单内容类型旁边的框。在页面底部有一些导出选项。第一个选项 Metadata 将包含内容类型的定义。此选项的一个用途是将内容类型及其记录从一个Orchard CMS站点复制到另一个Orchard CMS站点的简单方法。一个主要的例子是将新的内容类型和数据从开发站点移动到生产站点。导入包含元数据和数据的XML文件时,Orchard将在包含的数据中创建内容类型副本。
In the current situation we are only interested in exporting the data so there is no need to check the Metadata option. Also, be sure to bullet 'Draft Only' since none of the items submitted from the front end would have a published state.
在目前的情况下,我们只对导出数据感兴趣,因此无需检查元数据选项。此外,请确保弹出“仅草稿”,因为从前端提交的任何项目都不会具有已发布状态。
The exported file is and XML file that can be opened in MS Excel and manipulated to be made ready for the email campaign platform of your choice. And that's it... The site is now able to collect visitor's email addresses and save them for export later for a newsletter. The Custom Forms is also a great way to implement a Contact Us page or any other number of types of information a site should collect from it's users.
导出的文件是XML文件,可以在MS Excel中打开并进行操作,以便为您选择的电子邮件营销活动平台做好准备。就是这样......该网站现在能够收集访问者的电子邮件地址并保存,以便稍后导出以用于简报。自定义表单也是实现“联系我们”页面或站点应从其用户收集的任何其他类型信息的好方法。