Skip Navigation

[Resolved] Set post title with CRED field values

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

Problem:
How to dynamically generate the title of a post submitted with a Toolset Form using field values from the form?

Solution:
There are two possible solutions for what you want to do.

In the first you use JavaScript to add on change event listeners to the inputs for field1 and field2 and you update the post_title with their contents. In that way the post title input is populated when the form submits.

The second method is to omit the post_title field from the form altogether so that no title is submitted, and then use the Forms API (specifically, the cred_save_data hook: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data) to intercept the submitted and update what would be an auto-generated title using PHP based upon your custom fields.

This support ticket is created 6 years, 7 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by antonioS-7 6 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#913635

I have a CRED form to generate new posts. I want to generate the post title with values from other form fields.

Example:

[cred_field field='field1' value='' urlparam='' class='form-control' output='bootstrap']
[cred_field field='field2' value='' urlparam='' class='form-control' output='bootstrap']

<div style="display:none">
[cred_field field='post_title' value="[wpv-post-field name='field1'] - [wpv-post-field name='field2']" urlparam='' class='form-control' output='bootstrap']
</div>

This structure, at the moment, is not working. How can I do this?

#913787

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Antonio

What you are doing won't work because those shortcodes—the wpv-post-field shortcodes—have already been parsed in PHP when the page is rendered, they are interpreted at the time the server is building the page when your form is blank.

There are two possible solutions for what you want to do.

In the first you use JavaScript to add on change event listeners to the inputs for field1 and field2 and you update the post_title with their contents. In that way the post title input is populated when the form submits.

The second method is to omit the post_title field from the form altogether so that no title is submitted, and then use the Forms API (specifically, the cred_save_data hook: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data) to intercept the submitted and update what would be an auto-generated title using PHP based upon your custom fields.

If you have a preference for one and need help, let me know.

#914046

Thank you!