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 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.
This topic is split from https://toolset.com/forums/topic/contact-form-send-an-email-notification-using-custom-field-from-profile-page/
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 replies, has 2 voices.
Last updated by 6 years, 2 months ago.
Assisted by: Christian Cox.