Smarty combined with Xajax to detect user names

Source: Internet
Author: User
Tags parent directory

Look at the HTM file first.

<title><{$title}></title>
<{$xajax _javascript}><{* make Smarty support xajax*}>

<body>
<form name= "Check" >
Please enter user name:
<input type= "text" name= "username"/>
<input type= "button" name= "button" value= "Check user name"/>
<div id= "Result" ></div>
</form>
</body>

PHP Processing Code

<?php

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

Title:smarty combined with Xajax to detect a simple instance of user name
author:leehui1983 (leader of FAI)
Finish date:2006-12-09

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

In order to avoid Chinese garbled, need to change the default Encoding:define (' xajax_default_char_encoding ', ' GBK ') UTF8 code format file in xajax.inc.php need not change

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

function Checkusername ($textvalue) {//php functions needed to write
$checkresult = ($textvalue = = ' Test '? ' <font color=red> the username has been registered </font> ': ' <font color=red> can be registered </font> ');
$objresponse =new xajaxresponse ();//Instantiate Xajaxresponse Object
$objresponse->addassign ("result", "InnerHTML", $checkresult);//add content to the element that specifies the ID as result $checkresult
return $objresponse//Returns the result text
}

  $xajax =new xajax ()//Instantiate Xajax object
  $smarty =new smarty ()//Instantiate Smarty Object
  $smarty-> Template_dir = "./templates";//Set template directory
  $smarty->compile_dir = "./templates_c";//Set compilation directory
  $ Smarty->caching = false; Set caching method
 /*****************************************************
  left-right border characters, default to {}, But the actual application is easy to conflict with JavaScript
 , so it is recommended to set <{}> or other.
  *****************************************************/
  $smarty->left_delimiter = "<{";
  $smarty->right_delimiter = "}>";


$xajax->registerfunction ("Checkusername");//Register Checkusername function
$xajax->processrequests ();//Call Xajax to take over the request

$smarty->assign (' Xajax_javascript ', $xajax->getjavascript ('./xajax/'))//Output JS Code, note ('./xajax/') The parameter is xajax.inc.php parent directory, in the consent directory can be different fill in, or you must fill in
$smarty->assign (' title ', ' Smarty combination xajax detect user name simple instance ');/Replace template contents
$smarty->display (' index.tpl ');//Display template contents
?>

Related Article

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.