Skip Navigation

[Resolved] Autofill the post title with fields from a CRED Form

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

Problem:
Autofill the post title with fields from a CRED Form

Solution:
You will have to use the Toolset form's hook "cred_save_data" to generate the post title based on the custom field.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/autofill-the-post-title-with-fields-from-a-cred-form/#post-2089161

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 3 years, 5 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 2 replies, has 2 voices.

Last updated by nicoleR-3 3 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2089025

Tell us what you are trying to do?
I have created a form from my custom post types values and they have fields for the First and Last Name. I would like those to fields to automatically be used for the custom post title.

Is there any documentation that you are following?
I am following this, but I have zero coding experience for this kind of thing and don't know what I'm looking at. https://toolset.com/forums/topic/set-post-title-with-cred-field-values/

And I tried this but it didn't work, probably because this developer isn't using the CRED form: https://toolset.com/forums/topic/create-post-title-for-cpt-from-two-custom-fields/

Is there a similar example that we can see?
I see several other forum topics on this, but they only relate to those specific instances.

What is the link to your site?
The rough, unstyled form is here: hidden link

#2089161

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As refenced with another related ticket you shared, you can use the Toolset form's hook: cred_save_data
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Can you please try to add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset
OR
You can add it to current theme's functions.php file:

add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data) {
    if ($form_data['id']==96) {
        $first= get_post_meta($post_id, 'wpcf-first-name', true);
        $last= get_post_meta($post_id, 'wpcf-last-name', true);
        $title= $first. ' ' . $last;
        $args = array('ID' => $post_id, 'post_title' => $title);
        wp_update_post($args);
    }
}
#2089803

That worked! My issue is resolved now. Thank you!