D
D
Dropych2020-06-19 22:55:27
WordPress
Dropych, 2020-06-19 22:55:27

Wordpress can get URL or link title for Contact-form-7?

0

Worth wocoomerce through contact form 7 implemented feedback. For each product, you can ask a question. Is it possible to get a link or the name of a product that a person will ask about without going into the product, but from the catalog? I found this on the site:

$('.zakaz').click(function()
{
titleService=$(this).attr('data-title-service');
$('.hide-title').val(titleService);
});

i added this to common js and shortcode

[hidden title-service class:hide-title id:title-service]

but for some reason, nothing. do not throw slippers) nok ps js code changed the name of the button to its own of course

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2020-06-20
@azerphoenix

Hello!
It's hard to give advice when you can't debug and tell what exactly the problem is on your end.
For example:

$('.zakaz').click(function()
{
titleService=$(this).attr('data-title-service');
$('.hide-title').val(titleService);
});

First, you click on the "Order" button. If this is a contact form submit button, then it is better to add
e.preventDefault();and after inserting the value into the desired field, submit viasubmit()
$('.zakaz').click(function(e) {
e.preventDefault();
titleService=$(this).attr('data-title-service');
$('.hide-title').val(titleService);
});

And if this is not a contact form submit button, but for example, displays a modal or something else, and the submit happens later, then preventDefault is not needed.
Further, it is not clear whether you defined the titleService variable above in the common.js code, because you don’t have this variable.
Should be added insteadtitleService=$(this).attr('data-title-service');
var titleService=$(this).attr('data-title-service');

or
let titleService=$(this).attr('data-title-service');

Further, you again did not specify the html code of your hidden field. Note that, for example, if this hidden field has a disabled attribute, then it will not be sent when submitted.
In general, there are many nuances. Learn to debug code. And for this, open the browser console, put dots and check the code in the browser console.
Oh yes, another nuance:
Here, your code:
$('.zakaz').click(function(e) {
e.preventDefault();
titleService=$(this).attr('data-title-service');
$('.hide-title').val(titleService);
});

Try changing "dollar signs" to jQuery or wrapping your code in
jQuery(document).ready(function( $ ) {
// Ваш код тут
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question