Skip Navigation

[Resolved] Custom placeholder function in code snippets

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

Problem:

The issue here is that the user had created some custom placeholders for their CRED notifications.

add_filter('cred_subject_notification_codes', 'custom_generic_field_notification', 10, 1);
  
add_filter('cred_body_notification_codes', 'custom_generic_field_notification', 10, 1);
  
function custom_generic_field_notification( $defaultPlaceHolders ) {
  
    $newPlaceHolders = array( 
        '%%FICHE_TECHNIQUE%%' => $_REQUEST['produit-concerne']
        '%%TITLE%%' => $_REQUEST['producttitle']
    );
   
    return array_merge($defaultPlaceHolders, $newPlaceHolders );
}

With the generic field

[cred_generic_field type='textfield' field='produit-concerne']
{
"default":"[types field='fiche-technique-produit'][/types]"
}
[/cred_generic_field]
[cred_generic_field field='producttitle' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[wpv-post-title]"
}
[/cred_generic_field]   

However the placeholders weren't working.

Solution:

For this user they just needed to ensure that the field is being stored to the database by using the "persist":1 attribute.

This support ticket is created 5 years, 8 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Pat 5 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#1235760

Pat

Hello,

I'm trying to create some custom placeholder and would like to know if I can place the function inside the Toolset code snippets (inside the Toolset => Settings => Code snippets).
The function I'm trying to use is the following (I have 2 placeholders to retreive in my Cred form notification message) :

add_filter('cred_subject_notification_codes', 'custom_generic_field_notification', 10, 1);
 
add_filter('cred_body_notification_codes', 'custom_generic_field_notification', 10, 1);
 
function custom_generic_field_notification( $defaultPlaceHolders ) {
 
    $newPlaceHolders = array( 
        '%%FICHE_TECHNIQUE%%' => $_REQUEST['produit-concerne']
        '%%TITLE%%' => $_REQUEST['producttitle']
    );
  
    return array_merge($defaultPlaceHolders, $newPlaceHolders );
}

and I have integrated inside my Form the following code :

[cred_generic_field type='textfield' field='produit-concerne']
{
"default":"[types field='fiche-technique-produit'][/types]"
}
[/cred_generic_field]
[cred_generic_field field='producttitle' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[wpv-post-title]"
}
[/cred_generic_field]	

As this is not working with this code, could you tell me if I need to place the function in the function.php file (I'm using DIVI here) or if something is wrong with my current code.

Regards
Pat

#1235878

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pat,

Thank you for getting in touch.

Is your custom code activated ? When you go to the toolset custom code page does it say your snippet is active?

Also could you try adding "persist": 1 to your generic field attribute and then try again.

Thanks,
Shane

#1235959

Pat

Hi Shane,

Yes, sure, the snippet is activated !
I have added the "persist"=1 without any change in the result in the mail (%%TITLE%% – %%FICHE_TECHNIQUE%%) !!!
Last info : the Cred form is placed inside a Bootstrap modal window. Don't know if this could have an impact?

Regards
Pat

#1235983

Pat

Hi Shane,

I just discovered that there was an error in my function. I have forgotten to place a comma after the first item of the array !!!

Everything's fine now.
Thanks for your support and sorry for that.

Regards
Pat