Skip Navigation

[Resolved] Possible to refer to form by name instead of ID?

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

Problem:
The user would like to use the form name instead of the form id in his custom code hooks. This is useful if we export/import forms to other websites as they will get different ids.

Solution:
Toolset forms are saved as posts for an internal custom post type "cred-form". You can use regular WordPress functions to get the name of the form from the id:

$form = get_post( $form_id );
$form_name = $form->post_title;

You can build a function that will return the name of the form from the form_id and use it inside your hooks:

if ( get_form_name( $form_data['id'] ) == 'My Form Name' )

Relevant Documentation:
https://developer.wordpress.org/reference/functions/get_post/

This support ticket is created 4 years, 8 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
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: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by coc-admin 4 years, 8 months ago.

Assisted by: Jamal.

Author
Posts
#1614523

Tell us what you are trying to do?
I have a custom plugin that uses "add_filter('cred_form_validate','validate_dup_serial_nbr',10,2);" to check for duplicate entries. Right now, it is conditioned on the entry of specific form ID's: if ($form_data['id'] == 1190......

I am copying the forms to a new site, therefore getting new ID's. To protect my plugin from breaking, I would rather refer to the forms by name or something else that remains consistent from site to site.

Is that possible?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
The old one is hidden link but is secured so you may not be able to reach it. The new one is still in development, and is also secured and private.

#1615089

Hello and thank you for contacting the Toolset support.

Toolset forms are saved as posts for an internal custom post type "cred-form". You can use regular WordPress functions to get the name of the form from the id:

$form = get_post( $form_id );
 $form_name = $form->post_title;

You can build a function that will return the name of the from from the form_id and use it inside your hooks:

if ( get_form_name( $form_data['id'] ) == 'My Form Name' )

I hope this helps. Let me know your feedback.

#1615119

My issue is resolved now. Thank you!