As part of migrating a website application that has been continuously growing for the last 12 years over to a new CMS platform, it was necessary to understand how forms could be implemented using Hippo CMS.
After downloading the community edition of Hippo and working through the developer trail and reference documentation, there wasn't any clear example of how a form could be implemented. This post provides details of the proof-of-concept work carried out in developing a website form using registration as an example.
The existing website application provides a registration process that allows users to register with the site and also captures some additional information through a survey. The registration process is therefore spread over multiple pages.
|
Hippo CMS Forms |
The above diagram shows how the CMS repository is configured for the registration process. When a request for registration comes in, it will be matched to the
register.html sitemap item. This is configured with the component
hst:pages/register. This component reuses the
hst:pages/standard component for the general page layout and provides the specific contents through its child
body component. The body component shows how by specifying the
SpringBridgeHstComponent as the
componentclassname and the
spring bean id (
enrolmentComponent) as the
parameter value for the
spring-delegated-bean parameter name, we can define the component controller classes using Spring configuration and leverage its dependency injection functionality. The
register/body node is also specifies a
redirect-page parameter with '
survey' as its value. This parameter will be made available to the Spring configured
enrolmentComponent to indicate which page the user should be redirected to after the form has been submitted.
|
Form Processing EnrolmentComponent |
The above code extract shows the
doAction method for the
EnrolmentComponent. It shows how a list of the fieldnames is constructed and passed to the constructor of the Hippo
FormMap object. At this point, the form would be used to construct an object that would be passed to the enrolment service via the Spring injected
ServiceFacade. However, for the sake of simplicity and to serve as a PoC a previously generated identifier is used to retrieve existing enrolment details. The submitted form is then temporarily persisted in the repository for retrieval by the
SurveyComponent and the configured
redirect-page parameter is retrieved and used to redirect the response. By passing a
StoreFormResult instance when persisting the form, we are able to retrieve the
UUID to send back in the response. The
UUID identifies the node where the form is stored in the repository.
The code below shows how the
SurveyComponent then retrieves the form from the repository ready to be used as required.
|
SurveyComponent |
As can be seen the
UUID is extracted from the request and then used to populate a
FormMap instance using the form data stored in the repository.
The above demonstrates how a website form can be developed using Hippo. It doesn't demonstrate error handling but its obvious how easily that can be implemented.
The above solution is very specific and doesn't allow for a generic form processing component that could be reused in different contexts. With this in mind the Hippo developer community provides the '
easyforms' plugin that makes it very easy to create forms using drag and drop widgets. This will be investigated in an upcoming post.
No comments:
Post a Comment