Skip Navigation

[Resolved] How to add custom fields in a Notification email (linked to User Form)?

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to add custom fields added using the Generic field in a Notification email (linked to User Form)?

Solution:
You can use the Toolset form's API hook "cred_body_notification_codes" in order to add the custom fields to the email notification body on fly.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/how-to-add-custom-fields-in-a-notification-email-linked-to-user-form/#post-1503483

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/front-end-forms/how-to-use-custom-placeholders-in-cred-notifications/

This support ticket is created 4 years, 10 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by steveH-15 4 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1503187

I need to add two custom fields (1)type='phone' (2)type='numeric', to a notification email, that is send out when a User Form is filled in.

The coding for the User Form is:

[creduserform]
<div class="form-group">
<label>Email (Username)</label>
[cred_field field='user_email' class='form-control' output='bootstrap']
</div>

<div class="form-group">
<label>Password</label>
[cred_field field='user_pass' class='form-control' output='bootstrap']
[cred_field field='user_pass2' class='form-control' output='bootstrap']
</div>

<div class="form-group">
<label>First name</label>
[cred_field field='first_name' class='form-control' output='bootstrap']
</div>

<div class="form-group">
<label>Last name</label>
[cred_field field='last_name' class='form-control' output='bootstrap']
</div>

[cred_field field='form_messages' class='alert alert-warning']

<div class="form-group">
<label>Phone</label>
[cred_generic_field type='phone' field='phone' class='form-control']
{
"required":0,
"default":""
}
[/cred_generic_field]
</div>

<div class="form-group">
<label>NPTA Membership Number</label>
[cred_generic_field type='numeric' field='npta_membership_number' class='form-control']
{
"required":0,
"default":""
}
[/cred_generic_field]
</div>

[cred_field field='recaptcha' class='form-control' output='bootstrap']
[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']
[/creduserform]

#1503483

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can use the Toolset Form's hook: cred_body_notification_codes

For example - add the following code to your current theme's functions.php file

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

Now, within your email notification body, you can display the phone as:

%%PHONE%%

Please check the following Doc:
=> https://toolset.com/documentation/user-guides/front-end-forms/how-to-use-custom-placeholders-in-cred-notifications/

#1503561

Hello

Thank you very much for your reply!

I have managed to add the phone field in my notification email and it works!

How do I add the following to the NPTA Membership Number to the notification email?

<div class="form-group">
<label>NPTA Membership Number</label>
[cred_generic_field type='numeric' field='npta_membership_number' class='form-control']
{
"required":0,
"default":""
}
[/cred_generic_field]
</div>

#1503563

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You can replace the old code with the following one:

add_filter('cred_body_notification_codes', 'func_merge_custom_notification_placeholder', 10, 1);
function func_merge_custom_notification_placeholder($defaultPlaceHolders) {
    return array_merge($defaultPlaceHolders, array('%%PHONE%%' => $_REQUEST['phone'],'%%NPTAMEMBERSHIPNO%%' => $_REQUEST['npta_membership_number']));
}

and you can use it as follow within your email notification body;

%%NPTAMEMBERSHIPNO%%
#1508709

My issue is resolved now. Thank you!