Jump to content
  • 0

Passing Paramaters Containing Amperand (&)


joscetre

Question

I have a list of names which include an ampersand (eg: "Jack & Jill"), which I am using for users to identify themselves as part of their logon. I want to be able to pass the field value as a parameter within a string, but it only passes the part of the field before the ampersand (eg: "Jack"). Is there a way to pass a parameter that contains ampersands within the field values?

Link to comment
Share on other sites

18 answers to this question

Recommended Posts

  • 1
On 7/28/2021 at 10:06 AM, LittleMsGinger said:

Hi all, 

Instead of using script to pass parameters with '&', you can just use simple formula to convert or replace it in its corresponding URL encoded character. 

For more details, you may refer to this post:

Posted July 28

  On 7/28/2021 at 9:41 AM, 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.

Expand  

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: https://www.degraeve.com/reference/urlencoding.php

Link to comment
Share on other sites

  • 0

Very good question. Browsers recognize & as a reserved character (parameter separator) in a query string so if your data includes & you need to encode it. You can use a Java Script to encode the special characters, here is a sample script that you can put into your HTML block where you define your query string.

 <script>

document.write("[url="mysite.com?param="]link[/url]") ;

</script>

Best,

Bahar M.

Link to comment
Share on other sites

  • 0

Thanks, Bahar. It looks like it should work, but the code you quote does not seem to pass the parameter. Here is my specific version:

<script>
document.write("[url="http://b6.caspio.com/dp.asp?AppKey=ddae2000c2f0bb5fd8424eba8ca5?Mailing_Names="]link[/url]") ;
</script>
I know that [@field:Mailing_Names] contains the correct data. When I right-click on the link to view its properties, it only shows as far as Mailing_Names=, and does not include the value. I'm wondering in the format it not quite correct. Any advice?

Thanks

Trevor.

Link to comment
Share on other sites

  • 0

Jason & Bahar, thanks for the correction, not sure how I missed that.

But unfortunately it's still not quite right. I'm trying to pass the parameter value "Trevor & Justine Joscelyne". The link does not add the parameter value, but looks like this:

"http://b6.caspio.com/dp.asp?AppKey=ddae2000c2f0bb5fd8424eba8ca5&Mailing_Names="

However, I tried changing the position of the second single quote in the script like this:

<script>
document.write("[url="http://b6.caspio.com/dp.asp?AppKey=ddae2000c2f0bb5fd8424eba8ca5&Mailing_Names="]link[/url]") ;
</script>
Which results in this link, which looks more hopeful:

"http://b6.caspio.com/dp.asp?AppKey=ddae2000c2f0bb5fd8424eba8ca5&Mailing_Names=Trevor%20%26amp%3B%20Justine%20Joscelyne"

But it's still not being recognized by the datapage that's receiving it. Question - is that the way the link should look, or is something else wrong?

Link to comment
Share on other sites

  • 0

Hello,

I created a small project in which i want to pass value on next page in URL on button click in caspio. value are pass in URl like below

"offer_created.php?id=11"

but I don't know how to access that value from url in next caspio form .

Please sent me solution ASAP.

Link to comment
Share on other sites

  • 0

You can try this code, executing the parameters with ampersand(&) in values.

<script> 
var v_name = "[@field:yourfieldname]"; 
v_name = v_name.replace(/&amp;/gi,'%26');
v_name = v_name.replace(/&/gi,'%26'); 
document.write('<a href="www.yourwebsiteurl.com?yourfieldname=' + v_name + '">View Details</a>'); 


</script>
 

Link to comment
Share on other sites

  • 0

document.write is not supported on pages anymore. Instead you need to create a div and write in that div:

 

<div id="myurl"></div>
<script>
var v_name = "[@field:Mailing_Names]" ;
v_name = v_name.replace(/&/gi,'&');
document.getElementById('myurl').innerHTML ="[url="http://b6.caspio.com/dp.asp?AppKey=ddae2000c2f0bb5fd8424eba8ca5&Mailing_Names="]link[/url]";
</script>

 

Link to comment
Share on other sites

  • 0

Hello,

 

If you want to pass your parameter via query string , you may want to consider a different approach I came up with.

 

In a Tabular Report Record:

1.) Create an HTML Block

2.) Disable the HTML Editor from the Advanced Tab

3.) Paste the code below then replace the variables corresponding to your need.

<a id="link-[@cbRecordIndex]" target="_blank"> [@field:name] </a>

<script>

  var protocol = 'http://';
  var base_url = 'www.google.com';
  var param = 'param';
  var qStringVal = `[@field:name]`;

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

</script>

 

Hope this helps.

Regards,

DN31337

Link to comment
Share on other sites

  • 0

I was trying to pass a parameter that contains an ampersand and I came across this forum post. None of the provided solutions worked for me. I understand that document.write is no longer supported in Caspio and I tried both @MayMusic's and @DefinitelyNot31337's posts, still no luck.

I tried the following code as suggested. I can now receive the "&" symbol but it is displayed as "&amp". Is it expected? Is there a way to pass the "&" without adding "amp" text?

Quote

<a id="link-[@cbRecordIndex]" target="_blank"> [@field:name] </a>

<script>

  var protocol = 'http://';
  var base_url = 'www.google.com';
  var param = 'param';
  var qStringVal = `[@field:name]`;

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

</script>

 

Link to comment
Share on other sites

  • 0
On 3/5/2021 at 4:18 PM, Jess147 said:

I was trying to pass a parameter that contains an ampersand and I came across this forum post. None of the provided solutions worked for me. I understand that document.write is no longer supported in Caspio and I tried both @MayMusic's and @DefinitelyNot31337's posts, still no luck.

I tried the following code as suggested. I can now receive the "&" symbol but it is displayed as "&amp". Is it expected? Is there a way to pass the "&" without adding "amp" text?

 

instead of `[@field:name]` , try something like  var qStringVal = document.getElementById("link-[@cbRecordIndex]").textContent ; or  document.getElementById("link-[@cbRecordIndex]").innerText;

 var qStringVal = `[@field:name]`;

 

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...