源码网,源码论坛,源码之家,商业源码,游戏源码下载,discuz插件,棋牌源码下载,精品源码论坛

 找回密码
 立即注册
查看: 357|回复: 18

[AJAX相关] xajax的FORM例子

[复制链接]

7万

主题

861

回帖

32万

积分

论坛元老

Rank: 8Rank: 8

积分
329525
发表于 2006-11-25 00:00:00 | 显示全部楼层 |阅读模式
复制代码 代码如下:
<?php
// 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 = "<form id=\"signupForm\" action=\"javascript:void(null);\" onsubmit=\"submitSignup();\">";
                $sForm .="<div>First Name:</div><div><input type=\"text\" name=\"firstName\" /></div>";
                $sForm .="<div>Last Name:</div><div><input type=\"text\" name=\"lastName\" /></div>";
                $sForm .="<div>Email:</div><div><input type=\"text\" name=\"email\" /></div>";
                $sForm .="<div class=\"submitDiv\"><input id=\"submitButton\" type=\"submit\" value=\"done\"/></div>";
                $sForm .="</form>";
                $objResponse->addAssign("formDiv","innerHTML",$sForm);
                $objResponse->addAssign("formWrapper","style.backgroundColor", "rgb(67,149,97)");
                $objResponse->addAssign("outputDiv","innerHTML","\$_SESSION:<pre>".var_export($_SESSION,true)."</pre>");
        }
        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.<br />Thank you.";
                $objResponse->addAssign("formDiv","innerHTML",$sForm);
                $objResponse->addAssign("formWrapper","style.backgroundColor", "rgb(67,97,149)");
                $objResponse->addAssign("outputDiv","innerHTML","\$_SESSION:<pre>".var_export($_SESSION,true)."</pre>");
        }
        else
        {
                $objResponse->addAssign("submitButton","value","done");
                $objResponse->addAssign("submitButton","disabled",false);
        }
        return $objResponse->getXML();
}
$xajax = new xajax();
//$xajax->debugOn();
$xajax->registerFunction("processForm");
$xajax->processRequests();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
        <head>
                <?php $xajax->printJavascript(); ?>
                <style type="text/css">
                #formWrapper{
                        color: rgb(255,255,255);
                        background-color: rgb(149,67,97);
                        width: 200px;
                }
                #title{
                        text-align: center;
                        background-color: rgb(0,0,0);
                }
                #formDiv{
                        padding: 25px;
                }
                .submitDiv{
                        margin-top: 10px;
                        text-align: center;
                }
                </style>
                <script type="text/javascript">
                function submitSignup()
                {
                        xajax.$('submitButton').disabled=true;
                        xajax.$('submitButton').value="please wait...";
                        xajax_processForm(xajax.getFormValues("signupForm"));
                        return false;
                }
                </script>
        </head>
        <body>
                <div id="formWrapper">
                        <div id="title">Create a New Account</div>
                        <div id="formDiv">
                                <form id="signupForm" action="javascript:void(null);" onsubmit="submitSignup();">
                                        <div>Username:</div><div><input type="text" name="username" /></div>
                                        <div>Password:</div><div><input type="password" name="newPass1" /></div>
                                        <div>Confirm Password:</div><div><input type="password" name="newPass2" /></div>
                                        <div class="submitDiv"><input id="submitButton" type="submit" value="continue ->"/></div>
                                </form>
                        </div>
                </div>
                <div id="outputDiv">
                </div>
        </body>
</html>

回复

使用道具 举报

1

主题

2万

回帖

321

积分

中级会员

Rank: 3Rank: 3

积分
321
发表于 2023-4-11 07:13:30 | 显示全部楼层
下载来瞧瞧
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2023-8-15 06:16:02 | 显示全部楼层
飞飞飞飞飞飞飞飞飞飞飞飞飞
回复 支持 反对

使用道具 举报

6

主题

1万

回帖

174

积分

注册会员

Rank: 2

积分
174
发表于 2023-9-3 00:10:07 | 显示全部楼层
好人好人好人好人
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2024-3-21 23:59:52 | 显示全部楼层
抽根烟,下来看看再说
回复 支持 反对

使用道具 举报

0

主题

2万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2024-5-5 03:42:39 | 显示全部楼层
老衲笑纳了
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2024-5-19 03:56:09 | 显示全部楼层
下载来瞧瞧
回复 支持 反对

使用道具 举报

27

主题

2万

回帖

331

积分

中级会员

Rank: 3Rank: 3

积分
331
发表于 2024-5-25 09:16:55 | 显示全部楼层
哦哦哦ijhhsdj
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2024-7-12 10:19:21 | 显示全部楼层
了乐趣了去了去了去了去了
回复 支持 反对

使用道具 举报

0

主题

2万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2024-8-12 11:45:40 | 显示全部楼层
可以,看卡巴
回复 支持 反对

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

手机版|小黑屋|网站地图|源码论坛 ( 海外版 )

GMT+8, 2024-11-23 09:26 , Processed in 0.093035 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表