SebTags 1.0 Documentation: Adding and Updating Records

Adding and Updating Records

Here is a basic example of a form for adding and updating records:
<cfparam name="URL.id" default="0">

<cf_sebForm
   forward="basic-list.cfm"
   pkfield="RecordID"
   recordid="#URL.id#"
   CFC_Component="#Application.Basics#"
   CFC_GetMethod="getRecord"
   CFC_Method="saveRecord"
   >
   <cf_sebField name="RecordVal" label="Value" required="true">
   <cf_sebField name="RecordDescrip" label="Description" type="textarea">
   <cf_sebField type="Submit/Cancel" label="Save,Cancel">
</cf_sebForm>

This form will act as an edit form if the "recordid" value is given and represents an existing record. Otherwise it will act as an add form. (note that if "recordid" is not provided, cf_sebForm will check for the existence of URL.id and use that value if it exists)

Because the "RecordVal" field is required, cf_sebForm writes JavaScript (using the qForms JSAPI) to ensure that it is filled in when the form is submitted. On the server-side, the cf_sebForm custom tag checks to see if "RecordVal" is filled out as well. If it isn't, it returns the user to the form (with all of the fields populated with the data the user filled in) and displays a user-friendly error indicating that "RecordVal" is required.

Any error displayed to the user (via JavaScript or server-side validation) will use the field label instead of the field name.

Assuming that the form passes validation, then cf_sebForm will call the method indicated in the "CFC_Method" argument, passing each field as a separate argument. An argument named the value of the "pkfield" attribute will also be passed in to the method with the value of the "recordid" attribute (which defaults to URL.id) of cf_sebForm (assuming a recordset was returned). If I wanted to pass in other arguments, I could pass in a structure of additional arguments to an optional "CFC_MethodArgs" attribute of cf_sebForm.

The method in the CFC_Method attribute would need to handle the logic to add or edit a record.