Skip to main content

Setting up inquiry forms

This tutorial explains how to set up inquiry forms in a project using Kuroco.

info

This tutorial is written with the following versions:
Nuxt2: v2.15.8
Nuxt3: v3.8.0

info

This tutorial assumes that you have already set up a project with Kuroco and Nuxt.js.
If you have not yet set up one, please refer to the following tutorial.
Nuxt.js:Beginner's guide to Kuroco

About Kuroco forms

The form function in Kuroco allows the user to define data to support the creation of HTML forms, set automatic replies, and view form data submitted by users.

You can manage form settings via the [Campaign] -> [Form] module of the admin panel.

Image from Gyazo

For more information, refer to the following user guide documents:

Before your form can be used, you need to configure various settings and codes on the front-end. The sections below explain the steps to enable forms in your Kuroco and Nuxt.js project.

Defining your form data

To create a new form, click [Add] in the upper right corner of the form list screen.

Image from Gyazo

You will be redirected to a new form editor. See: Form editor - Basic settings for a detailed description of each field. For this tutorial, we will create a sample form with the following entries:

Image from Gyazo

FieldValue
TitleTest form
DescriptionEnter description here.
Enter description here.
Enter description here.
Thank you messageEnter thank-you message here.
Enter thank-you message here.
Enter thank-you message here.

When you are done, click [Add] at the bottom of the screen.

Image from Gyazo

You will be redirected back to the form list, which now contains your newly created form.

Image from Gyazo

Note: The number displayed in the "ID" column is the unique identifier of the inquiry form.

caution

The ID value of each entry is automatically generated and varies depending on the environment. In the above example, the ID number is 5. However, for the steps below, remember to substitute this value with the ID shown on your screen.

Verifying the form settings

Verify the field settings

On the form list screen, click the title of your new form.

Image from Gyazo

You will be redirected to the form editor screen. From there, click the [Field settings] tab.

Image from Gyazo

This will take you to the form field settings screen.

Image from Gyazo

Here, you can set HTML definitions of the inquiry form fields.

"name", "email", and "message" have been preset, since they are required fields in Kuroco. To add a custom field, you can define it as desired in the blank fields below "message".

Image from Gyazo

For this part of the tutorial, we will use only the default fields.

Verify the responses

Click the [Submissions] tab to view a list of user-submitted responses to the form.

Image from Gyazo

All responses submitted via the HTML form are displayed here.
(In the above screenshot, there are no records displayed, since the HTML form has not been created yet and hence no data has been submitted.)
Details such as the response contents can be verified on this screen or in the [Report] tab to the right.

Setting up endpoints for the form

Next, create two endpoints as follows and enable the form function on the front-end:

  • For form definition retrieval: (GET) form
  • For form data submission: (POST) form

A. (GET) form endpoint setup

In the sidebar menu, select the target API from [API] and click [Add new endpoint] on the endpoint list screen.

Image from Gyazo

Set up your endpoint as follows:

Image from Gyazo

Field(s)Setting
Pathform
CategoryForm
ModelInquiryForm
Operationdetails
API Request LimitNone
tip

For simplicity, we will omit the authorization settings here.

Swagger UI verification

Then, verify if the Swagger UI can retrieve the form you have defined. On the endpoint list screen, click [Swagger UI].

Image from Gyazo

You will be redirected to the Swagger UI screen. Select the endpoint you created earlier.

Image from Gyazo

Click [Try it out]

Image from Gyazo

Enter the ID of your new form (in this case, 3) in the "inquiry_id" field and click [Execute].

Image from Gyazo

The form will be converted to JSON and displayed under "Responses".

Image from Gyazo

B. (POST) form endpoint setup

You also need to create an endpoint for submitting data from HTML to the target form.

As before, select your target API in the sidebar menu and click [Add new endpoint] on the endpoint list screen.

Image from Gyazo

Set up your endpoint as shown below.

tip

Similarly, we omit the authorization settings here for simplicity.

Image from Gyazo

Image from Gyazo

ItemSetting
Pathform
CategoryForm
ModelInquiryMessage
Operationsend
API Request LimitNone
idForm ID to which the submission is sent (3)

When you are done, click [+Add] to save these settings.

Next, let's confirm the behavior of the POST request.

Click on the [Try it out] button for the InquiryMessage::send endpoint created earlier.

Image from Gyazo

In the "Request body" section, you'll see a sample of data that can be sent. Edit the JSON below and click [Execute].

{
"name": "My Name",
"email": "email@example.com",
"body": "Example Message"
}

Image from Gyazo

The response will include the ID of the answer registered in Kuroco's form and a thank-you message.

