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!

#83813

Please Log in or Create an account to join the conversation.


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
#83905
The following user(s) said Thank You: Adam Brennick

Please Log in or Create an account to join the conversation.


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

#84111

Please Log in or Create an account to join the conversation.


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
#84127
Attachments:

Please Log in or Create an account to join the conversation.


Time to create page: 0.329 seconds
Powered by Kunena Forum

WORLD-CLASS SUPPORT

We are here for you every step of the way. Turn to our support with any questions you might have about our products and services. Our experienced customer care team is available to help you as fast as we possibly can.

Contact us