Combined with xajax, smarty detects simple user names-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;? Php & nbsp; **************************************** * & nbsp; & nbsp; Title: smarty combined with xajax to detect simple instances of user names & nbsp; Author: leehui1983 (huibo) & nbsp; FinishDate & nbsp;: 2006-12-09 & nbsp; * script ec (2); script

/*************************************** **

Title: Combined with xajax, smarty detects simple user name instances
Author: leehui1983 (Boss Hui)
Finish Date: 2006-12-09

**************************************** */

// To avoid Chinese garbled characters, you need to modify the default encoding in xajax. inc. php: define ('xajax _ DEFAULT_CHAR_ENCODING ', 'gbk') UTF8 encoding format file.

Require_once ('./libs/Smarty. class. php'); // contains the smarty class library
Require ('./xajax. inc. php'); // contains the xajax class library

Function checkusername ($ textvalue) {// compile the required PHP function
$ Checkresult = ($ textvalue = 'test '? 'The user name has been registered ': 'registration ');
$ Objresponse = new xajaxResponse (); // instantiate the xajaxresponse object
$ Objresponse-> addassign ("result", "innerHTML", $ checkresult); // add content to the element whose ID is result. $ checkresult
Return $ objresponse; // return result text
}

$ Xajax = new xajax (); // instantiate an xajax object
$ Smarty = new Smarty (); // instantiate a smarty object
$ Smarty-> template_dir = "./templates"; // set the template directory
$ Smarty-> compile_dir = "./templates_c"; // set the compilation directory
$ Smarty-> caching = false; // sets the cache mode.
/*************************************** **************
Left and right boundary characters. The default value is {}.
Conflict, so it is recommended to set it to <{}> or another.
**************************************** *************/
$ Smarty-> left_delimiter = "<{";
$ Smarty-> right_delimiter = "}> ";


$ Xajax-> registerFunction ("checkusername"); // register the checkusername Function
$ Xajax-> processRequests (); // call xajax to take over the request

$ Smarty-> assign ('xajax _ javascript ', $ xajax-> getJavascript ('. /xajax/'); // output JS Code, note ('. the parameter in/xajax/') is xajax. inc. php parent directory, which can be entered differently under the consent directory; otherwise, it must be entered
$ Smarty-> assign ('title', 'smarty combined with xajax detection username simple instance'); // replace template content
$ Smarty-> display ('index. tpl '); // display template content
?>



<{$ Title}>
<{$ Xajax_javascript}> <{* enabling smarty to support xajax *}>




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.