-
AuthorPosts
-
January 21, 2025 at 6:23 pm #1475507
HI,
I would need to add the URL of origin in all forms, so I can know on which page or article the form was filled out.How can I do it?
Thanks for the support!January 21, 2025 at 11:19 pm #1475519January 22, 2025 at 3:42 pm #1475560Thank you Mike,
but I have the same form in all the articles, added with a shortcode, which recalls a page with a color section and a form inside.
I tried putting some code in the object, but it doesn’t work. Where can I find the files relating to the form, so I can study them. Or does anyone know how to do it?
Thank you so much!January 22, 2025 at 10:25 pm #1475601Hi,
You could review the file at config-templatebuilder/avia-shortcodes/contact/contact.php
but changing this file will make all of the forms have the same result, you are best to use a different form on each page with a unique “E-Mail Subject” as posted above.Best regards,
MikeJanuary 23, 2025 at 12:42 am #1475608maybe it is possible via that filter: avia_contact_form_args ?
January 23, 2025 at 12:19 pm #1475642if a hint on the bottom of your e-mail is enough – you can put this to your child-theme functions.php:
function add_page_info_to_form_email($message, $new_post, $form_params) { // Get the current page URL and title $page_url = get_permalink(); $page_title = get_the_title(); // Append the page information to the message $message .= "\n\n--\nSent from the page:\n" . $page_url . "\n"; return $message; } add_filter('avf_form_message', 'add_page_info_to_form_email', 10, 3);
January 23, 2025 at 12:38 pm #1475646Since I use contactform 7, I can’t say whether this has always been the case: the subject in the email header is always :
sent by contact form at bloginfo.January 23, 2025 at 4:10 pm #1475658Thank you so much everyone!
I solved it thanks to your instructions.
Below is the code used, if it helps, which inserts URL and page title to all forms.Thank you for your help and your time!
————
function add_page_info_to_form_email($message, $new_post, $form_params) {
// Debug: Controlliamo se la funzione viene eseguita
error_log(‘DEBUG: Entrato in add_page_info_to_form_email’);// Recupera il titolo e l’URL della pagina corrente
$page_url = get_permalink();
$page_title = get_the_title();// Se il titolo è vuoto, proviamo a recuperarlo dall’URL di riferimento
if (empty($page_title) && isset($_SERVER[‘HTTP_REFERER’])) {
$referrer_url = esc_url_raw($_SERVER[‘HTTP_REFERER’]);
error_log(‘DEBUG: Il titolo della pagina è vuoto, provo a recuperarlo dall’URL -> ‘ . $referrer_url);$response = wp_remote_get($referrer_url);
if (!is_wp_error($response)) {
$body = wp_remote_retrieve_body($response);
preg_match(‘/<title>(.*?)<\/title>/s’, $body, $matches);
if (!empty($matches[1])) {
$page_title = html_entity_decode(trim($matches[1]), ENT_QUOTES | ENT_HTML5, ‘UTF-8’);
$page_title = preg_replace(‘/[^\x20-\x7E]/’, ”, stripslashes($page_title));
error_log(‘DEBUG: Titolo recuperato dal corpo della pagina -> ‘ . $page_title);
}
}
}// Se il titolo è ancora vuoto, assegna un valore predefinito per il debug
if (empty($page_title)) {
$page_title = ‘Titolo non disponibile’;
error_log(‘DEBUG: Nessun titolo trovato, imposto “Titolo non disponibile”‘);
}// Se l’URL è vuoto, recuperiamolo dall’HTTP_REFERER
if (empty($page_url) && isset($_SERVER[‘HTTP_REFERER’])) {
$page_url = esc_url_raw($_SERVER[‘HTTP_REFERER’]);
error_log(‘DEBUG: URL recuperato da HTTP_REFERER -> ‘ . $page_url);
}// Debug finale prima di aggiungere le informazioni alla mail
error_log(‘DEBUG: Titolo finale prima di inviare la mail -> ‘ . $page_title);
error_log(‘DEBUG: URL della pagina -> ‘ . $page_url);// Aggiungiamo il titolo e l’URL al fondo del messaggio email
$message .= “\n\n—\nTitolo della pagina: ” . $page_title . “\nURL: ” . $page_url . “\n”;return $message;
}
add_filter(‘avf_form_message’, ‘add_page_info_to_form_email’, 10, 3);January 23, 2025 at 4:21 pm #1475659Hi,
Great, I’m glad that you found a solution and thanks for sharing it. Please let us know if you should need any further help on the topic, or if we can close it.
Best regards,
RikardJanuary 23, 2025 at 4:48 pm #1475669You can close the ticket, thanks!
January 23, 2025 at 5:37 pm #1475671Why not using the code tag for your code? Link
No one can copy paste the code for his own use.January 23, 2025 at 7:44 pm #1475680Hi,
Thanks for the update, we’ll close this thread for now then. Please open a new thread if you should have any further questions or problems.
Best regards,
Rikard -
AuthorPosts
- The topic ‘Add the URL of the current page to the form’ is closed to new replies.