Home › Forums › Quform WordPress › Form with creating user, save user_id in data form
- This topic has 4 replies, 3 voices, and was last updated 5 years, 3 months ago by ykontas.
- AuthorPosts
- January 10, 2019 at 3:24 pm #28194ykontasParticipant
Hi,
I have made a form who create a wordpress user. with that code :
add_action('quform_post_process_2', function (array $result, Quform_Form $form) {
$username = $form->getValue('quform_2_5');
$email = $form->getValue('quform_2_7');
$password = $form->getValue('quform_2_13');
$user_id = wp_insert_user(array(
'user_login' => $username,
'user_pass' => $password,
'user_email' => $email
));
//On success
if ( ! is_wp_error( $user_id ) ) {
echo "User created : ". $user_id;
}
return $result;
}, 10, 2);
That work fine. But now in the same form, i need to get the id of the new user, and save it with the other data from the form.
How i can do that ?
thanks
- This topic was modified 5 years, 3 months ago by ykontas.
January 11, 2019 at 2:25 pm #28206ykontasParticipantLittle update of my needs.
I have to set, the id of the new user in the created_by of the quform_entries table.
tkx
January 12, 2019 at 2:46 am #28210VenomParticipantHi tkx,
You might try this.
add_action('quform_post_process_2', function (array $result, Quform_Form $form) {....... //below your code
//On success
if ( ! is_wp_error( $user_id ) ) {
echo "User created : ". $user_id;
global $wpdb;
$entry_id = $form->form_entry_id;
$sql = $wpdb->prepare("update wp_quform_entries set created_by = %s where id =%d", $user_id , $entry_id);
$result = $wpdb->query( $sql);
}}
January 14, 2019 at 1:39 pm #28216AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
January 14, 2019 at 3:55 pm #28220ykontasParticipantThis is perfert !!!
Thanks for your help Venom and Ally
- AuthorPosts
- You must be logged in to reply to this topic.