I am building a form where the user does the following:
Goal
Assemble these values into a valid URL.
Ex. www.website.com?utm_campaign=field1&utm_source=field2&utm_somethin=field3
Now, at the moment I have each individual field getting entered into its own column in the data source. I do not assemble the URL and enter it into its own column although I am considering this. I do not account for spaces in the field values either. For example, utm_campaign might be something like "Fall Sale Event". What gets entered into the data source is "Fall Sale Event". The problem is that is you try and assemble a URL you have spaces. What should be there in place of the spaces is %20. How would I handle these spaces? Do I enter the %20 into the data being entered into each column of the data source? Do I assemble the URL and add the %20 at that point and then write the assembled URL to the data source? Or do I assemble the URL in a gallery and deal with the spaces there? And, of course, how do I handle swapping out the spaces?
Ultimately, this would go for any encoding that needs to be done. Not just spaces.
That's what I was actually noodling on doing. Doesn't even need to be hidden necessarily.
You could actually chain the Substitute functions if you had only a couple of conditions (i.e. Spaces and perhaps ampersands or something). But, after that it gets just about a unwieldly.
The other thing you can do is establish a label (hidden) on the screen that has that formula in it to combine the URL with its encoding. Then for writing the record or emailing, you can just refer to the Text property of that label.
It will be dynamic (i.e. change based on the record) and will be readily available for where ever you need it in your app.
Good point. I think there may be some other characters that need to be encoded but I'm not completely sure. It's probably best to capture all of them instead of just singling out spaces.
As for deciding whether to pre or post encode of the URL I haven't really decided. The app is likely the only thing that is going to use the URL although I can see emails being sent as part of the process. It might be easier to just grab a single column from the data source in that case instead of trying to build the final URL on the fly. All of the 'pieces' of that final URL would still live in the data source in their own individual columns alongside the column with the fully built and encoded URL. If I go this route of building the URL before writing it to the data source is the process the same? Instead of grabbing values from the data source I am grabbing the values from each field of the form?
Also...in reading back, you only seemed concerned with the spaces. EncodeUrl will obviously encode the spaces and any other special characters, but if ONLY spaces are your concern, then you could consider something like this:
Substitute(yourFinalUrl, " ", "%20")
This would replace just the spaces with the "%20" needed.
Yeah, it's not optimum, but as you noted, the EncodeUrl function (if you feed it the whole url) will encode everything where you just want individual parameters encoded. So that formula is about the best you've got.
Certainly if this is a one time creation url (meaning when you are say, creating or saving a record), then I would consider creating and saving the encoded url for the future. But if your app will be the only thing that really accesses the data, then it's just as easy to do it when selected.
Either way works, just depends on your design.
That could be a little unwieldy to manage especially if there are numerous parameters which could happen but I suppose it is an option.
Now, I've been wondering do you encode those parameters and then write them to the datasource or do you extract the parameters from the datasource and encode them for rendering?
Yes, I wasn't suggesting preforming the EncodeUrl function on the entire URL, only on the parameters of the URL.
Sorry I did not make that clear.
i.e.
"www.website.com?utm_campaign=" & EncodeUrl(field1) & "&utm_source=" & EncodeUrl(field2) & "&utm_somethin=" & EncodeUrl(field3)
Anyone else have some ideas on ho to solve this problem? EncodeURL seems like to broad of a solution that is likely going to cause issues. I have one particular vendor that would be using these URLs that specifically says not to encode certain symbols.
This works to a certain degree. Not all characters need to be encoded. For example I wouldn't want to encode '?', '&'; and '='. I could put an encode on every single parameter but that would be a mess. Maybe encode the values before/as they get submitted to the data source? Or is there some logic that will only EncodeURL specific characters?
Perhaps a Substitute or Replace might be an option?
Any ideas?
You will want to utilize the EncodeUrl function. This will do the conversion for you.
I hope this is helpful for you.
WarrenBelz
146,743
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,089
Most Valuable Professional