xajax的FORM例子有哪些?
来源:爱站网时间:2021-11-11编辑:网友分享
今天傍晚有同事来问爱站技术小编,xajax的FORM例子有哪些?小编列举了几个写了一篇文章,给大家参考参考,有兴趣的朋友可以点进来看看。
// signup.php
// demonstrates a simple multipage form using xajax
// and the xajax.getFormValues() function.
// using xajax version 0.1 beta4
// http://xajax.sourceforge.net
session_start();
include ("xajax.inc.php");
function processForm($aFormValues)
{
if (array_key_exists("username",$aFormValues))
{
return processAccountData($aFormValues);
}
else if (array_key_exists("firstName",$aFormValues))
{
return processPersonalData($aFormValues);
}
}
function processAccountData($aFormValues)
{
$objResponse = new xajaxResponse();
$bError = false;
if (trim($aFormValues['username']) == "")
{
$objResponse->addAlert("Please enter a username.");
$bError = true;
}
if (trim($aFormValues['newPass1']) == "")
{
$objResponse->addAlert("You may not have a blank password.");
$bError = true;
}
if ($aFormValues['newPass1'] != $aFormValues['newPass2'])
{
$objResponse->addAlert("Passwords do not match. Try again.");
$bError = true;
}
if (!$bError)
{
$_SESSION = array();
$_SESSION['newaccount']['username'] = trim($aFormValues['username']);
$_SESSION['newaccount']['password'] = trim($aFormValues['newPass1']);
$sForm = "";
$objResponse->addAssign("formDiv","innerHTML",$sForm);
$objResponse->addAssign("formWrapper","style.backgroundColor", "rgb(67,149,97)");
$objResponse->addAssign("outputDiv","innerHTML","\$_SESSION:
".var_export($_SESSION,true)."");
}
else
{
$objResponse->addAssign("submitButton","value","continue ->");
$objResponse->addAssign("submitButton","disabled",false);
}
return $objResponse->getXML();
}
function processPersonalData($aFormValues)
{
$objResponse = new xajaxResponse();
$bError = false;
if (trim($aFormValues['firstName']) == "")
{
$objResponse->addAlert("Please enter your first name.");
$bError = true;
}
if (trim($aFormValues['lastName']) == "")
{
$objResponse->addAlert("Please enter your last name.");
$bError = true;
}
if (!eregi("^[a-zA-Z0-9]+[_a-zA-Z0-9-]*(\.[_a-z0-9-]+)*@[a-z??????0-9]+(-[a-z??????0-9]+)*(\.[a-z??????0-9-]+)*(\.[a-z]{2,4})$", $aFormValues['email']))
{
$objResponse->addAlert("Please enter a valid email address.");
$bError = true;
}
if (!$bError)
{
$_SESSION['newaccount']['firstname'] = $aFormValues['firstName'];
$_SESSION['newaccount']['lastname'] = $aFormValues['lastName'];
$_SESSION['newaccount']['email'] = $aFormValues['email'];
$objResponse->addAssign("formDiv","style.textAlign","center");
$sForm = "Account created.
Thank you.";
$objResponse->addAssign("formDiv","innerHTML",$sForm);
$objResponse->addAssign("formWrapper","style.backgroundColor", "rgb(67,97,149)");
$objResponse->addAssign("outputDiv","innerHTML","\$_SESSION:
".var_export($_SESSION,true)."");
}
else
{
$objResponse->addAssign("submitButton","value","done");
$objResponse->addAssign("submitButton","disabled",false);
}
return $objResponse->getXML();
}
$xajax = new xajax();
//$xajax->debugOn();
$xajax->registerFunction("processForm");
$xajax->processRequests();
?>
printJavascript(); ?>
Create a New Account
以上内容就是爱站技术频道小编为大家分享的xajax的FORM例子有哪些?看完以上分享之后,大家应该都知道xajax的FORM例子有哪些了吧。
上一篇:什么是Ajax Hacking