Image from Gyazo

Upon checking the response, you'll see that the data you submitted is stored in Kuroco.

Image from Gyazo

We have now set up two endpoints:

  • For form definition retrieval: (GET) form
  • For form data submission: (POST) form

Next, let's use them to create and submit your form.

Additional front-end modifications

In the Nuxt installation directory, create additional files with the following structure. This time, create the following files in the /form/ directory to display a form.

pages
- form
- index.vue

Insert the following code.

/pages/form/index.vue
loading...
caution

For const FORM_ID = 3 above, substitute the ID value with your own.

caution

For /rcms-api/8/form/${FORM_ID} and /rcms-api/8/form, enter the path shown on your endpoint list screen.

Browser verification

Next, verify the above file in youe browser.
If your local server is down, run npm run dev to access http://localhost:3000/form. You should see the screen below:

Image from Gyazo

When checking the [Network] tab in Chrome's developer console, you can confirm that communication is taking place with Kuroco, retrieving detailed information about the form.

Image from Gyazo

For detailed information in the response, please check the development console or use SwaggerUI to verify from the Kuroco management screen.

Send the HTML form data

Next, submit data from the HTML form. Enter values for each item as follows:

FieldInput Value
NameTest Name
Emailtest@example.com
MessageTest Message

Upon clicking the [submit] button, the data will be sent, and a thank you message will be displayed.

Image from Gyazo

As seen in the source code under "handleOnSubmit()," this action POSTed the data of [Form Items] to Kuroco.

You can also verify the content POSTed from the development console. If the submission is unsuccessful, please ensure that the data format matches the format confirmed in SwaggerUI.

Image from Gyazo

Data verification in Kuroco

On the form list screen, click [Test form].

Image from Gyazo

Click the [Submissions] tab to view the list of form responses received. You should see the entry you submitted earlier.

Image from Gyazo

You can click the "No." link ([40] in this example) to view the response details, which contain data submitted via the HTML form.

Image from Gyazo

Form validation

Lastly, let's test the form validation function.

Revisit the form page and enter an invalid value in the [email] field. Sample input:

FieldInput value
[name]Empty
[email]mail
[message]Empty

After you click [submit], an error message will be displayed at the top of the screen.
Please also check the error messages from Kuroco in the development console.

Image from Gyazo

The above procedure verifies Kuroco's server-side validation. When an error occurs, the error content and HTTP status code are returned in the response body. As seen in the source code, you need to implement error handling on the front-end as well.

tip

To validate dynamic forms, you will need custom implementations based on the values obtained from Kuroco.

Custom fields

In addition to the default form fields, you can freely define custom fields following the steps below.

Add a custom field

On the form list screen, click [Test form].

Image from Gyazo

Click the [Field settings] tab to display the inquiry field settings screen.

Image (fetched from Gyazo)

To set up a dropdown selection field, enter the values shown below in a blank custom entry:

Image (fetched from Gyazo)

FieldInput value
Titleitem
Required attributeOptional
Answer format / Input restrictionDropdown selection
Options settings1::apple
2::banana

When you are done, click [Update] near the bottom of the screen.

Image (fetched from Gyazo)

Using SwaggerUI, confirm that the response from the InquiryForm::details endpoint in Kuroco includes the added form field (ext_01).

Image from Gyazo

Next, using SwaggerUI, check how to POST the 'ext_01' field to the InquiryMessage::send endpoint, including its data format.

Check SwaggerUI's Example Value and Schema.

Image from Gyazo

Image from Gyazo

In this case, for a single selection (select box), it accepts data in the following formats:

  • "ext_01": {"key": "1" , "label": "apple"}
  • "ext_01": "1"

Based on the confirmed information, add frontend code to display the contents of options obtained from Kuroco as choices and POST the selected key using a select box.

The updated code is as follows:

/pages/form/index.vue
loading...

Confirm that the added field is displayed.

Image from Gyazo

Submit the form and confirm that the response is registered in Kuroco.

In the development console, verify that the key selected in the select box is POSTed in the format "ext_01":"1".

Image from Gyazo

Date

Next, let's add a date input field and verify the form

Setup

To set up a date input field, enter the values shown below in a blank custom entry:

Image from Gyazo

FieldInput value
Titledate
Required attributeOptional
Answer format / Input restrictionDate
Options settings(Leave blank)

When you are done, click [Update] near the bottom of the screen.

Image (fetched from Gyazo)

Similarly to before, let's use SwaggerUI to confirm the addition of the field and the data format for POSTing. As the date is to be POSTed in String format as Y-m-d, modify the index.vue accordingly to accommodate this.

