Jump to content
  • 0

Passing parameters containing an ampersand


Empowering

Question

I am trying to solve an issue with a parameter with an ampersand in the value being passed to a url.  I did some research on this forum and found an answer that gets me closer, but still doesn't quite work.  

<a id="link-[@cbRecordIndex]" target="_blank"> Worksheet </a>

<script>

  var protocol = 'http://';
  var base_url = 'xxxxxxx.caspio.com/dp/d86e500027f87dfc582049xxxxxx';
  var param = 'Opportunity_Name';
  var qStringVal = `[@field:Opportunity_Name]`;

  document.querySelector('#link-[@cbRecordIndex]').href = `${protocol + base_url}/?${param}=${encodeURIComponent(qStringVal)}`;

</script>

The parameter [@field:Opportunity_Name] is "Munis & EnerGov".  The resulting url from the code above is :https://xxxxxxxx.caspio.com/dp/d86e500027f87dfc582049xxxxxx/?Opportunity_Name=Munis%20%26amp%3B%20Energov"  and the parameter that is received to the other datapage is "Munis &amp; EnerGov".  So, the & is coming in, which is great, but how do I get rid of the "amp;"?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 2

Hello!

Instead of using script to pass parameter with ampersand, you can just use a simple formula. You need to change the ampersand to URL encoded character.

Add Calculated Value/ Calculated field and use: replace('[@field:FIELDNAME]','&','%26')

Then, pass this field as parameter instead of the actual field. Lastly, hide this field so it will not be visible in the form.

https://howto.caspio.com/tech-tips-and-articles/common-customizations/how-to-hide-fields-in-datapages/

 

Hope this helps.

Link to comment
Share on other sites

  • 2
25 minutes ago, LittleMsGinger said:

Hello!

Instead of using script to pass parameter with ampersand, you can just use a simple formula. You need to change the ampersand to URL encoded character.

Add Calculated Value/ Calculated field and use: replace('[@field:FIELDNAME]','&','%26')

Then, pass this field as parameter instead of the actual field. Lastly, hide this field so it will not be visible in the form.

https://howto.caspio.com/tech-tips-and-articles/common-customizations/how-to-hide-fields-in-datapages/

 

Hope this helps.

Hi!

Just to add on this, I have found a documentation containing the list of URL encoded characters that you can use as a reference: URL Encoded Characters (degraeve.com)

Link to comment
Share on other sites

  • 0

Hello @Empowering,

 

It might be because your field [@field:Opportunity_Name] contains a literal &amp; value. This usually happens when you submit on a Rich Tex Editor.

 Try checking your DataSheet if this is the case. If it is, you may need to run the function over to some HTML Entity decoder like this one [link].


You may also try checking this solution. Which, I think, the output will be the same. If it is, then it is likely that my assumption above is true.

 

Link to comment
Share on other sites

  • 0
On 7/29/2021 at 12:41 AM, cheonsa said:

Hello!

Instead of using script to pass parameter with ampersand, you can just use a simple formula. You need to change the ampersand to URL encoded character.

Add Calculated Value/ Calculated field and use: replace('[@field:FIELDNAME]','&','%26')

Then, pass this field as parameter instead of the actual field. Lastly, hide this field so it will not be visible in the form.

https://howto.caspio.com/tech-tips-and-articles/common-customizations/how-to-hide-fields-in-datapages/

 

Hope this helps.

This is a champ solution as this resolves the &amp; issue but I have another problem. It now cuts the word next to the %26 even if its on the URL when using it as an external parameter.

Link to comment
Share on other sites

  • 0
On 6/10/2022 at 7:43 AM, Lepidoptera said:

This is a champ solution as this resolves the &amp; issue but I have another problem. It now cuts the word next to the %26 even if its on the URL when using it as an external parameter.

I solved this by using JavaScript:

var company_name = [@Company_Name]; //Even though the original value is "Family & Friends"
//When you assign it to a variable it becomes "Family &amp; Friends"
company_name.replace("&amp;", "%2625");

Supposedly the ampersand is the 25 and 26 is the modulo/percent symbol.  Reason is because when you pass the %25 alone as query parameter value, it gets converted into a standalone "&" which results in the browser thinking you were adding a new line of query parameter. To get around this you have to add a percent symbol in UTF-8 format "%26" and concatenate together with "25". So that when the browser url reads this the %26 will get translated as "%" which results to "%25". Voila, you have an ampersand as value of query parameter without breaking it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...