Saltar navegación

[Resuelto] Get url parameter for cred form taxonomy and select it

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
Get url parameter for cred form taxonomy and select it

Solution:
To set the default option for the taxonomy select added to Toolset forms, you will require to add custom JS code to your form's JS box.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/get-url-parameter-for-cred-form-taxonomy-and-select-it/#post-1778423

Relevant Documentation:

This support ticket is created hace 4 años, 3 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Etiquetado: ,

Este tema contiene 5 respuestas, tiene 2 mensajes.

Última actualización por urkoP hace 4 años, 3 meses.

Asistido por: Minesh.

Autor
Mensajes
#1777979

Hi,

I have a view with a map, on this map are displaying taxonomy terms. Every point on the map have a pop up and in the pop up a link to pass with url the taxonomy term. with this enlace oculto type='mendia-taxonomia' format='name']">froga botoia THE PAGE-> (enlace oculto)

When click on link, it goes to another page wich contains a cred form. And there a form with multiple inputs and between these the taxonomy term select [cred_field field='mendia-taxonomia' force_type='taxonomy' output='bootstrap' display='select' single_select='true']

I would like this option to be selected based on the url, the taxonomy term. But it does not work.

Is there any documentation that you are following?
yes, a support ticket (https://toolset.com/forums/topic/can-i-pass-a-taxonomy-term-to-a-cred-form-via-a-url-parameter/)

What is the link to your site?
enlace oculto

Thank you!

#1778233

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I will require to check within the map view, are you using the taxonomy view, as [wpv-taxonomy-title] shortcode does not offer the attributes "type" and "format".
=> https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-153462

May be you mean to say that you are using the shortcode [wpv-post-taxonomy] that actually offers the attribute "type" and "format".
=> https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-153472

If above is correct - what if you try to change your slug to:

.
<a href="<em><u>enlace oculto</u></em> type='mendia-taxonomia' format='slug']">froga botoia</a> THE PAGE->

And then - add the following JS code to your form's JS editor:

var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;
  
    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');
  
        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
};
var param = getUrlParameter('param-mendia');
 
jQuery('select[name="mendia[]"]').find("option:contains('" + param + "')").attr('selected', 'selected');

Where:
- Please adjust the select name if required.

#1778393

Hi minesh,

I am using a taxonomy view for the map, and therefore i use [wpv-taxonomy-title] to pass the url parameters. I checked shortcodes and you're right shortcode does not offer the attributes "type" and "format". But without these attributes it passes the parameters as well, and also I could pass the id of the taxonomy . the question is that I do not know how to collect them in the form.

Thanks

#1778395

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Ok - Can you please share access details so I can setup the solution for you.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1778423

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Can you please check now: enlace oculto

I've adjusted the JS code to your Form's JS editor as given under:
=> enlace oculto

jQuery(document).ready(function($){
var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;
   
    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');
   
        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
};
var param = getUrlParameter('param-mendia');
  
jQuery('select[name="mendia-taxonomia[]"]').find("option:contains('" + param + "')").attr('selected', 'selected');

  });

I can see its working as expected. Can you please confirm its working as expected at your end as well.

#1778503

My issue is resolved now. Thank you!