How to use a [show_param] value as a URL parameter?

By: Michael Clark | Asked: 01/31/2023
ForumsCategory: Code HelpHow to use a [show_param] value as a URL parameter?
Michael ClarkMichael Clark asked 2 years ago
Scenario, in a View:     Using [frm-set-get param=total_things] to wrap a simple [frm-math] calculation. Works like a charm as [show_param param="total_things"] displays the resulting value as intended.      I need to use that value as a URL parameter. Tried
<a href="https://myurl.com?toth=[show_param param="total_things"]">My Total Things Link</a>
..but that doesn't work. The resulting link just has the shortcode and not the value, as displayed in the View.   How can I get the value displayed by the [show_param ..] shortcode to use as a URL parameter?
1 Answers
Rob LeVineRob LeVine answered 2 years ago

I think you want:
<a href="https://myurl.com?toth=[get param="total_things"]">My Total Things Link</a>

 

Michael ClarkMichael Clark replied 2 years ago

Thanks for the suggestion, Rob! Since I'm using frm-set-get inside a view, to save a complex value (the result of a frm-math calculation, get-param won't retrieve the parameters set by the frm-get-set, so I'm using the show_param shortcode, as noted in the docs here:

https://formidableforms.com/knowledgebase/set-values-to-be-used-in-custom-displays-or-default-values/#kb-additional-options

Michael ClarkMichael Clark replied 2 years ago

The value shows up in the View just fine.

Bobby Clapp replied 2 years ago

Can you use the simple shortcode to get the value and put it within an element with a CSS class or ID that will be hidden and then capture the value from the class/ID with JS and then hook that to create your link?

Michael ClarkMichael Clark replied 2 years ago

<p>Hey Bobby. As always I appreciate the creativity and depth of knowledge in the insights you share. Your potential workaround/solution may work. Unfortunately, once we get into the realm of using JS to grab a value based on a CSS class or ID, I'm at a loss. Even moreso when thinking about how to use that value in as a parameter in a link.</p><p> </p><p>Let me see if I can take a stab at it. First set my variable, in this case, "toth", and use the CSS ID to get it:</p><p> </p><p><span id="toth">[show_param param="total_things"]</span></p><p> </p><p>var nm = document.getElementById("toth").innerText;<br />console.log(nm);</p><p> </p><p>But after that, I'm at a loss. I can run the above code in JS Fiddle, replacing the shortcode with a value and log that value to the console, it works but I can't get it to work in my view. Help me make magic? :)</p>

Bobby Clapp replied 2 years ago

The view doesn't grab the value with the code that works in JS fiddle or you can't figure out how to create the link with the new set variable?

Michael ClarkMichael Clark replied 2 years ago

I can't figure out how to set the variable in js in my view or use it as a parameter in my link.

Do I create a in my view and set the var in there? Once it's wherever it needs to be, can I just reference it in building the link, just like a short code (without brackets)?

Not too proficient here, but I'm totally grateful to learn!

Michael ClarkMichael Clark replied 2 years ago

It seems like a pretty straightforward thing, to parse a value from text inside a CSS ID, and the then use that value as a URL parameter, but after hours on stackexchange, I'm no closer than getting the console in js fiddle to log the value correctly. :/

Bobby Clapp replied 2 years ago

Add the script into your view within script tags. I usually put this type of code in the after content. You'll then need something like this to grab the CSS ID of the place where your link will go, something like this:

https://paste2.org/fBAODwE4

Michael ClarkMichael Clark replied 2 years ago

This looks great. I'll give this a go. And report back.

Michael ClarkMichael Clark replied 2 years ago

Bobby, you provided a great script and it got me *way* closer. Since I've got to use FF shortcodes referencing other fields as additional URL parameters, this won't work. Even if I got it to work, not sure how sustainable it'd be. Really appreciate your help on this. If anybody needs to grab a value from a show_param shortcode to use as a single URL parameter, modifying this snippet should work for you:

https://paste2.org/PwbL2Pgm

let nm = document.getElementById("tm").innerText; //surround the shortcode in a span with an id and call that id here
let text = "Click For The Things"; //the text of the link or button
result = "" + text + ""; //build the link with the shortcode value and the link/button text value
document.getElementById("applink").innerHTML = result; //output the resulting link to an element with an id of your choosing

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right