How to get logarithm of a value on the server side?

Hello,

I am new to Wappler and the community. I would like to know how to calculate a logarithm value of a post value($_POST.field1) sent from the form.

Btw, I am using php server side.

Thank you.

Hi.
Welcome to Wappler.
The built-in formatters/components in Wappler do not have any log() functions.
You can create a custom formatter or extension in PHP and use that.
Ref: Wappler Extensibility - Writing Custom Modules and Formatters for Server Connect

Hello.

Thank you for your quick response.

I have created the extensions/server_connect/formatters/number.php.

Then I have created a simple API file to test the extension.

While I call the API file, I am getting the response as “null” as shown below:

Is there something that I am missing?
Will Wappler automatically add the extensions folder or do I have to add it somewhere in the settings?

logValue = formatter_log(number)
you are calling just log(number)

image

Try returning just $val, and check if the value is getting converted to string.
Also, you can just do return 123; to test if extension is working as expected.
I haven’t used the PHP log() function, so you will have to experiment a little.

Debugging PHP errors is a bit weird, last I used it years ago. :sweat_smile:

Oh… I see the problem.
You have created a formatter. Formatters are functions to be called on some value/variable.
The value is passed implicitly.

EG: you cannot call log(0.2). You need to call 0.2.log()… which obviously is not possible for a number…
So an alternate would be to set a variable with value 0.2, then call var1.log().

2 Likes

That is how custom formatters in Wappler work.
formatter_ is a required suffix. No needed when calling the formatter.

1 Like

Yeah! I’ve already used formatters…
My mistake
I’m sorry guys

Comprementig Sid, “0.2”.log()

Thank you. This is working. Really appreciate your help.

1 Like