Custom validation and data conversion

I need to perform some data conversion when performing update and insert transactions into a database. As a simple example, I need to store a numerical value into the database, however I want the user to be able to enter hexadecimal data. I could do this on the client side with a simple JS parseInt call, but I’ve not worked out how to call this.

On the display side, Wappler provides custom formatters, but I’ve not seen something similar for converting UI data to a format required for the database.

Additionally, if this can be done in PHP that would also be fine. I found the following post which I think is looking for similar functionality to call custom functions but haven’t seen that anything is implemented.

I’d welcome any thoughts on this - it seems like this must be possible so I’m sure I’m just missing the obvious.

Well that is why we have formatters. So you can convert, transform or format any values when you use them.

So just use the magic wand icon next to the field in the data picker.

Can you explain where this is done when inserting data into a database?

In the above example, I have produced a formatter that prints the data that comes FROM the database and displays it in the UI in hexadecimal. That is set in the Dynamic Attribute -:

However what I’ve not worked out is how to do it the other way - ie how to format the data taken from the input before it is sent to the server via the server connect action.

When you create a server action with database updates on it, there you pick the fields and their values. So you can format them there. Server side

Thanks - so you mean this is added in the query editor?

I tried using the standard php hexdec as below, but that throws a null insertion error so I’m assuming I’m still not getting what your saying (sorry).

I tried both hexdec({{$_POST.newmanufacturer_reference}}) and {{hexdec($_POST.newmanufacturer_reference)}}. Can you provide a reference for this?

Thanks.

No, you just need to double click on the column and call the data picker:

then call the server formatters:

Then choose the formatter you need, we have quite a few:

Thanks - I’d missed that there was a formatter for hex already, so I picked a bad example in that respect.

What I really wanted to know if there is a way to add custom formatters and validation - either in PHP server side, or in JS client side. I’ve added a custom formatter for presenting data in the UI as I showed earlier - but I need to work out how this is handled when taking data from the UI and converting it for sending to the database (trust me - your existing formatters will not cover all the data formats I need to cope with).

1 Like

@George can you please provide some hints on how to run a custom PHP function / formatter. We ultimately have a legacy formatter that takes the output from a query (as a PHP object) and formats this up in various. It’s extremely complex and I very much doubt that it can be done in the visual tool (one of these formatters is currently 1300 lines of PHP!).

Is this something that can be done? Alternatively, I can create a PHP page to do this, but I would like to re-use the queries that I’ve generated in Wappler, so if there’s a way to call these and return a PHP object, that is also fine with me. One of these two options is I think necessary - unfortunately I’ve not found anything on the forum or the docs about this - mostly the answer is that everything can be done with the visual design tool, which unfortunately is not the case unfortunately.

@George or @Teodor is there any way we can progress with this? We need to have a way to call legacy code - or have a way to call Server Connect queries from legacy code.

Thanks. I’m aware of this, but it really doesn’t fulfil the general need to be able to run external libraries in PHP - preferably within the flows. Unfortunately without this Wappler is unable to meet our needs so I’ve had to cancel the subscription and we have to unfortunately look elsewhere.