Skip Navigation

[Resolved] Cred user form

This support ticket is created 5 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.

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

Last updated by olivierF 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1312453

You have several undefined variables here, like $user_id, $user_firstname, $user_lastname, and $user_email. You can use $post_id here as the User ID, and then use standard WordPress APIs like get_userdata to get more information about the User.
https://codex.wordpress.org/Function_Reference/get_userdata

#1312483

ok, I see.
I'm almost there, I have this as code but there must be something that does not work...

$user_info = get_userdata($userid);
      $prenom = $user_info->first_name;
      $nom = $user_info->last_name;
      $email = $user_info->user_email;

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

    if ($form_data['id']==62)
    {
    $my_post = array(
    'post_title'    => $prenom,
    'post_status'   => 'publish',
    'post_author'   => $post_ID,
    'post_type' => 'auteur',
	'meta_input'   => array(
		'wpcf-type' => $_POST['type'],
		'wpcf-prenom' => $prenom,
		'wpcf-nom' => $nom,
		'wpcf-societe' => $_POST['societe'],
		'wpcf-telephone' => $_POST['telephone'],
		'wpcf-email' => $email,
		'wpcf-site-web' => $_POST['site-web']
    )
);
wp_insert_post( $my_post );
    }
}
#1312485

Any variable you use in the cred_save_data hook should be defined in that hook, or created as a global variable. The $userid variable is still undefined, as far as I can tell.

#1312491

Thanks,
I do not understand how I can recover the information of the user who is not yet created.
I tried with this

$userid = $post_ID;  

The form is sent but the information is not transmitted

#1312499

I do not understand how I can recover the information of the user who is not yet created.
In the cred_save_data hook, the User has already been created. The first variable, $post_id, is equal to the User ID. If this isn't working, share the complete code please.

#1312519

here is the complet code :

$userid = $post_ID;
$user_info = get_userdata($userid);
      $prenom = $user_info->first_name;
      $nom = $user_info->last_name;
      $email = $user_info->user_email;

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

    if ($form_data['id']==62)
    {
		
    $my_post = array(
    'post_title'    => $prenom,
    'post_status'   => 'publish',
    'post_author'   => $post_ID,
    'post_type' => 'auteur',
	'meta_input'   => array(
		'wpcf-type' => $_POST['type'],
		'wpcf-prenom' => $prenom,
		'wpcf-nom' => $nom,
		'wpcf-societe' => $_POST['societe'],
		'wpcf-telephone' => $_POST['telephone'],
		'wpcf-email' => $email,
		'wpcf-site-web' => $_POST['site-web']
    )
);
wp_insert_post( $my_post );
    }
}
#1312529
Screen Shot 2019-08-08 at 11.12.55 AM.png

I see a few things here, please look at the screenshot. You should move the code at the top inside the "if" in your callback. Also all the $post_id variables should be identical but you have some capitalization differences.

#1312545

It still does not work ...
Here is the 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']==62)
    {
	$userid = $post_id;
	$user_info = get_userdata($userid);
    $prenom = $user_info->first_name;
    $nom = $user_info->last_name;
    $email = $user_info->user_email;
		
    $my_post = array(
    'post_title'    => $prenom,
    'post_status'   => 'publish',
    'post_author'   => $post_id,
    'post_type' => 'auteur',
	'meta_input'   => array(
		'wpcf-type' => $_POST['type'],
		'wpcf-prenom' => $prenom,
		'wpcf-nom' => $nom,
		'wpcf-societe' => $_POST['societe'],
		'wpcf-telephone' => $_POST['telephone'],
		'wpcf-email' => $email,
		'wpcf-site-web' => $_POST['site-web']
    )
);
wp_insert_post( $my_post );
    }
}
#1312547

Let's check the logs to see what is happening. Do you know how to activate server logs? If not, I can show you.
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 update the wp-config.php file on your server. Next, add error_log statements to your code to see what is happening.

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    if ($form_data['id']==62)
    {
error_log('in form 62');
    $userid = $post_id;
    $user_info = get_userdata($userid);
error_log('user_info: ' . print_r($user_info, true));
    $prenom = $user_info->first_name;
    $nom = $user_info->last_name;
    $email = $user_info->user_email;
         
    $my_post = array(
    'post_title'    => $prenom,
    'post_status'   => 'publish',
    'post_author'   => $post_id,
    'post_type' => 'auteur',
    'meta_input'   => array(
        'wpcf-type' => $_POST['type'],
        'wpcf-prenom' => $prenom,
        'wpcf-nom' => $nom,
        'wpcf-societe' => $_POST['societe'],
        'wpcf-telephone' => $_POST['telephone'],
        'wpcf-email' => $email,
        'wpcf-site-web' => $_POST['site-web']
    )
);
$auteur_id = wp_insert_post( $my_post );
error_log('auteur id: ' . $auteur_id);
    }
}

Then submit the User Form again. This will create an error_log.txt file in your site's root directory. Please open the file, copy the text, and paste it in your next reply.

#1312551

I can not find

define('WP_DEBUG', false); 

in the wp-config.php but i find it in wp-config-sample.php
Is that the same ?

#1312563

No, the sample file is just a template, it is not used. If WP_DEBUG is not defined in wp-config.php that is okay. Add the code just before it says "stop editing here":

define('WP_DEBUG', true);
ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
#1312569

Unfortunately, I followed all the indications but I can not find the error file in the 'root directory'.

#1312585

Okay, I see...may I have FTP access information? I'll take a look and find out what's going on.

#1312605

It's working here:
hidden link

I created two Users and two Auteurs were automatically created. I cannot tell why it is not working on the homepage. That template is part of your custom theme code.

#1312613

I just tested with this link but it still does not work on my side, I tried with several browsers.