Skip Navigation

[Resolved] using cred api with user registration to populate post as user is created. I wa

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

Problem: I am trying to test that my CRED API calls are being triggered but my JavaScript browser console messages are not showing up as expected.

Solution: Instead of trying to write to the JavaScript console by echoing script tags, try using the PHP error log:

function add_parent_inquiry1($post_id, $form_data){
  error_log('You posted: add_parent_inquiry1'); // basic string
  error_log($post_id . '<br />'); // you can append markup like this
  error_log(print_r($form_data, true)); // log the contents of an array or associative array
}

Or, echo the information directly to the screen and call die(); to end PHP execution immediately.

Relevant Documentation: https://toolset.com/documentation/user-guides/debugging-toolset/

This support ticket is created 7 years, 3 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by oliverD 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#554367

I am trying to:using cred api with user registration to populate post as user is created. I was making progress and api was being called and could see console write coming back so I could see it was in the function. Then it completely stopped and is not calling the function for any cred user form but seems to be working for cred post form. Please help as have spent hours working on this and have trashed a lot of code to try to figure it out. I have tried 3 user form to see if they even hit the cred save function and none of them do. the post form does hit the same function on save.

Link to my site:

I expected to see:

Instead, I got:

#554371

code is
add_action('cred_save_data', 'add_parent_inquiry1',10,2);
function add_parent_inquiry1($post_id, $form_data){
debug_to_console('You posted: add_parent_inquiry1');
}

function debug_to_console( $data ) {
if(is_array($data) || is_object($data))
{
echo("<script>console.log('PHP: ".json_encode($data)."');</script>");
} else {
echo("<script>console.log('PHP: ".$data."');</script>");
}
}
this function works for posts

#554476

Hi, I'll try to help. Have you tried using the PHP error log? I see you are trying to write messages to the JavaScript console on-the-fly, which might be part of the problem. First, I would like to remove the JavaScript console logging from the process to narrow down the issue. Go in your wp-config.php file and look for define(‘WP_DEBUG’, false). Change it to:

define('WP_DEBUG', true);

Then add these lines, just before it says 'stop editing here':

ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');

Then change your cred_save_data callback:

function add_parent_inquiry1($post_id, $form_data){
  error_log('You posted: add_parent_inquiry1'); // basic string
  error_log($post_id . '<br />'); // you can append markup like this
  error_log(print_r($form_data, true)); // log the contents of an array or associative array
}

Submit the CRED form. If your callback is being fired at all, this will create an error_log.txt file in your site's root directory. Verify the callback is logging to the error log as expected. If not, we know that we need to investigate elsewhere. Let me know the results.

#556555

Got is resolved. It seems that on certain occasions that the console writes were not getting called. I used the echo and exit in the function to check that it was working and all looks fine now.