Skip Navigation

[Resolved] Auto populate title from fields

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

Author
Posts
#2640579

This is a follow up question for this topic: https://toolset.com/forums/topic/relationship-form-6/

I would like to auto populate the post title with some form fields: arrival date - ship name - port name

#2640899

Nigel
Supporter

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

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

Hi there

Am I right in thinking that the solution you went with from the other thread was to have a reservation post type and a one-to-many relationship between ports and reservations, and another one-to-many relationship betweem ships and reservations?

And so the form you are talking about here is a form to publish reservation posts, which is shown on the port page, and which has the port pre-selected and from which a ship can be chosen. (I assume the arrival date is a field belonging to the reservation post.)

To auto-populate the post title there are two ways you might do this.

One would be to add JavaScript to your form. The post title field would be included (it is needed) but hidden, and you could add on-change event handlers to the arrival date field and the ship selector which assembles the title from the 3 field components, and then the post title will be handled normally as the form is submitted.

The alternative would be to use PHP on the server via the cred_save_data API hook. In the linked documentation there is an example of how to generate a dynamic post title (expand the example usage section): https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

In your case you would have the ship and port IDs available in the $_POST object and you would need to get those post objects (with get_post) to access their titles.

#2640901

Hi Nigel,

Yes, that seems right. I can't write JS or PHP though, that's why I use Toolset 😉

#2641201

Hi,

Thanks for writing back.

If you're not comfortable writing/editing PHP and JS code for the customizations, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar