Jump to content

Can a text field be pre-filled based on a URL parameter?

Recommended Posts

I'm using the Wells template and would like users to be able to click a link in a photo caption and be taken to a form where they can inquire about the image and the image number is pre-filled into a text field so the user doesn't have to remember what number to fill in there. In other words, a link looking something like this:

http://xyz.com/contact?img=20150314_0048

The link goes to the "contact" page with a form where a text field for "img" is pre-filled with "20150314_0048".

When I do a view source of the contact page, I see the text field has an ID of "text-yui-(string of numbers)-field" which is perhaps what I would need to reference in place of "img" in the URL link on each image? I tried that and nothing was pre-filled. Any suggestions?

Link to comment
  • Replies 5
  • Views 13.4k
  • Created
  • Last Reply

Not without the developer platform, and not without a pretty advanced understanding of json/javascript...and really you would need access to the database to define this and that. Which is something I have yet to figure out how to do! I don't think the developer platform opens up access enough to the data needed. I could be wrong though!

Also anytime you see a "yui" and a string of numbers, you need to know those change dynamically on each page load.

I run the Squarespace Guru blog (www.sqsp.guru) and host the Squarespace Guru podcast.

Link to comment
  • 9 months later...

you can do it this


<input type="text" name="uniquecode" id="uniquecode" style="width: 350px;" class="input" value="" placeholder="Copy-Paste your Code"/>

<script type="text/javascript">

window.onload=function(){ 

function querySt(ji) {

hu = window.location.search.substring(1); 
gy = hu.split("&");

for (i=0;i<gy.length;i++) { 
ft = gy[i].split("="); 
if (ft[0] == ji) { 
return ft[1]; 
} 
} 
} 
var uc = querySt("uc");


if( uc==null){ 
}else{ 
document.getElementById('uniquecode').value = uc; 
} 
} 
</script>

then I can input an URL such as:

http://www.xyz.com/page?uc=sometextformyform

This work but I am looking to do that with squarespace product / popup forms if anyone knows?

Link to comment
  • 11 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.