How to validate with server function

We use validation component when we want to validate form on button click. This tutorial shows you how to use validation component with Server function. In our example we will validate form for registration.

Validation example

1. Login into developer panel of application.

2. Click on Pages menu item.

3. Select page pageRegistrationCustomer.

4. Drag and drop Validation component from all components list to button for registration named ButtonRegister. So when someone click on button Register, form will be validated first.

Server function with validation

5. In dropped validation component properties, for Data source type property choose Server function.

6. Click on Data source Function field and on the left side of dialog window choose plugin. On the right side choose function. You can send values from form components to function in plugin as parameters. Drag and drop Form components from left side to Parameters text fields on the right side. Function in plugin returns result variable. Variable result in plugin function is an instance of AjaxProxy class. Attribute status of result variable ($result->status) can be true or false. If there is an error in validation proccess set attribute status to false. You can also set error message in attribute error ($result->error). You can also set custom error message for every component on form by using validationMessages attribute (i.e. $result->validationMessages = “NameOfComponent1|Error for component 1.;NameOfComponent2|Error for component2.;”). Click on Save button.

Choose server function

7. Click on Save changes, go into your application and check out the results.