Tech Bites - Should we validate form data on server-side?

< Back to Blog

Hi, and welcome to another Tech Bite!

When including forms in applications, developers often wonder if they need to re-validate data on the server side after having checked it on the client. Why go to the trouble of checking the data twice?

Even using mandatory fields and validating the data on the button's "client action," what happens on the device is never safe and ready to use.

That's why the OutSystems Platform automatically reminds us to validate all data on the server side before saving!

We should add an "if node" in our application and validate the Price input parameter. Drag the IF node to your logic and write the condition.

If the validation fails, the logic should raise an exception. Pick a Raise Exception Node and select a new User Exception for the first validation. 

Later, you will be reusing this exception, so let’s rename it to something meaningful like Invalid Parameters. 

Now, return to your Exception node and configure the Exception Message field with the message you will display to the user.

That raised exception could be handled on the Screen's Client Action with an Exception Handler node, but it is unnecessary. Because, for all user exceptions without a handler, the Global Exception Handler of your module will do the work. 

You can check it on the On Exception action of the "Common" UI Flow. This will trigger an error message to be shown to the end user.

Let's simulate an issue in the data typed by a user. To be able to test the exception in runtime, we will temporarily disable the client-side validation.

Now, if we try to input invalid data, such as a negative value in the Price field, an error message will be displayed! Meaning the application raised an exception because the data was not valid.

Thanks for watching.

Turn Up Academy

Apply to our Turn Up Boot Camp


Latest Articles

How to download Excel files in OutSystems

How to download Excel files in OutSystems

Learn how to download Excel files using the OutSystems platform in this simple tutorial!

Mastering Email Integration with OutSystems: A Step-by-Step Guide

Mastering Email Integration with OutSystems

In OutSystems Reactive Web Applications, we can configure the Service Center and implement logic in the Service Studio to send emails to our peers or contacts. Follow this step-by-step guide to learn how to!

How to use WebAssembly inside OutSystems - Part 2

How to use WebAssembly inside OutSystems - Part 2

WebAssembly (WASM) is a new technology that is getting a lot of attention. We continue the use of Go compiled to WASM to show how we can use WASM inside OutSystems.