Inputting user data

In this topic we show you how to enter data into a database using a form to input the data. We show how to:

To create and run the form

  1. Add the code for the InputInfo page to the configuration.pages.xml file (it can go either before or after the code for the listFriends page). (Alternatively, create a new file, and include a reference from the configuration.1.xml file.)
  2. Open a browser and type the base URL followed by /admin/GenerateAllPages.php You should see a list of messages, the final one being, "Finished Generating Pages". This indicates that there are no errors in the code.
    The GenerateAllPages tool is useful for testing code before pages are used on a live database. It ensures that all the pages are generated, and it shows any errors for each page. It also improves the initial response time for the user.
  3. Open the InputInfo page in your browser. You should see three input fields and a button named "Enter". Type values into the fields, and click the button. Arcos processes the data, and the form is cleared. Repeat a few times.
  4. Open the listFriends page in your browser. This will show all the records, including the ones that you have just entered.

Code for InputInfo page

<Page PageName="InputInfo">
   <DataSource Name="tblFriends">
      <SYS_Recordset_GetDefaultRecord/>
   </DataSource>

   <SYS_Form Name="frm1"/>
  
   <SYS_Button Name="btnRowButton" RecordsetName="tblFriends"
      value="Enter" Section="PR_FormPassedNew">
      <SYS_Action_AddCurrentRecord RecordsetName="tblFriends" />
      <SYS_Action_GoToPage PageName="InputInfo"/>
   </SYS_Button>

   <SYS_Display_Template TemplateFile="LOCAL_InputInfo">
      <SYS_AutoTemplate_Form FormName="frm1" >
         <SYS_AutoTemplate_RecordListEdit ComponentName="tblFriends">
            <Property Name="RowButtons">
               <Property Value="btnRowButton" />
            </Property>
            <Property Name="FieldFilterExt">
               <Property>
                  <Properties FieldName="Name" />
               </Property>
               <Property>
                  <Properties FieldName="Tel" />
               </Property>
               <Property>
                  <Properties FieldName="Email" />
               </Property>
            </Property>
         </SYS_AutoTemplate_RecordListEdit>
      </SYS_AutoTemplate_Form>
   </SYS_Display_Template>

</Page>

Explanation of code

<SYS_Recordset_GetDefaultRecord/>

This pre-defined component creates an empty record and makes it available for manipulation.

<SYS_Form Name="frm1"/>

This pre-defined component creates a form. The name can be anything. The tag is an anomaly in that it does not need a closing tag, even though other definitions below are included in the form.

<SYS_Button Name="btnRowButton" RecordsetName="tblFriends" value="Enter" Section="PR_FormPassedNew">

Create a row button. The internal name is btnRowButton.

Name. The internal name with which to identify the button.

RecordsetName. The name of the recordset that is linked to the button.

value. Note that the letter "v" is lower case. This causes Arcos to pass the value ("Enter") as HTML, rather than being interpreted. If you omit this property, or if you use an upper-case "V", then the button will have a default label of "Submit".

Section. This parameter ensures that the component, and all its child components are run at the right time. The value "FormPassedNew" ensures that the form is not processed more than once (for example, if the user clicked the button twice).

<SYS_Action_AddCurrentRecord RecordsetName="tblFriends" />

This component takes the record that is associated with the button and puts in the database.

<SYS_Action_GoToPage PageName="InputInfo"/>

This component specifies that when the button is clicked, the specified page is opened. Since we may want to add many records, we open the InputInfo page again.

<SYS_Display_Template TemplateFile="LOCAL_InputInfo">

Create a template that is used for input of information.

<SYS_AutoTemplate_Form FormName="frm1" >

This associates the form with the autotemplate components which are within the AutoTemplateForm component.

<SYS_AutoTemplate_RecordListEdit ComponentName="tblFriends">

This autotemplate allows you to edit records. The component goes through all the records in the named recordset (tblFriends) and produces a list of the fields which can be edited.

<Property Name="RowButtons">
   <Property Value="btnRowButton" />
</Property>

The first line above specifies that the RecordListEdit autotemplate will get data from a row button. The second line specifies that the button that we created earlier will be the row button.

Since we have loaded only one record (using GetDefaultRecord), we will see just a single set of fields on the form.

<Property Name="FieldFilterExt">

This line specifies that we want to show only a subset of fields on the form. Without it (and the following field specifications) all the fields would be displayed.

<Property>
   <Properties FieldName="Name" />
</Property>

Each field that is displayed is specified using this code structure.