Jump to content
  • 0
TroubleShooter

Passing field values with ampersand (&) over query String

Question

Hello

 

Is it possible to pass a field with special charaters such as ampersand over query string?

I was trying to pass a field value to another webpage but it seems to break after the & character. Is there something we can do to receive this onto the other page.

 

Any help is appreciated.

 

many thanks,

TS

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello @TroubleShooter,

 

The reason why the ampersand symbol is being cut is because Caspio renders the link literally. In this example:

<a href="https://www.google.com?myParameter=[@field:someField]"> Link </a>

 

If "someField" evaluates to "Some Value & Another Value" then the mark-up would result to 

<a href="https://www.google.com?myParameter=Some Value & Another Value"> Link </a>

 

This is when urlencoding comes into play. What this does is substitutes the special characters in a standard HTML format which interprets characters a different way.

 

You may try using my code snippet below.

1.) Just replace the link ID with the id attribute of your link.

2.) repeat the addParameter function as needed. The first argument is your parameter name, and the second argument is your field value.

<a href="#" id="link-1">MyLink</a>

<script>
// DO NOT TOUCH FROM THIS POINT
var params = []; 
addParameter = function(qs, val){
  params.push(`${qs}=${encodeURIComponent(val)}`);
}
//UP TO THIS POINT

var link_id = "link-1";
var base_url = "https://SomeDomainFrom.caspio.com/dp/926560as124321324dasd00a6523f123123624543123423fc0453b9093";
addParameter('boo', '[@field:SelectedAction]'); //repeat as needed
addParameter('far', '[@field:SelectedAction]');


  
// DO NOT TOUCH FROM THIS POINT
var queryString = params.join("&");
document.querySelector(`#${link_id}`).href = `${base_url}?${params.join("&")}`
//UP TO THIS POINT


</script>

 

Works for me.

 

-DN31337!

Share this post


Link to post
Share on other sites
  • 0

I need to ask another question about this. I don't know Javascript, but my links are not working because I have # in my addresses (for Apt Numbers).

Could you explain how I can escape # characters. I understand it's %23 and that I have to use encodeURIComponent().

This is my link

 

<a href ="[@app:URL_2]?cid=[@field:ID]&fn=[@field:FirstName]&ln=[@field:LastName]&a1=[@field:Address1]&a2=[@field:Address2]&c=[@field:City]&z=[@field:ZipPostalCode]&p1=@field:PrimaryPhone]&p2=[@field:SecondaryPhone]&da1=[@field:Address1]&da2=[@field:Address2]&dc=[@field:City]&dz=[@field:ZipPostalCode]&dp1=@field:PrimaryPhone]&dp2=[@field:SecondaryPhone]&r=[@field:Route]&dn=[@field:DriverNote]&pa=[@field:PhysicalAssistanceComment]&rc=[@field:Rate_Cd]&m=[@field:MobilityDevice]&cbResetParam=1">[@calcfield:1#]<a>

I am finding # in a1, a2, d1 d2.  I don't understand how to replace the  # in the code above.

Thanks for any help

 

Edited by Tonie
Found a problem, it's only working on the first line of a report, the later links are not working.

Share this post


Link to post
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...