Example using Interface
Given below is an example of using interface to create a signin form.
The above code creates a form with two input fields. When the button is clicked, the form data is sent to the server and the response is displayed in the #result
div.
You can create a Service
that rests on the server and has a /server.php
endpoint to handle the form data. The Service
can be created as shown below:
Now, when a user enters the name and email and clicks the button, the form data is sent to the server and the response is displayed in the #result
div.
The actual payload
sent to the server is:
Understanding the code
We’ll be taking a closer look at the Submit Button and the Form, for more info on the Service, check the Service documentation.
We start the div
with the class Interface
. This is the parent container for the form and the submit button.
This ensures that Approach will be able to initialize an Interface for the div.
Form
Take a look at the form
In this, you can notice the Autoform
class. This is a special class that tells Approach to handle the form submission. The data-action
attribute is used to specify the action that will be sent to the server. In this case, the action is Survey
.
This means that the name and email are sent to the server grouped under the Survey
action.
Submit Button
Now, this is the submit button that actually triggers the form submission.
This snippet tells Interface that
- The role of this control is to launch a Service request call. Generally this means AJAX to a server.
- The API endpoint is
/server.php
that is where the Service is located. - The method of the API call is
POST
, as specified bydata-api-method
. - The intent of the call is to
REFRESH
theClient
with the response from theServer
actionSave
. - The context of the call is to update the
#result
div with the response from the server. This is essentially the support payload, which is used to specify any additional information that the server might need to process the request.