/pages/form/index.vue
loading...

Select 1900/01/01 in the Date field, submit the form, and confirm that the response is successfully registered in Kuroco.

Image from Gyazo

Validation check

field settngs can be validated in Kuroco. For example, let's set up a validation check for dates between 10 years ago and the present.

In the [Field settings] tab of the form editor, click [Settings] next to the custom "date" field.

Image (fetched from Gyazo) In the settings dialog, enter -10 years for the "Relative start offset" field under [Input type].

Image from Gyazo

tip

Refer to the reference guide List of available fields for the inquiry form: Date format for more information.

After you implement this validation check, entering a date over 10 years before the current date will result in an error. To test this, enter 1900-01-01 in the "date" field of the form page as before and click [submit].

Image from Gyazo

info

The validation on the Kuroco side is strictly backend validation. If you wish to perform additional validation on the frontend, you will need to implement it yourself.

tip

When setting the Year (min) and Year (max) in the form field settings, you can obtain a list of selectable years in the InquiryForm::details.cols.ext_02.options of the response from InquiryForm. You can use this to restrict the selectable years or allow users to choose a year using a select box. For example, if the request to Kuroco's endpoint is in the format "ext_02":"1990-01-01", it is acceptable to input the date field with a any tag.

File upload

This field type allows you to upload and submit files in the inquiry form.

Setup

To set up a file upload field, enter the values shown below in a blank custom entry:

Image from Gyazo

FieldInput value
Titlefile
Required attributeOptional
Answer format / Input restrictionFile
Options settings(Leave blank)

When you are done, click [Update] near the bottom of the screen to save these settings.

Image (fetched from Gyazo)

Create file upload endpoint

The implementation process is as follows:

  1. Upload your file to Kuroco.
  2. Submit the ID of the uploaded file.

In order to do that, you need to first create an endpoint to receive uploads. Select your target API in the sidebar menu and click [Add new endpoint] on the endpoint list screen.

Image (fetched from Gyazo)

Enter the following settings in the endpoint configuration dialog:

Image (fetched from Gyazo)

ItemSetting
Pathfile
CategoryFiles
ModelFiles
Operationupload
AuthorizationNone
tip

For simplicity, we will omit the authorization settings here.

Swagger UI verification

The next step is to verify if Swagger UI can retrieve the new form definition. On the endpoint list screen, click [Swagger UI].

Image (fetched from Gyazo)

On the Swagger UI screen, select the file upload endpoint you created earlier.

Image (fetched from Gyazo)

Click [Try it out].

Image (fetched from Gyazo)

In the input field labeled "file", select a sample file from your local drive and click [Execute]. For this tutorial, we will use the logo image kuroco.png.

Image (fetched from Gyazo)

The file is uploaded and stored in a temporary location indicated by the file_id path.

Image from Gyazo

note

When uploading files, the specified header should be 'Content-Type: multipart/form-data'. Please be sure to specify this when performing a POST request from the frontend.

Moreover, accessing the file_id in the browser will display the uploaded image, allowing you to confirm that the file has been stored.

Image (fetched from Gyazo)

tip

The URL for confirmation is ADMIN_URL + file_id.

Sending this file_id to the endpoint of InquiryMessage::send will result in the file stored in the temporary area being saved in KurocoFiles, associated with the corresponding response.

With this, the endpoint for the form is now complete.

Form modification and file submission

Next, update pages/form/index.vue.

The following is the updated code.

/pages/form/index.vue
loading...

Let's actually upload an image and submit form data to confirm that the new [file] field is sent to Kuroco.

When uploading an image file from the front end, a request is sent to the Files::upload endpoint at the time of upload, and you can confirm that the file_id is obtained.

Image from Gyazo

Next, enter the required information and click [submit]. You can confirm that the file_id is POSTed to the InquiryMessage::send endpoint.

Image from Gyazo

Click the [Answers] tab from the [Forms] section in the admin panel to display the list of responses and confirm that the data has been added.

Image from Gyazo

Click on [No.] (in this case, 31) to view the details, and you can confirm that the newly added [file] field and the value entered for that field are applied.

Image from Gyazo

Reference

For the sake of simplification in this tutorial, HTML corresponding to each field in Kuroco is written on the front end. Therefore, if you change the field settings in Kuroco, you also need to update the front-end code.

If you want to dynamically change the front-end display based on Kuroco's field settings, please use the type included in the response of InquiryForm::details for branching.

For more details, refer to the corporate sample site repository:
https://github.com/diverta/front_nuxt_corporate/blob/main/pages/contact/index.vue


Support

If you have any other questions, please contact us or check out Our Slack Community.