Validation Rules aren't run in Server Action for server-side binding

Wappler v7.3.4

NodeJS

Validation Rules aren't run in Server Action for server-side binding

  1. Create a page
  2. Attach a Server Action to the page, for server-side binding
  3. In the Server Action, place a validation rule on $_GET.hello parameter, make it required
  4. You should’ve seen an error or something, instead page proceeds normally

Just curious, how are you displaying the validation on the page?

You're right on being curious :slight_smile:

To give you a little context, imagine I send an email to a user and there's an unsubscribe link:

/unsubscribe?id=123

I made an unsubscribe page that has attached a Dababase Update query, so the validation is just for that, I don't care much what the user sees if validation fails, at least for a minimum viable implementation

Hi Apple,

My understanding is that only $_POST parameters with Linked Fields can show an error in the UI. I haven't used validations for $_GET parameters when submitting a form in the UI. Try by adding the Linked Field property, matching the input field ID, to check whether it shows the error message.

Thanks guptast for your suggestion, it didn’t work either

Validate Data step is not working either

In this example, you have a query parameter id=123. This query parameter can be used to populate a hidden input field value in a server connect form when user clicks on the unsubscribe link. This way you can use $_POST variables with proper validation for both server and UI, and show an error message if validation fails.

Validating a GET input seems to work fine in my tests:

Same for validate data step in the server action. Maybe show some screenshots explaining what you're doing.

You forgot to attach the Server Action to a page for server-side binding:

And then you try to load the page, Validation isn’t processed

1 Like

The validation is only executed if the server action is accessed directly, when it is called as a sub action the validation in not run. This is for sub actions you include or execute from an action and for templates which execute them as a sub action for the template. Executing validation after other steps already have run and output is already generated will result in server errors.

I will check if there is perhaps another way to do validation in templates but with the current implementation it is not possible.