Skip Navigation

[Resolved] auto-populate submitted form post-title with submitted form post-id?

This support ticket is created 7 years, 2 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 Eric Anderson 7 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#567347

I’ve created a Post Form of CPT ‘Feedback.’ Its shortcode is included in a Visual Editor cell of a Layout for another CPT. As users submit these forms, I want their post-title to include their auto-incremented post-id in the title, like this: Feedback Form #537 (where 537 = the post-id of the *submitted form*).

This works on the form email notification, like so:
SUBJECT: Form # [wpv-post-id] = Form #537

However, when I try to auto-populate the *submitted form* post-title using [wpv-post-id], I get a different value, like this: Form #319 (where 319 = the post-id of the post in which the form is embedded). Here’s the code I’m using:

Edit CRED Post Form > Content
[cred_field field='post_title' post='scene-feedback' value='[wpv-post-id]' urlparam='' class='form-control' output='bootstrap']

It makes sense that *before* the form is submitted the only value for [wpv-post-id] would be the value of the existing page in which the form is embedded.

So, how do I auto-populate the title of the *submitted form* with the post-id of the *submitted form* so that it matches up with the Email Notification Subject Line?

Thank you.

#567438

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - We have the nice example how you can auto-populate the post title while using CRED form. You need to use CRED hook cred_save_data .

For example:

//Create a dynamic post title by the CRED form.
add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data) {
    if ($form_data['id']==9999) {
        $name = get_post_meta($post_id, 'wpcf-name', true);
        $email = get_post_meta($post_id, 'wpcf-email', true);
        $title= $name. '-' . $email;
        $args = array('ID' => $post_id, 'post_title' => $title);
        wp_update_post($args);
    }
}

You need to adjust your title according to your requirement.

Please check the following Doc:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Related Tickets you may interested in:
=> https://toolset.com/forums/topic/adding-two-custom-fields-together-to-make-a-post-title-on-submit/#post-412305
=> https://toolset.com/forums/topic/how-to-set-format-date-field/#post-408928

#569303

Thank you, Minesh.

I am back from another project and will now attempt to implement your solution. I will follow up with any questions.

#569401

Minesh
Supporter

Languages: English (English )

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

Ok fine - thank you. Please get in touch with me if you have any further queries.

#569822

That worked great, thanks.