In Z-CMS, it is possible to realize forms inside webpages to perform insertion and update of data.
A form can be added inside a webpage by using the tags described below. When a form is submitted, Z-CMS provides data handler tools for storing the input data.
Example: Creation of a form
This example describes how to create a form inside a webpage with Z-CMS and how to deal with the information inserted in the form at the submission.
Relevant input controls are to be placed inside the form with respect to the attributes of the Content Model using zcms:component tag. Content Data input for the attributes can then be stored in Z-CMS by submitting the form using the Z-CMS submit tag zcms: submit.
Note: jQuery v1.7 will be included as default in webpages having at least one form realized.
For creating a form to insert content data for the attributes of the Content Model named "user", use the following tags:
<zcms:content-form name="user" type="INSERT" action="saveuser" method="post"> <zcms:component type="text" name="txtname" attribute="name" /> <zcms:component type="text" name="txtsurname" attribute="surname" /> </zcms:content-form >
For updating data inside the attributes of the "user" Content Model use the following tags:
<zcms:content-form name="user" type="UPDATE" action="updateuser" method="post"> <zcms:component type="text" name="txtname" attribute="name" /> <zcms:component type="text" name="txtsurname" attribute="surname" /> </zcms:content-form>
Parameter "type" denotes the expected form action type. Action types can be "INSERT" (create), "UPDATE" (modify) or "AUTH" (authenticate).
Parameter "action" expects a unique identifier value within the Site that can be used by Z-CMS to distinguish the particular mapping of the form with the relevant Z-CMS handler when the form is submitted. In other words, an identifier that can be used by Z-CMS to construct the action page URL.
A "component" can be of "type": "text", "textarea", "password", "checkbox", "radio" (radio button), "filechooser", "select" or "date".
Parameter "attribute" denotes the respective "Attribute Name" of the Content Model.
A form to authenticate login credentials:
<zcms:content-form name="user" type="AUTH" action="userlogin" method="post"> <zcms:component type="text" name="txtusername" attribute="username" /> <zcms:component type="password" name="txtpassword" attribute="password" /> </zcms:content-form>
Note: result status of an authentication process can be obtained using the Z-CMS tag zcms:status.
For submitting the form, Z-CMS submit tag zcms:submit has to be used as a wrapper of a standard "anchor/div/span" tag as shown below:
<zcms:submit form="user"><a>Click here to login</a></zcms:submit>
Note: value of the parameter "form" must be the name of the "content-form" which is to be submitted. Further, Z-CMS submit tag must be placed within a particular zcms:content-form tag.
Input validation can be imposed on relevant components of a form in a webpage using the Z-CMS validation tag zcms:validate as follows.
<zcms:validate checkfor="required" name="txtusername">Please enter username</zcms:validate>
Validation criterion can be one of the following: