Skip Navigation

[Resolved] Possible to load a Toolset Custom Field into a 3rd party Form (Forminator Pro)?

This support ticket is created 3 years, 6 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 3 voices.

Last updated by Minesh 3 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2037431

Tell us what you are trying to do?
I have a Custom Post Type called 'Client'. This post type is setup to mirror a User Role (also called 'client') - it has been setup this way so that I can create a Relationship between Clients and other Post Types in my website (as this is not possible between User Roles and Post Types).
One of the custom fields that I have attached to the 'Client' custom post type (ie NOT the user role, but the post type), is 'Telephone Number' (slug is 'client-phone-number').
When a 'Client' logs into the site, I have a page where they can go to make a request to the website admin to be contacted, I have set this up using a 3rd party Form Plugin (called 'Forminator Pro' - hidden link). The reason I have used this instead of a Toolset form, is that this form is basically just like a standard contact form (I don't need it to create a post or a user), and I have seen it mentioned on other forum posts for Toolset, that you should not use Toolset Forms for basica contact forms.
So, my question is as follows:
When a 'Client' (User Role) is logged into the site, and they go to the page with the Forminator Form on it, I would like this form to pre-populate the Phone Number field with the 'client-phone-number' custom field from the 'Client' post type, how can I do this please?
I have tried generating the short code for this and placing it in the default value field on the form, but this just displays the short code as a text string, so I am guessing that I will need a code snippet to add to my functions.php file.
Are you able to provide me with some example code to try?
If it helps, the 'ID' of the input field I am trying to pre-populate is 'forminator-field-phone-1'

Thank you very much for your help,

Keith

Is there any documentation that you are following?
I tried searching through the forum but I couldn't find anything similar to my issue.

Is there a similar example that we can see?
No

What is the link to your site?
Under development but I can provide full access if required (via a private box), many thanks.

#2037679

Nigel
Supporter

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

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

Hi Keith

There are two parts to this: how to get the phone number belonging to the logged in user, and how to use that value to prepopulate a Forminator form.

We can't really help with the second part: if you cannot use shortcodes to provide a default value for a form, you'll need to consult with the Forminator documentation or support about what is possible here.

As for the first part, if you have connected the client post type to users with the client role, I assume you have done that by making the user the author of the client post.

So on the page where the form is displayed, in PHP you can find the ID of the current user (who will be submitting the form) using get_current_user_id() (https://developer.wordpress.org/reference/functions/get_current_user_id/). You can then use get_posts (https://developer.wordpress.org/reference/functions/get_posts/) to retrieve the client post authored by that user, and you can finally retrieve the phone custom field value using get_post_meta (https://developer.wordpress.org/reference/functions/get_post_meta/). Bear in mind the Types fields are saved with a 'wpcf-' prefix, so a Types field with slug "client-phone-number" would have a meta_key of 'wpcf-client-phone-number'.

#2037797

Minesh
Supporter

Languages: English (English )

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

Changing the ticket status.