Ecshop Registration page Add a recommendation person validation method Summary

Source: Internet
Author: User
Tags php file trim

Method One,

Add the recommended candidate Fill box when registering:

1, open/languages/zh_cn/user.php.

Ctrl+f, find $_lang[' label_password '] = ' password ';
Add one line below: $_lang[' label_rec_user ' = ' referrer ';

Save changes

2, open/themes/Current topic directory/USER_PASSPORT.DWT

Ctrl+f, finding

Paste the following code (which can be modified according to your theme style): program code

<<tr>
<<TD align= "right" >{$lang. Label_rec_user}
<<td>
<<input name= "Rec_user" type= "text" size= "" id= "Rec_user" class= "INPUTBG"/>
<</td>
<</tr>

Save changes

3, open/user.php.

Ctrl+f, Find $email = isset ($_post[' email '))? Trim ($_post[' email ')]: ';
Add one line below: $rec _user = isset ($_post[' Rec_user '))? Trim ($_post[' rec_user ']): ';
Ctrl+f, find if (register ($username, $password, $email, $other)!== false)
Modified to: if (Register ($username, $password, $email, $rec _user, $other)!== false)

4, open/includes/lib_passport.php.

Ctrl+f, find * @param string $email registered Email
Add one line below: * @param string $rec _user referrer username (This step can be skipped, just add a comment)
Ctrl+f, find the function register ($username, $password, $email, $other = Array ())
Modified to: Function register ($username, $password, $email, $rec _user, $other = Array ())
Ctrl+f, find//Set referrer
Put the following program code


$sql = ' Update '. $GLOBALS [' ECS ']->table (' users '). ' SET parent_id = '. $up _uid. ' Where user_id = '. $_session[' user_id '];
$GLOBALS [' DB ']->query ($sql);

Replace with program code


if (Empty ($rec _user))
{
$rec _userid= $up _uid;
}
Else
{

$recsql = "Select user_id from". $GLOBALS [' ECS ']->table (' users '). "Where user_name = ' $rec _user '";
$recone = $GLOBALS [' db ']->getone ($recsql);

if ($recone)
{
$rec _userid= $recone [' user_id '];
}
Else
{
$rec _userid=0;
}

}

$sql = ' Update '. $GLOBALS [' ECS ']->table (' users '). ' SET parent_id = '. $rec _userid. ' Where user_id = '. $_session[' user_id '];
$GLOBALS [' DB ']->query ($sql);

5, open/js/user.js.

Ctrl+f, find var password = utils.trim (frm.elements[' password '].value);
Add one line below: var rec_user = Utils.trim (frm.elements[' Rec_user '].value);

{$lang. Label_rec_user}

Method Two,

The main modification of the 4 page idea, is to copy the user name Input function to recommend people on the line do not need to change the bottom

1. Foreground template user_passport.dwt
2.js (jquery implemented) file User.js
3. Front desk user.php
4. lib_passport.php

1 First add the referrer input HTML attribute to the relevant location in the user registration template

Ecshop Registration page Add recommender validation feature

<!--email-->
<div class= "INPUTBG" >
<label class= "LabelBox" >
<input name= "Email" type= "text" id= "email" onblur= "checkemail (this.value);" onkeyup= "Checkemail (this.value);" Placeholder= "{$lang. Label_email}" >
</label>
<span class= "T_text" >{$lang .label_email}</span>
<span class= "Error_icon" ></span>
</div>
<div class= "Err_tip" id= "Email_notice" ><em></em> </div>

<!--reference person-->
<div class= "INPUTBG" >
<label class= "LabelBox" >
<input name= "Rec_user" type= "text" id= "Rec_user" onblur= "is_rec_registered" (This.value); "Onkeyup=" is_rec_  Registered (this.value); " Placeholder= "{$lang. Label_rec_user}" >
</label>
<span class= "T_text" > {$lang .label_rec_user}</span>
<span class= "Error_icon" ></span>
</div>
<div class= "Err_tip" id= "Rec_user_notice" ><em></em> </div>
The is_rec_registered (this.value) JS function needs to be modified in User.js

2. Open User.js File

Find Method function is_registered (username), copy and paste a modified name to function is_rec_registered (rec_user), independently verify that the referrer is a registered user,

The code is as follows:

The referrer modifies the start.
function is_rec_registered (rec_user)
{
var submit_disabled = false;
var Unlen = Rec_user.replace (/[^\x00-\xff]/g, "* *"). Length;

if (Rec_user = = ")
{
document.getElementById (' Rec_user_notice '). InnerHTML = ' Recommended person is not allowed to be empty! '
var submit_disabled = true;
}

if (!chkstr (Rec_user))
{
document.getElementById (' Rec_user_notice '). InnerHTML = ' Recommended person contains illegal characters ';
var submit_disabled = true;
}
if (Unlen < 3)
{
document.getElementById (' Rec_user_notice '). InnerHTML = ' Recommended person length cannot be less than 3 characters. ';
var submit_disabled = true;
}
if (Unlen > 14)
{
document.getElementById (' Rec_user_notice '). InnerHTML = ' Recommended person length is less than 14 characters. ';
var submit_disabled = true;
}
if (submit_disabled)
{
document.forms[' formuser '].elements[' Submit '].disabled = ' disabled ';
return false;
}
Ajax.call (' user.php?act=is_rec_registered ', ' rec_user= ' + rec_user, rec_registed_callback, ' get ', ' TEXT ', true, true);
}

Register Ajax.call called function rec_registed_callback () Change function implementation according to the true and false state of the returned result, the page prompts the information (the referrer does not exist ...)

function Rec_registed_callback (Result)
{
if (result = = "true")
{

$ ("#rec_user"). Parent (). Removeclass ("Params_error");
$ ("#rec_user"). Parent (). addclass ("params_success");

document.getElementById (' Rec_user_notice '). InnerHTML = "<em></em>"; Zhouhuan
document.forms[' formuser '].elements[' Submit '].disabled = ';
}
Else
{

$ ("#rec_user"). Parent (). Removeclass ("params_success");
$ ("#rec_user"). Parent (). addclass ("Params_error");
document.getElementById (' Rec_user_notice '). InnerHTML = ' referrer does not exist, please re-enter ';
document.forms[' formuser '].elements[' Submit '].disabled = ' disabled ';
}
}

Recommended person to modify end


3. Modify user.php file Important!!!!

First find $not _login_arr =array (' login ', ' act_login '; In this array, the is_rec_registered of the act is added.
$not _login_arr =
Array (' login ', ' act_login ', ' register ', ' Act_register ', ' Act_edit_password ', ' Get_password ', ' send_pwd_email ', ' Password ', ' signin ', ' add_tag ', ' collect ', ' return_to_cart ', ' logout ', ' email_list ', ' validate_email ', ' Send_hash_ Mail ', ' order_query ', ' is_registered ',
' is_rec_registered ', ' check_email ', ' clear_history ', ' qpassword_name ', ' get_passwd_question ', ' check_answer ', ' oath ' , ' Oath_login ', ' other_login ');

Add the following code to perform the following action when act = = is_rec_registered (check if the referrer is registered)

/* Verify that the reference is registered. *
ElseIf ($action = = ' is_rec_registered ')
{

Include_once (Root_path. ' includes/lib_passport.php ');

$rec _user = Trim ($_get[' rec_user '));
$rec _user = Json_str_iconv ($rec _user);

if ($user->check_user ($rec _user) | | | admin_registered ($REC _user))
{
Echo ' true ';
}
Else
{
echo ' false ';
}
}

Finally, in the lib_passport.php file
Find $up _uid = Get_affiliate ();

The following if statement is replaced by (the original is based on ID lookup, now according to Rec_user)

If (!empty ($rec _user))
{
     $recsql = "Select user_id from". $GLOBALS [' ECS ']->table (' users '). "WHERE user_name = ' $rec _user '";
       $recone = $GLOBALS [' db ']->getone ($recsql);
       if ($recone)
     {
            $up _uid= $recone;
     }
}
 
General process thinking so,   specifically to your own actual to modify the details, hoping to help you

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.