Skip Navigation

[Resolved] To auto complete a ppost name based on firstname and lastname

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.

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
- 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 1 reply, has 2 voices.

Last updated by Minesh 5 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1224346

I have a form where we add new learners. I am trying to add a snippit to autocomplete the post name based on the first and last names of the learners.
The snippit i am using is

<?php
/**
 * New custom code snippet.
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );
if ($form_data['id']==682) {
        $surname = get_post_meta($post_id, 'wpcf-surname', true);
        $firstname = get_post_meta($post_id, 'wpcf-full-names', true);
        $cptitle= $surname. ' - ' . $firstname;
        $args = array('ID' => $post_id, 'post_title' => $cptitle);
        wp_update_post($args);
    }

The cred form id is 682, The field names are "surname" and "Full-names" respectively. I am getting an error when I test the snippet.

E_NOTICE: Undefined variable: form_data in file /home/hostin28/lms1.2hosting.co.za/wp-content/toolset-customizations/autocomplete_learner_post_name.php on line 7

Note: Depending on the nature of the error, you may need to run the script in a particular scenario to make sure the issue is gone.

Any assistance would be appreciated

#1224404

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - it looks like you do not added the code with the proper filter cred_save_data . Can you please try to use the following code and try to resolve your issue.

add_action('cred_save_data', 'func_auto_post_name',10,2);
function func_auto_post_name($post_id, $form_data) {

if ($form_data['id']==682) {
        $surname = get_post_meta($post_id, 'wpcf-surname', true);
        $firstname = get_post_meta($post_id, 'wpcf-full-names', true);
        $cptitle= $surname. ' - ' . $firstname;
        $args = array('ID' => $post_id, 'post_title' => $cptitle);
        wp_update_post($args);
    }

}

More info:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data