Pre-filled Field from link

Gregory Pirault created the topic: Pre-filled Field from link

Hello,
First, i would like to apologize if my english is not perfect... I'm french B) So i hope you'll understand my question :)

I would like to link articles to forms with a pre-filled field.

I will try to explain B)

My website is an artists gallery.
Customers choose an artist and consult his works (one item per work).
Since each work, they have the opportunity to ask a question about it from a link directing them to a form (one form per artist).

My request is whether it would be possible to have the field "Item Title" pre-filled when the user accesses the form from this link.
The title of the article is the name of the work.

Thank you.

#58589

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


Agapi G. replied the topic: Pre-filled Field from link

Greetings, Gregory!

Thank you for posting your request!
Unfortunately Joomla Form Maker does not have the functionality to pre-select a field based on referrer source.

However, if your articles are not many, you can perhaps write a few lines of Javascript code with if/else if statements, and set the value of Item Title field pre-selected.

You will need to add your code to Form Options of your form, Javascript tab.
Thank you!


Kind regards,
Agapi G.
Web-Dorado team
#58683

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


Gregory Pirault replied the topic: Pre-filled Field from link

Thank you for your reply :)

I understand that the function is not integrated in formaker and that my request is special

The proposed solution seems to be cool.
Would it be possible to give an example to code (for one or two items).
I'm not an expert in JavaScript ...

My site contains about 50 items, do you think this is possible?

Thank you

#58759

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


Agapi G. replied the topic: Pre-filled Field from link

Hi Gregory!

It is, of course, possible, but the code will be large and messy. It might even slow down your form page loading.

Let me suggest you another way of doing this, which will just require a few lines. Instead of filling in the name of the artist, you can fill in the referrer link, where the submitter was redirected from. Here's how you can do that.

Please add a text input field to your form and get its ID from the frontend of your form page. Afterwards add the following Javascript code to Form Options > Javascript tab:

var referrerURL = document.referrer;
jQuery('#text_field_id').val(referrerURL);

Please make sure to replace text_field_id with the text field's exact ID, keeping the # sign in the beginning. Let me know if this works for you.

Thank you!


Kind regards,
Agapi G.
Web-Dorado team
#58815

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


Gregory Pirault replied the topic: Pre-filled Field from link

Hi,

Sorry for my silence... The last week has been busy.

I've tried your solution and it works like a charm, Thanx for that :)


But unfortunately, i'm not sure that my client will be comfortable with that...

Are you sure that i couldn't get the document.title or the page.title or the last part of the url (artworkname.html) instead of the full url, using the "document.referrer" :oops:

It will be perfect for me.

Thanx a lot for your help

#59923

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


Agapi G. replied the topic: Pre-filled Field from link

Hello Gregory!

We are very glad the code worked on your website!
There are a couple of ways of getting the referrer partly as you wish to. Please see the following to lines:

jQuery('#text_field_id').val(referrerURL.substr(referrerURL.lastIndexOf("/")));
jQuery('#text_field_id').val(referrerURL.replace("unnecessary_url_part", ""));

Please try one of them each time and see which one works for you better. For the second code, please replace unnecessary_url_part the actual part of the link, which you don't want to display.

Thank you!


Kind regards,
Agapi G.
Web-Dorado team
#59949

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


Gregory Pirault replied the topic: Pre-filled Field from link

After searching, I finally found a way to make that work perfectly.

With your help, I decided to make use of the url and cut it.

The base url of a work is:
www.MyWebsite.com/oeuvres-the-artiste/75-work.html

The code i used:

// Occurs before the form is loaded

before_load function ()

{

var = referrerURL document.referrer;

lartiste var = '';
LOEUVRE var = '';

var = referrerURL.split the URL ( 'http://www.MyWebsite.com/');

the URL the URL = [1];
lesinfos lurl.split = ( '/');

lartiste lesinfos = [0];
LOEUVRE lesinfos = [1];

lartiste lartiste.replace = ( 'oeuvres-', '');
LOEUVRE loeuvre.replace = ( '' 'html.');

//jQuery('#wdform_7_elementform_id_temp').prop('readonly','readonly ');
jQuery ( '# wdform_7_elementform_id_temp') val (LOEUVRE + 'of' + lartiste).

}


Finally, the field is filled as follows:
75-work of the artist :cheer:


As you see in the code, I tried to ensure that we can not modify the content of the field, but without success ... :blink:

I've you got a last idea for that?

Again, thank you for your help B)

#60145

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


Agapi G. replied the topic: Pre-filled Field from link

Hi Gregory!

We are very glad you have achieved the functionality you were looking for! As for making the field readonly, please edit it and scroll down to Additional attributes option.

Set both of the parameters to readonly as the following:

Name: readonly
Value: readonly


Let me know if this works on your field.
Thank you!


Kind regards,
Agapi G.
Web-Dorado team
#60209

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


Gregory Pirault replied the topic: Pre-filled Field from link

Hi,

The "readonly" attribute works but...

The user can't write but if he "clic" on the field, my prefilled value disapear. :blink:

#60251

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


Agapi G. replied the topic: Pre-filled Field from link

Hey Gregory!

That actually shouldn't be happening. Could we please take a look at the problem? Please submit a support ticket by sending an e-mail to [email protected]. Kindly grant us temporary admin access to your website.

Our development team will provide a solution as soon as possible. Also please make sure to indicate the link to this forum topic in your e-mail.
Thanks in advance!


Kind regards,
Agapi G.
Web-Dorado team
#60277

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


David replied the topic: Pre-filled Field from link

Hi

I am trying to include the referrer URL into my form so that I can see the link they came from to arrive at my form.

I have tried the above, I've added a text field and taken the ID and added it to the Javascript, I'm not sure if I have put the code in the right place though, could you confirm how my Javascript should look and how to get make sure it arrives in the submission email?

My Javascript currently looks like this:

// Occurs before the form is loaded

function before_load()

{

var referrerURL = document.referrer;
jQuery('#wdform_1_element24').val(referrerURL);


}



// Occurs just before submitting  the form

function before_submit()

{



}



// Occurs just before resetting the form

function before_reset()

{


}

#75721

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


Agapi G. replied the topic: Pre-filled Field from link

Hello David!

Thank you for posting your question!

Could you please try adding your code to before_submit() function? In case it doesn't work, please take it outside of the built-in functions and write in jQuery(document).ready() instead. Here's an example:

jQuery(document).ready(function () {
    var referrerURL = document.referrer;
    jQuery('#wdform_1_element24').val(referrerURL);
});

Let me know if it works.
Thank you! Have a wonderful day!


Kind regards,
Agapi G.
Web-Dorado team
#75763

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


Time to create page: 0.241 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