Form with creating user, save user_id in data form

Home Forums Quform WordPress Form with creating user, save user_id in data form

This topic is: resolved
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #28194
    ykontas
    Participant

    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.
    #28206
    ykontas
    Participant

    Little update of my needs.

    I have to set, the id of the new user in the created_by of the quform_entries table.

    tkx

    #28210
    Venom
    Participant

    Hi 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);
    }

    }

    #28216
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #28220
    ykontas
    Participant

    This is perfert !!!

    Thanks for your help Venom and Ally

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy