Support » Plugin: Forminator - Contact Form, Payment Form & Custom Form Builder » Hidden field – Custom Value – how to get a value

  • Resolved alena353

    (@alena353)


    Hello!

    I’ve got a table of different courses. Each course has an “Enroll” button. When the button is clicked, it triggers the pop-up to appear. This pop-up has a contact form that I made with Forminator plugin. I added a hidden field with a “Custom Value”as a Default Value.

    So, I want to do this: when the button of the course is clicked, the value of this button (which is the name of the course it’s assigned to) would automatically get inserted into that hidden field, so I would know what course exactly a user would like to enroll.

    That’s what my button looks like: <a class="popmake-2710 course-info__enroll blue-enroll-link" href="https://www.aviatour-expert.ru/kursy-i-tseny/?the-course=the-course-name">Enroll</a>

    So, the class (“pop make-2710…”) allows the pop-up with the contact form to appear. In the “href” I set the-course value to the name of the course: I used “the-course” in the “Custom Value” of the Hidden Field in the Forminator form, and “the-course-name” is what I want to get in this hidden field when the form is sent by user.

    I tried to add this code – https://gist.github.com/wpmudev-sls/dc9ab640bf675b274ff12acfba3965db – but it didn’t work. Wnen a user sends the form, the value of this hidden field just comes out as “the-course”.

    Could you, please, help me to figure out what I’m doing wrong here?

    • This topic was modified 2 years, 5 months ago by alena353.
    • This topic was modified 2 years, 5 months ago by alena353.
    • This topic was modified 2 years, 5 months ago by alena353.
    • This topic was modified 2 years, 5 months ago by alena353.

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Support Pawel – WPMU DEV Support

    (@wpmudev-support9)

    Hi @alena353,

    Thank you for contacting us.

    Did you also make sure to enable the option “Populate Field from URL” in advanced tab?

    In order to better assist you, could you please export your form to a drive and share with us the link so that we can check on your setup and run a similar setup to test this for you?

    Best,
    Jonathan S

    Thread Starter alena353

    (@alena353)

    Hi Jonathan,

    Yes, I enabled that option in advanced tab.

    Here’s the link to the form – https://drive.google.com/file/d/11rBEy3RSdTdn19eqw71nk3kXSUAbKVX2/view?usp=sharing

    Thanks,
    Alyona

    Plugin Support Pawel – WPMU DEV Support

    (@wpmudev-support9)

    Hi @alena353,

    Thanks for providing that info.

    I tested the form by adding it to a test page and using a query parameter in URL, I was able to populate the hidden field. See my test URL: https://jsolofree.tk/form-test/?the-course=theonecourse

    And the submission field: https://snipboard.io/Dxu6zj.jpg

    Go ahead and make a test by having the form embedded directly on a test page without the popup form and let us know how it goes.

    Best,
    Jonathan S

    Thread Starter alena353

    (@alena353)

    Hi Jonathan,

    It works perfectly without popup! Thank you so much!!!

    Why do you think it doesn’t work with popup, though? And is there a way to make it work?

    I’ve also got 2 more questions:)

    1) Is it possible to automatically embed the field that is not hidden (to do the same thing that we do with hidden field, but to make this field visible to the user and not allow user to change it)?

    2) When I put a long text in the hidden field, it gets cut and, as a result, I get only part of the value. Is there a way to allow the form to accept longer values in the hidden field?

    Thanks so much for your help,
    Alyona

    • This reply was modified 2 years, 5 months ago by alena353.
    • This reply was modified 2 years, 5 months ago by alena353.
    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @alena353

    Why do you think it doesn’t work with popup, though? And is there a way to make it work?

    Could you test our PopUp plugin?

    https://wordpress.org/plugins/wordpress-popup/

    From my test it looks the code worked using our plugin.

    1) Is it possible to automatically embed the field that is not hidden (to do the same thing that we do with hidden field, but to make this field visible to the user and not allow user to change it)?

    You can use the HTML field and embed the hidden-1 macro:

    https://monosnap.com/file/l49PpWccOpAnI59gDayWA6kYIOvYxT

    It is going to show in the front end but not allow the user to modify the value from the HTML field.

    2) When I put a long text in the hidden field, it gets cut and, as a result, I get only part of the value. Is there a way to allow the form to accept longer values in the hidden field?

    Could you give an example and we can try to replicate it?

    Best Regards
    Patrick Freitas

    Thread Starter alena353

    (@alena353)

    Hi @wpmudevsupport12

    Thanks so much for your reply!

    So, I tested the popup plugin you sent, it didn’t work for me though.
    I chose “Informational” type of popup, inserted the shortcode for the form in the Main Content area, chose “Click” option in PopUp-Trigger field and inserted “.show-popup” as the class of my button that’s gonna trigger the popup to appear.

    I changed the code for the trigger button to <a class="show-popup" href="https://www.aviatour-expert.ru/kursy-i-tseny/?the-course=Автоматизированная">Записаться</a>

    For some reason, when I click the button, the popup with my contact form appears, but the link in the browser doesn’t change (it stays “https://www.aviatour-expert.ru/kursy-i-tseny/&#8221;, not “https://www.aviatour-expert.ru/kursy-i-tseny/?the-course=Автоматизированная&#8221;), so when I fill out the form, I don’t get the name of the course in the result.

    Here’s the link to that popup I imported – https://drive.google.com/file/d/1wBkDxtcNLRT9qmVwgECNx388ziB4qvF9/view?usp=sharing

    Maybe you could take a look and help me figure out what I did wrong?

    Thanks,
    Alyona

    Thread Starter alena353

    (@alena353)

    As for the other question,

    2) When I put a long text in the hidden field, it gets cut and, as a result, I get only part of the value. Is there a way to allow the form to accept longer values in the hidden field?

    Could you give an example and we can try to replicate it?

    Sure, for, example, last time I tried putting this value “Автоматизированная система бронирования авиабилетов “Сирена – Трэвел”. Базовый курс.” in the hidden field by doing this code:

    <a class="show-popup" href="https://www.aviatour-expert.ru/kursy-i-tseny/?the-course=Автоматизированная система бронирования авиабилетов "Сирена - Трэвел". Базовый курс.">Записаться</a>

    – in the submission message I got only the first 4 words “Автоматизированная система бронирования авиабилетов” which is only a part of the corse’s name.

    Thread Starter alena353

    (@alena353)

    I think I just realized why it didn’t give me the whole course’s name! I guess, I shouldn’t have put quotation marks (“) in the name of the course as the system thought it was the end of the “href”.

    Sorry to bother you about that.

    Plugin Support Pawel – WPMU DEV Support

    (@wpmudev-support9)

    Hi @alena353,

    No bother at all.

    I was able to replicate the behavior with popup. The reason the URL is not shown is that the actual trigger will just activate with a button click event, but not redirect, which is where the href URL is set for.

    I’m going to check with our plugin team if there is any possible way of doing this and get back to you.

    Best,
    Jonathan S

    Thread Starter alena353

    (@alena353)

    Hi @wpmudev-support9

    Thank you! Looking forward to hearing back from you.

    Thanks,
    Alyona

    Plugin Support Pawel – WPMU DEV Support

    (@wpmudev-support9)

    Hi @alena353,

    Our Plugin team was able to provide a workaround code to allow you to have the popup with form setup and get the hidden field connected to the value from the query parameter. To do this, please set up the following code in either an MU plugin or in your theme’s functions.php file. If it’s the latter, make sure to set it up in a child theme and not a parent theme, so you avoid the code from being erased.

    Here is the code:

    function hustle_front_custom_script() {	
    	if( is_page( array( 101 ) ) ) { // Id, slug, or title of pages having the form.
    		$data = 'jQuery(document).ready(function($){
    					$(".show-popup").click(function() { // Class name that triggers the popup
    						var href = $(this).attr("href");
    						if(href.length) {							
    							var course = href.substr(href.indexOf("=") + 1);
    							if(course.length) {							
    								//alert(course);
    								$("#hidden-1").val(course); // Id of the hidden field.
    							}
    						}													
    					});					
    				});';
    		
    		// Since WordPress 4.5.
    		wp_add_inline_script( 'hustle_front', $data );     
        }	
    }
    add_action( 'wp_enqueue_scripts', 'hustle_front_custom_script' );

    The code uses the class “show-popup” so in case you changed it, it will need to br modified in the code as well. For additional reference on setting up the code via an MU-plugin, take a look here:https://premium.wpmudev.org/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Let us know how it goes.

    Best,
    Jonathan S

    Thread Starter alena353

    (@alena353)

    Hi @wpmudev-support9

    Thank you so much! I’ll give it a try when I have a chance. For now, I’m using the contact form on the separate page, so hidden field works perfectly!

    Thanks again for your help! This plugin has got the best technical support ever!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Hidden field – Custom Value – how to get a value’ is closed to new replies.