Skip Navigation

[Resuelto] Forms: Add current page information to email notification subject

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

Problem: I have a Form that is placed in a template for posts, so it is displayed on many pages of the site. I would like to be able to know which page contained the Form that was submitted, so I can use the post title in the email notification.

Solution: You can access the title of the current page and insert it into a generic field in the Form. Then I can give you a snippet that will allow you to use a custom placeholder in the subject or body of an email notification to display the current post title. Add this generic field to your Form Builder, inside the credform shortcodes:

[cred_generic_field field='currentpagetitle' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-title id='$current_page']"
}
[/cred_generic_field]

Then add this custom code snippet to your child theme's functions.php file:

add_filter('cred_body_notification_codes', 'custom_generic_field_notification');
add_filter('cred_subject_notification_codes', 'custom_generic_field_notification');
 
function custom_generic_field_notification( $defaultPlaceHolders ) {
  $newPlaceHolders = array(
    '%%CURRENT_PAGE_TITLE%%' => $_REQUEST['currentpagetitle']
  );
 
  return array_merge($defaultPlaceHolders, $newPlaceHolders );
}

Now you can use the custom placeholder %%CURRENT_PAGE_TITLE%% in your email notification's subject or body area to display the title of the post where the Form was displayed:

%%CURRENT_PAGE_TITLE%% you have a new message from your profile page.

Relevant Documentation:
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://toolset.com/documentation/user-guides/how-to-use-custom-placeholders-in-cred-notifications/

This support ticket is created hace 5 años, 7 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 respuestas, has 2 mensajes.

Last updated by andresG-3 hace 5 años, 7 meses.

Assisted by: Christian Cox.

Autor
Mensajes
#1093190

Thanks Christian!

Now i can select the hidden-email-adress variable and it works! thanks for your help. There is an small detail that i want to achieve and is to use on subject email notification wp-title from profile page "lawyer name a last name" but it seems that is loading this from wp-title of form "name and last name"

Subject notification example
[wpv-post-title] you have a new message from your profile page

#1093231

You can access the title of the current page and insert it into a generic field in the Form. Then I can give you a snippet that will allow you to use a custom placeholder in the subject or body of an email notification to display the current post title. Add this generic field to your Form Builder, inside the credform shortcodes:

[cred_generic_field field='currentpagetitle' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-title id='$current_page']"
}
[/cred_generic_field]

Then add this custom code snippet to your child theme's functions.php file:

add_filter('cred_body_notification_codes', 'custom_generic_field_notification');
add_filter('cred_subject_notification_codes', 'custom_generic_field_notification');

function custom_generic_field_notification( $defaultPlaceHolders ) {
  $newPlaceHolders = array(
    '%%CURRENT_PAGE_TITLE%%' => $_REQUEST['currentpagetitle']
  );

  return array_merge($defaultPlaceHolders, $newPlaceHolders );
}

Now you can use the custom placeholder %%CURRENT_PAGE_TITLE%% in your email notification's subject or body area to display the title of the post where the Form was displayed:

%%CURRENT_PAGE_TITLE%% you have a new message from your profile page.
#1097420

thanks!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.