programing

Wordpress 2단계 등록 양식

magicmemo 2023. 3. 12. 10:39
반응형

Wordpress 2단계 등록 양식

다음을 달성하려고 하는데 어디서부터 시작해야 할지 모르겠어요.

두 단계로 등록/등록 양식을 작성하려고 합니다.

번째 순서: 2개의 입력 필드(이름, 이메일)를 가지는 것으로, 유저가 송신하면, 2번째 순서로의 링크와 함께 이메일이 송신됩니다.

스텝 2: 사용자는 자신의 이메일로 전송된 링크를 입력하고 두 번째 폼을 사용하여 페이지를 입력합니다.사용한 이메일과 이름 값 + 특정 페이지에 액세스할 수 있는 다른 2개의 필드(사용자 이름, 비밀번호)가 있습니다.

어디서 시작할지 찾을 수 없었고 다음을 충족하는 플러그인이 없습니다.

안부 전해요,

모스타파.

순서 1

먼저 2개의 템플릿을 작성해야 합니다(각 스텝에1개씩).첫 번째 템플릿에서는 두 번째 페이지로 사용자 이메일을 보낼 양식을 만들어야 합니다.에는 '다'가 있어야 .GET그의 이메일과 이름을 얻을 수 있는 속성입니다.다음으로 예를 제시하겠습니다(개선할 수 있음에 주의해 주십시오.

<?php 
/*
** Template Name: Step 1
*/

get_header();

if ( !empty( $_POST['firstname'] ) && !empty( $_POST['email'] ) ) {
    $link = 'http://my-site/step-2';
    $link = add_query_arg(
        array(
            'firstname' => $_POST['firstname'],
            'email'     => $_POST['email'],
        ),
        $link
    );

    $subject = 'New user registration';
    $message = 'Please click on the following link to complete your registration: ' . $link;
    $headers = array('Content-Type: text/html; charset=UTF-8');

    $result = wp_mail( $_POST['email'], $subject, $message, $headers );

    if ( $result ) {
        $message = 'Please check your email address to complete the registration';
    } else {
        $message = 'Something went wrong. Please contact the administrator';
    }

    echo $message;
} else {
?>
    <form method="POST" action="">
        <input type="text" name="firstname" placeholder="First Name">
        <input type="email" name="email" placeholder="Email address">
        <input type="submit" value="Submit">
    </form>
<?php
}
get_footer();

양식이 제출되고 모든 필드가 채워진 경우 간단한 검사를 만듭니다.그렇다면 2단계로 이메일을 보낼 수 있습니다.


순서 2

하다를 사용해서 첫 예요.$_GET2면 패스워드입니다.

<?php 
/*
** Template Name: Step 2
*/

get_header();

if ( !empty( $_POST['firstname'] ) && !empty( $_POST['email'] ) && !empty( $_POST['password'] ) ) {
    $user_id = username_exists( $_POST['username'] );

    if ( !$user_id and email_exists($_POST['email']) == false ) {

        $user_id = wp_create_user( $_POST['username'], $_POST['password'], $_POST['email'] );

        if ( $user_id ) {
            update_user_meta($user_id, 'first_name', $_POST['firstname']);
            $message = 'User has been created';
        }
    } else {
        $message = 'User already exists!';
    }

    echo $message;
} else {
?>
    <form method="POST" action="">
        <input type="text" name="firstname" value="<?php echo ( !empty( $_GET['firstname'] ) ) ? $_GET['firstname'] : '' ; ?>" placeholder="First Name">
        <input type="email" name="email" value="<?php echo ( !empty( $_GET['email'] ) ) ? $_GET['email'] : '' ; ?>" placeholder="Email Address">
        <input type="text" name="username" placeholder="Username">
        <input type="password" name="password" placeholder="Password">
        <input type="submit" value="Submit">
    </form>
<?php
}
get_footer();

두 번째 양식이 제출되고 이상이 없으면 사용자를 생성할 수 있습니다.생성되면 이름을 업데이트할 수 있습니다.

내 코드를 무제한으로 수정할 수 있지만, 이것이 기본입니다.예를 들어 필수 필드를 만들고 비밀번호 강도, 이름 길이 등을 확인할 수 있습니다.

다음은 여러분이 취할 수 있는 간단한 단계입니다.

사용자가 고유한지 확인하고 확인을 위해 자격 증명을 저장합니다.

if(!email_exists( $email )){

    /*
       Store credentials in a custom table 
       with a unique identifier, 
       hashed password and email. 

       Email user with the confirmation link ex.
       site.com/confirmation/<unique-identifier>
    */

}

서서 confirmation페이지 작성은 다음과 같이 사용자를 만듭니다.

// Confirm <unique-identifier>

// Create user
$user_id = wp_create_user( $email, $password, $email );

// Set user role
$user = new WP_User( $user_id );
$user->set_role( 'contributor' ); // or a custom role

것도 것 .Contact form 7 Multi-Step Form "플러그인정:

폼 7 다단계 폼으로 문의

데모를 시도해 보세요.

나중에 당신의 재능으로 이러한 등록 양식을 개발하는 방법을 알 수 있습니다.

용도에 맞게 이 플러그인을 사용해 보십시오.

  1. 커스텀 플러그인을 작성하고 쇼트 코드를 2개 만듭니다.

  2. 2페이지를 작성하고 2개의 쇼트코드를 각각 삽입합니다.

  3. 첫 번째 단축코드에 사용자가 이메일 주소와 이름을 입력할 수 있는 폼의 코드를 적습니다.

  4. 그런 다음 데이터베이스에 사용할 세부 정보(이름 및 이메일 주소)를 입력합니다.wp_insert_user그런 다음 이메일 주소로 이메일을 보내 두 번째 페이지에 대한 링크를 생성하고 링크에 암호화된 사용자 ID를 추가합니다.

  5. 사용자가 링크를 클릭하면 두 번째 페이지로 리디렉션됩니다. 두 번째 페이지에서는 선택 쿼리를 사용하여 이름과 전자 메일 주소가 자동으로 입력됩니다.

  6. 이 페이지에 나머지 모든 세부 정보를 삽입합니다.

이것을 사용해 보세요.고객님께 도움이 됩니다.https://www.sitepoint.com/building-a-multi-step-registration-form-for-wordpress/

저는 쇼트 코드를 사용하는 것을 선호합니다.여기 단계가 있습니다.완전한 코드:기스트

  1. 페이지(등록)를 만듭니다.예를들면[request_form action="/thanks"]

주의: 내부thanks_func사용자가 URL을 수정해야 합니다.$confirmation_body_text = "/signup/?hid='.$hash.'";

  1. 만들다thanks페이지를 열고 다음 단축코드를 추가합니다.

    [thanks] Thank you page [/thanks]

  2. 사용자 데이터베이스에 새 테이블 만들기:

    CREATE TABLEwp_new_user( 아이디int(11) NOT NULL, 이름.varchar(40) NOT NULL, 이메일varchar(80) NOT NULL, 사용자 이름varchar(30) DEFAULT NULL, 패스워드varchar(30) DEFAULT NULL, 해시varchar(40) DEFAULT NULL, 작성필_attimestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 갱신필_시timestamp NULL DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

첫 번째 단계에서는 다음과 같은 링크가 포함된 이메일이 전송됩니다.signup?hid=1679091c5a880faf6fb5e6087eb1b2dc

두 번째 단계에서는 이 고유한 이메일 해시에서 기존 사용자 레코드를 가져와 미리 입력합니다.name그리고.email[ ]를 클릭합니다.

  1. 2단계에서는 기존 사용자 레코드를 갱신합니다.

    함수 request_form_funcats, $content = null){ extract(shortcode_atts(array('id' =) false, 'class' => false, 'false', 'false', 'action' => "/thanks", 'key' => false, 'but' => false, 'button_text' =' > $smit) ;

    if( $class ) {  $class = ' ' . $class; }
    else { $class = ''; }
    
    if( empty($_GET) ){
        $next_step = false;
        $db_name = '';
        $db_email = '';
    }
    if(isset($_GET['hid'])){
        $email_hash = trim($_GET['hid']);
    
        $table = "wp_new_user";
        $project_data = new wpdb('root','root','wordpress','localhost');  // Testserver
        $rows = $project_data->get_results( $project_data->prepare(
            "
                SELECT id,name, email, hash FROM " . $table . "
                WHERE hash = %d
            ",
            $email_hash
        ) );
    
        $db_hash = $rows[0]->hash;
        if( $db_hash == $email_hash ) {
            $field_id = $rows[0]->id;
            $db_name = $rows[0]->name;
            $db_email = $rows[0]->email;
            $next_step = true;
        }
    }
    
    $out = '';
    
    if($id) { $id = '-'.$id; }
    
    $out .= '<div class="request_form'.$class.'">';
    $out .= '<div class="form-wrap">';
    if($title) {
        $out .= '<span class="title">' . $title . '</span>';
    }
    $out .= '<form id="step-form" class="cf" method="post" action="'.$action.'">';
    $out .= '<div class="field-wrap"><label for="fullname'.$id.'"><span class="desc">Name</span>';
    $out .= '<input type="text" id="fullname'.$id.'" name="fullname" data-required="true" placeholder="Jon Doe" value="'.$db_name.'"></label></div>';
    
    $out .= '<div class="field-wrap"><label for="email'.$id.'"><span class="desc">E-Mail</span>';
    $out .= '<input type="email" id="email'.$id.'" name="email" data-required="true" placeholder="name@domain.com" value="'.$db_email.'"></label></div>';
    
    if($next_step){
        $out .= '<div class="field-wrap"><label for="username'.$id.'"><span class="desc">Username</span>';
        $out .= '<input type="text" id="username'.$id.'" name="username" data-required="true" placeholder="username"></label></div>';
    
        $out .= '<div class="field-wrap"><label for="password'.$id.'"><span class="desc">Password</span>';
        $out .= '<input type="password" id="password'.$id.'" name="password" data-required="true" placeholder="password"></label></div>';
    

    $out . = "; } $out .= ";

    $out .= wp_nonce_field('step_form', 'step_form_nonce'.$id, true, false);
    $out .= '</form>';
    $out .= '</div>';
    $out .= '</div>';
    return $out;
    

    } add_shortcoderequestrequest_form', 'request_form_func' ;

  2. 그러면 감사 쇼트 코드를 만듭니다.thanks폼 데이터를 관리합니다.기본적으로 첫 번째 단계에서는 데이터를 저장해야 하며, 또한 이메일로 전송하여 데이터베이스에 저장할 고유 ID를 생성해야 합니다.링크가 'sign-up'처럼 표시됩니다.hid=1029091c5a880faf6fb5e6087eb1b2dc'

    함수 thanks_funcsets, $content = null){ $out = ' ;

    if(!empty($_POST) || wp_verify_nonce($_POST['step_form_nonce'],'step_form')){
    }
    else {
        $out .= '<div class="content-area">';
        $out .= '<h2 class="h1 page-title">Something went wrong</h2>';
        $out .= '<p class="block">Please Re-Submit your form again</p>';
        $out .= '</div>';
    
        return $out;
    }
    
    if(isset($_POST['fullname'])){ $fullname = trim($_POST['fullname']); }
    if(isset($_POST['email'])){ $email = trim($_POST['email']); }
    
    if(isset($_POST['username'])){ $username = trim($_POST['username']); }
    if(isset($_POST['password'])){ $password = trim($_POST['password']); }
    if(isset($_POST['hash'])){ $db_hash = trim($_POST['hash']); }
    $hash = md5( rand(0,1000) ); // Generate random 32 character hash and assign it to a local variable.
    
    $header .= "MIME-Version: 1.0\n";
    $header .= "Content-Type: text/html; charset=utf-8\n";
    $header .= "From:" . "admin@domain.com";
    
    $confirmation_text = "Thanks for Submitting your first form";
    $confirmation_body_text = "/registration/?hid='.$hash.'";
    
    $subject = "Please click the link below";
    $message = "Name: $fullname\n";
    $message .= "Email Address: $email\n";
    $message .= "Click the link: $confirmation_body_text\n";
    
    if (!empty($username) && !empty($password) && !empty($field_id)){
        update_custom_user($username, $password, $$db_hash);
    } else if (create_custom_user($fullname, $email, $hash) && wp_mail($email, $subject, $message, $header)){
    
    }
    
    $out .= '<div class="content-area">';
    $content = do_shortcode($content);
    $out .= $content;
    $out .= '</div>';
    
    return $out;
    

    }

    add_shortcode(고맙습니다), '고맙습니다_func' ;

나도 2개의 함수를 썼다.create_custom_user그리고.update_custom_user첫 번째 단계부터 데이터를 저장하고 업데이트합니다.username그리고.password2단계에서.

function create_custom_user($fullname, $email, $hash){
    global $wpdb;
    $table_name = $wpdb->prefix . "new_user";

    $cur_date = new DateTime();
    $cur_date->setTimezone(new DateTimeZone('Europe/Berlin'));
    $cur_date = $cur_date->format('d.m.Y').', '.$cur_date->format('G:i');


    $wpdb->insert( $table_name, array(
        'name' => $fullname,
        'email' => $email,
        'hash' => $hash,
        'created_at' => $cur_date

    ) );

    return true;
}


function update_custom_user($username, $password, $field_id){
    global $wpdb;
    $table_name = $wpdb->prefix . "new_user";

    $cur_date = new DateTime();
    $cur_date->setTimezone(new DateTimeZone('Europe/Berlin'));
    $cur_date = $cur_date->format('d.m.Y').', '.$cur_date->format('G:i');


    $wpdb->update( $table_name, array(
        'username' => $username,
        'password' => $password,
        'updated_at' => $cur_date
    ),
        array(
            "id" => $field_id
        ) );

    return true;
}

언급URL : https://stackoverflow.com/questions/40707591/wordpress-two-step-registration-form

반응형