Skip Navigation

[Resolved] Using Toolset Hooks

This support ticket is created 3 years, 10 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 9 replies, has 2 voices.

Last updated by michaelO-8 3 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1640469

Tell us what you are trying to do?

I am trying to use toolset hooks to retrieve and modify form data.
I was trying to test this by using the 'cred_save_data' hook; however, I am unsure if I am properly calling the function. When trying to use a do_action() to call the hook, I get an error message indicating that only one argument is being passed in when there should be two. When utilizing hooks, can it automatically retrieve $post_id and $form_data or do we have to use another built in function to retrieve this data before passing it into the function as arguments? Also, is there a way to log data to the console through toolset (I am currently using a plugin to do so which utilizes the syntax: do_action( 'php_console_log', $my_string ) ).

Here is a test function I have written, to log the form id within the hook function (errors out when using do_action( 'cred_save_data'):

add_action( 'cred_save_data', 'my_save_data_action', 10, 2 );
function my_save_data_action( $post_id, $form_data){

if ($form_data['id']==3111) {
do_action( 'php_console_log', $form_data['id']);
}
}

do_action( 'cred_save_data', $post_id, $form_data)

What is the link to your site?
hidden link

#1641165

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

You just need to add the hook to your current theme's functions.php file or you can add it to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_action( 'cred_save_data', 'my_save_data_action', 10, 2 );
function my_save_data_action( $post_id, $form_data){

if ($form_data['id']==3111) {
do_action( 'php_console_log', $form_data['id']);
}
}

Where:
- When you submit the form with ID 3111, it will have the $post_id and $form_data content automatically, you do not need to do anything. You can var_dump it. For example:

var_dump($post_id);
var_dump($form_data);

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#1641947

Thank you for the thorough response! When I try to implement the hook as you have shown above, it still does not log to the console when I try to submit form 3111. The form is meant for editing though, so does the 'cred_save_data' only work on first time submissions and not updating info?

Also will var_dump log to the browser console as console.log would in javascript?

Updated:
I tried implementing the hook on the initial form submission and it still does not work. Not sure if it helps, but I attached an error message that I get in the browser.

#1642543

Minesh
Supporter

Languages: English (English )

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

so does the 'cred_save_data' only work on first time submissions and not updating info?
==>
Using Toolset form you can create either form that create new entry or edit existing one. For both kind of forms the cred_save_data hook works.

Can you please share problem URL and access details so I can check whats going worng.

*** 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.

#1646213

Minesh
Supporter

Languages: English (English )

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

Thank you for sharing access details.

Can you please share problem URL where I can see the form that you use to add the entry as well as edit the entry.

***Also, can you hide or delete the image from reply #1641947. I did not realize the message was not private and do not want that info the be public
==>
Ok. I've removed the image.

#1646755

Thank you so much for deleting the image!

Link to create form: hidden link

Link to edit form: hidden link

Thank you again!

#1647283

Minesh
Supporter

Languages: English (English )

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

Can you please check now:
=> hidden link
=> hidden link

I've adjusted the code as given under so the hook should fire when you submit both add/edit form with IDs 3110 or 3111 respectively.

add_action('cred_save_data', 'func_checking_console_log', 10, 2 );
function func_checking_console_log( $post_id, $form_data){

 if ($form_data['id']==3111 or $form_data['id']==3110) {
   do_action( 'php_console_log', $form_data['id']);
   var_dump($post_id);
    exit;
	
 }
 }

The issue was the code snippet you added was inactive ( I do not know if you inactivated intentionally), so I activated the code snippet and when I submit the form I can see the var_dump with post ID.
hidden link

#1648047

Yes, I switched it back to inactive when I wasn't testing it, but it does seem to be working now. I wonder if it had to do with adding exit at the end of the conditional.

My one concern is that the php_console_log still does not work. It is great that I can use var_dump, but I would prefer to be able to log data in the console. Is the php_console_log not compatible with toolset? It seems to work when it is called outside of the the hook.

#1648683

Minesh
Supporter

Languages: English (English )

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

My one concern is that the php_console_log still does not work. It is great that I can use var_dump, but I would prefer to be able to log data in the console. Is the php_console_log not compatible with toolset? It seems to work when it is called outside of the the hook.
==>
Yes - it could be the possibility.

What if you try to use the default wordpress function for error log:

error_log('id: ' . print_r($post_id, true));
error_log('form_data: ' . print_r($form_data, true));

For example:

add_action('cred_save_data', 'func_checking_console_log', 10, 2 );
function func_checking_console_log( $post_id, $form_data){
 
 if ($form_data['id']==3111 or $form_data['id']==3110) {

   error_log('id: ' . print_r($post_id, true));
   error_log('form_data: ' . print_r($form_data, true));
     
 }
 }

- The above function should log post ID and form data to your error log file.

More info:
=. hidden link

#1649197

Great, I will try the error_log out. Thank you again for all of your help!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.