Skip Navigation

[Closed] Pre-fill Custom field from SQL table

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 7 replies, has 2 voices.

Last updated by Minesh 3 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1636297

We have a fitness site which uses the WP Amelia plugin to book courses.
This plugin store booking information in a table "wpaa_amelia_users"

ID
First Name
Last Name
Email

and of course, all the booking relationships.

We use a CRM built around a Toolset CPT "Customers" with custom fields to store additional information.
Through a Cred form, that reads the customer id stored in the Amelia table, it create new entries in the CPT "Customers".

ID
Amelia ID
First Name
Last Name
Email
Phone
Address
.....
.....

Is it possible to "hard-sync" the First Name, Last Name and Email of the Amelia "wpaa_amelia_users" table to the Toolset CPT?
So that when users change their email address in the Amelia table it will be automatically updated also in the relative Toolset custom field (or the other way around)?

I can query
SELECT firstName FROM wpaa_amelia_users WHERE id=toolset_customer_id

but I don't really understand how to save this information in the "Customers" CPT.

Any help is really appreciated.
Thanks

#1636999

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

The thing is that Toolset stores the custom field value as per the WordPress standard to the postmeta table. So, any custom field value if you want to get/update you need to query the postmeta table.

You said:
Is it possible to "hard-sync" the First Name, Last Name and Email of the Amelia "wpaa_amelia_users" table to the Toolset CPT?
So that when users change their email address in the Amelia table it will be automatically updated also in the relative Toolset custom field (or the other way around)?

==> https://toolset.com/contractors/
As per your requirement the action should be fired when you update the value within the Amelia table and as you know Amelia table is not Toolset property.

This is a pure custom programming case that is beyond the scope of Toolset support policy. If you require custom programming for your project, please feel free to contact our certified partners:
=>

However, if you want that when creating the new customers entry using Toolset form you want to fetch the First Name, Last Name and Email of the Amelia "wpaa_amelia_users" table, you can use the Toolset form hook: cred_save_data.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

You can also try the hook "cred_filter_field_before_add_to_form" to assign default value before the custom field added to the form and check if that helps.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_filter_field_before_add_to_form

#1637363

Let's say I would prefill the Cred form field before submission, can I do that using the API instead of shortcodes?
I have this function, which read a user name from a table in a variable, but I still don't understand how do I set this value to the the form field.

add_filter('cred_filter_field_before_add_to_form', 'prefill_prima_scheda_cliente', 10, 1);
function prefill_prima_scheda_cliente($id){
	
	 if ($form_data['id']==8833)
    {
    global $wpdb;
   $table_name = "wpaa_amelia_users";
   $cid = $post->post_author;
	
$username = $wpdb->get_var("SELECT firstName FROM " . $table_name . " WHERE externalId=" . $cid);	

$field['wpcf-nome'] = $username; //HERE is where I don't understand how to set the form field "Name" using the variable $name

}
}
#1637365

Minesh
Supporter

Languages: English (English )

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

Can you please share access details and problem URL where you added the form. I hope when you are displaying the form with that page you are passing the customerID as URL param.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1637485

I think I have made the wrong question.
Let's simplify this.

I would like to prefill a Cred form field (Name) with a value.

When a user is logged in and open a page with a Cred Form, I would like to have his name (taken from his user data) prefilled in the form
hidden link

Can you help me to the right direction?
It should be done using php.
Thanks

#1637545

Minesh
Supporter

Languages: English (English )

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

Yes - sure.

But can you please share access details so that I can adjust your code and please share the problem URL where you added the form.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1637553

The site I am testing this function is on localhost.
That's why I couldn't send you access before.

Any other chance?

#1637567

Minesh
Supporter

Languages: English (English )

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

Is it possible for you to send me duplicator copy of your site?

More info:
=> https://toolset.com/faq/provide-supporters-copy-site/

The topic ‘[Closed] Pre-fill Custom field from SQL table’ is closed to new replies.