Skip Navigation

[Resolved] How to add generic fields data to notification body

This support ticket is created 8 years, 4 months ago. 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
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

Tagged: 

This topic contains 13 replies, has 2 voices.

Last updated by ernestasK 8 years, 4 months ago.

Assisted by: Waqas.

Author
Posts
#348316

I am trying to: send generic field added in user form via email

I visited this URL: inserted in user form

[cred_generic_field field="Problema" type="textarea" class="" urlparam=""]
{
"required":1,
"validate_format":0,
"persist":0,
"default":""
}
[/cred_generic_field]

I expected to see: in email value from field "Problema"

Instead, I got:

nothing. Tried all kind of shortcodes - all return just text.

shortcodes on notification body

[Problema]

%%Problema%%

%%FORM_DATA%%

[cred_generic_field field="Problema"][/cred_generic_field]

#348492

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Generic fields are not handled and processed automatically by the CRED. But CRED provides a sophisticated way to deal with such fields on the fly. I suggest using following example code:

add_filter('cred_body_notification_codes', 'cb_problema_placeholder', 10, 1);
function cb_problema_placeholder($defaultPlaceHolders) {
	return array_merge($defaultPlaceHolders, array('%%Problema%%' => $_REQUEST['Problema']));
}

Please add this code to your theme's functions.php file.

This code actually does followings:

- Adds 'cred_body_notification_codes' filter to the filters queue. This filter is defined by CRED to render default placeholders.
- It takes a parameter and passes the array of existing placeholders (defined by CRED).
- All we need to add our own %%Problema%% placeholder and render it accordingly. This what it does within the callback function 'cb_problema_placeholder'.
- During this addition, it grabs the generic field's value from standard $_REQUEST super global array.

You can do the same with Subject Field also. Remember to use 'cred_subject_notification_codes' filter, just like above. I hope it resolves the issue.

#348860

Thank you very much for help. Now I have another problem - when inserting custom user fields - they do not appear in email.

User fields in form

[cred_generic_field field="telefonas" type="numeric" post="user" class="" urlparam=""]
{
"required":1,
"validate_format":1,
"persist":1,
"default":""
}
[/cred_generic_field]

[cred_field field='telefonas' post='user' value='' urlparam='']

Tried fields in notification

%%USER_TELEFONAS%%
[types usermeta="telefonas" user_is_author="true" output="raw"][/types]

Your approach does not work on [cred_fields]

#349098

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

The fields from a Post Type and User Profile (standard and custom) should work fine with their respective methods (i.e. types short code or other short codes provided). However, for Generic Fields the code I provided above should work just fine - regardless of CRED Forms and User Forms.

All you need to make sure that you add new placeholders in the code. So you can replace their values accordingly.

If you can copy your code here, I can see for a problem.

#349308
email values.jpg
form entry.jpg

user form

[creduserform class='cred-user-form cred-keep-original']
[cred_field field='form_messages' value='']
[cred_field field='user_login' post='user' value='' urlparam='']
[cred_field field='user_email' post='user' value='' urlparam='']
[cred_field field='telefonas' post='user' value='' urlparam='']
[cred_field field='adresas' post='user' value='' urlparam='']
[cred_field field='pasto-kodas' post='user' value='' urlparam='']
[cred_generic_field field="problema" type="textarea" class="" urlparam=""]
{
"required":1,
"validate_format":0,
"persist":0,
"default":""
}
[/cred_generic_field]
[cred_field field='form_submit' value='Patvirtinti' urlparam='']
[/creduserform]

notification form

Problema %%problema%%
1. %%USER_LOGIN_NAME%%
2. %%USER_USERNAME%%
3. %%USER_PASSWORD%%
4. [types usermeta="telefonas" format="FIELD_NAME: FIELD_VALUE" user_is_author="true"][/types]
5. [types usermeta="adresas" user_is_author="true"][/types]
6. [types usermeta="pasto-kodas" user_is_author="true"][/types]

function code

add_filter('cred_body_notification_codes', 'cb_problema_placeholder', 10, 1);
function cb_problema_placeholder($defaultPlaceHolders) {
return array_merge($defaultPlaceHolders, array('%%problema%%' => $_REQUEST['problema']));
}

In the screenshots - what I entering to the form and what I get in email. Just empty fields.

If I use generic field with your approach for this, generic values are not saved to database even if I set persist to 1 🙁

Please help

#349368

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Can you please provide some debug information about your site? Please see https://toolset.com/faq/provide-debug-information-faster-support/ for more information.

I have enabled debug information area for your next reply.

#349396

Debug provided.

#349602

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for providing the debug information.

Can you please upgrade all Toolset Plugins to latest versions and recheck for the issue? Please let me know your findings, thanks.

#350086

Updated to the latest - still same problem. Can provide debug info. Empty fields in email body.

#350089

Added to the functions

add_filter('cred_body_notification_codes', 'cb_pastas2_placeholder', 10, 1);
function cb_pastas2_placeholder($defaultPlaceHolders) {
return array_merge($defaultPlaceHolders, array('%%pasto-kodas4%%' => $_REQUEST['pasto-kodas']));

added to the notification form

%%pasto-kodas4%%

nothing. Still empty values 🙁

filed are save to the database without any problem. Just not passed to notify form.

Please help

#350106

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

This is really weird that your code isn't working, although it looks just fine. However, can you please try replacing your add_filter line with following:

add_filter('cred_body_notification_codes', 'cb_pastas2_placeholder', 99, 1);

Notice 99 in the 3rd parameter of add_filter. This is a priority attribute. Setting it to higher level will ensure that it runs lately. I suspect running it too early may not be working in this case. Please try the above line.

If it still does not work for you. Please provide temporary access to your site. So I can look for more details.

I have enabled your next reply as private, please input all details in that area. Please mention the links to the pages, views, forms, CPTs and configurations in question.

Please take a backup of your site, before proceeding. Also make sure the functions.php is writeable so I can make necessary changes (if needed).

#350167

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for providing the access information. I was able to look into your website and have corrected the issue with %%pasto-kodas4%%. While %%problema%% is already working fine.

However, please consider followings, on order to get other [types] short codes and other %% placeholders to work:

1) For [types usermeta] short codes, please update CRED and Layout plugins as well. I noticed that you are using a previous release than the current one. Updating to CRED 1.4.2.1 and Layouts 1.4.2 should fix this issue.

2) For %%pasto-kodas3%% you need to activate the appropriate filter, but remember to add a relevant field in the form as well. Since I don't see a field representing this placeholder. But the method is the same as for other working placeholders.

3) Remember, when you are referencing a form field (not generic field), you should grab it by adding 'wpcf-' as a prefix to it's name. For example your field 'pasto-kodas' should be grabbed as $_REQUEST['wpcf-pasto-kodas'] in the filter. I have corrected this in your functions.php file. However, generic fields do not have such a prefix in their names and should be referenced as-it-is (i.e. problema).

Apparently, if you upgrade CRED and Layouts to the latest versions, rest of the issues should also be solved. Please let me know if issue is resolved after the update. Please see https://toolset.com/account/downloads/ for latest available versions of Toolset Plugins.

#350177

Hello,

updated to the latest. Code you have sent works now.

I think it would be much easier to add custom user fields that can be inserted into notification via "insert body codes".

But now I have another problem 🙁 Email sent to the customer with registration details returns empty password.

#350179

I found it. It needed generate password to be checked.

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