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

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.

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Related documentation: Front-end Content Submission and Editing Forms

This topic contains 4 replies, has 2 voices, and was last updated by  Eric Anderson 1 week ago. The support staff assigned to this topic is Minesh.

Viewing 5 posts - 1 through 5 (of 5 total)
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
Forum moderator

Supporter languages: English (English )

Supporter 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://wp-types.com/documentation/programmer-reference/cred-api/#cred_save_data

Related Tickets you may interested in:
=> https://wp-types.com/forums/topic/adding-two-custom-fields-together-to-make-a-post-title-on-submit/#post-412305
=> https://wp-types.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
Forum moderator

Supporter languages: English (English )

Supporter 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.

Viewing 5 posts - 1 through 5 (of 5 total)

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Known issues and their solutions

We document known issues and their solutions in Toolset erratas. Save time by checking there first and seeing if what you are facing is a known issue. This list is kept short. We do our best to resolve all known issues with every release of Toolset plugins.

Support Policy

Toolset staff will help you use the Toolset plugins correctly, provide any information you need, help troubleshoot problems and advice on best-practices.

Please make sure to issue only one topic per each support ticket.

For more information, read our full Customer Support Policy.

Need custom programming work for your site? Check out our certified partners.