Create URL Encoded String

Hi.
I have a case where I need to set a URL string in an input by creating it dynamically.
I need this URL to be encoded, i.e. for this case, SPACES should get replaced by %20.

txtDataHookURL.setValue('http://localhost:210/api/Comms?name='+varCampaignName.value);

The campaign name variable here can have a value say some random value.
So, the final string I need should look like:
http://localhost:210/api/Comms?name=some%20random%20value

There is a replace formatted for string values, but that would mean I have to configure all possibilities. There can be any other such special character which requires encoding.
Looking to get an output similar to this in JS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

Hi @sid as an alternative i use base64 encoding/decoding which serves the same purpose, would that work in your case?

Actually, when looking closer, some base64 characters (+, /, =) might not work in the URL

Yeah, unfortunately, that would not work.

Found this feature request: URL encoding
@Teodor Can you please confirm if there is no way to do this in Wappler at present?

URL encoding formatter has been integrated in Wappler 2.6.4

@Teodor, I cannot find a url encode/decode option in the data formats menu… can you tell me what it is in code please?

I’m using version 3 beta 3.

1 Like

But I’m on the client side… is it only available on the server side?

@Antony what are you trying to do exactly? Why do you need url encoding on the clientside?
Please explain your idea in details, as you might be doing something wrong.

I’m passing an affiliate marketing link to the user, and it includes a random code which could itself include a character that needs encoding.

But no worries, I can pass the url encoded random code from the server side.

It should be done there anyway.

1 Like