Passing Value to Hidden Field via URL
Adam Brennick created the topic: Passing Value to Hidden Field via URL
Is there a way to pass a value to a field (preferably hidden) via URL? I have a form and I want to be able to give individual URLs to partners so when they refer someone they can provide their URL and it will fill that hidden field with an identifier for that partner. Like:
Form URL -
site.com/myform.php
Partner URL -
site.com/myform.php?field=identifier
Not sure if this is possible or if there is another option besides creating individual forms for each partner. I want to avoid a referral check box with text field, but if that is the only way then so be it.
Thanks!
Please Log in or Create an account to join the conversation.
-
Topic Author
- Adam Brennick
- Offline
- Fresh Boarder
-
- Posts: 2
- Thank you received: 0
6 years 7 months ago
Agapi G. replied the topic: Passing Value to Hidden Field via URL
Hello Adam!
Thank you for posting your request!
You can achieve this by writing a few lines of Javascript code on Form Options > Javascript tab. Please firstly add these two lines inside before_load() function:
value = getParameterByName('field');
jQuery("#hidden_id").val(value);
Afterwards add the following code outside of all built-in functions in the editor:
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
Let us know if it works.
Thank you! Have a wonderful day!
Kind regards,
Agapi G.
Web-Dorado team
Please Log in or Create an account to join the conversation.
6 years 6 months ago
Adam Brennick replied the topic: Passing Value to Hidden Field via URL
So I got the query string data working, but it is not updating the Hidden Field. It will pass to a simple text field but if I try to pass the data to a Hidden Field in the form it will not take. Any suggestions?
Thanks!
-Adam
Please Log in or Create an account to join the conversation.
-
Topic Author
- Adam Brennick
- Offline
- Fresh Boarder
-
- Posts: 2
- Thank you received: 0
6 years 6 months ago
Agapi G. replied the topic: Passing Value to Hidden Field via URL
Hello Adam!
There should not be any difference between regular text input and hidden field. Could you please double-check the ID of your hidden field? Try to copy it from frontend of your form by inspecting the element. I am posting a screenshot below.
Let us know it works this way.
Thanks! Have a good day!
Kind regards,
Agapi G.
Web-Dorado team
Please Log in or Create an account to join the conversation.
6 years 6 months ago