/source/Plug-in/xajax/examples/signup/signup.server.php

http://prosporous.googlecode.com/ · PHP · 132 lines · 93 code · 16 blank · 23 comment · 16 complexity · c9e54ed171e4ccc9cae67fbbd3e36245 MD5 · raw file

  1. <?php
  2. /*
  3. File: signup.server.php
  4. Example which demonstrates a xajax implementation of a sign-up page.
  5. Title: Sign-up Example
  6. Please see <copyright.inc.php> for a detailed description, copyright
  7. and license information.
  8. */
  9. /*
  10. Section: Files
  11. - <signup.php>
  12. - <signup.common.php>
  13. - <signup.server.php>
  14. */
  15. /*
  16. @package xajax
  17. @version $Id: signup.server.php 362 2007-05-29 15:32:24Z calltoconstruct $
  18. @copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson
  19. @license http://www.xajaxproject.org/bsd_license.txt BSD License
  20. */
  21. require_once ("signup.common.php");
  22. function processForm($aFormValues)
  23. {$_SESSION=array();
  24. $_SESSION[form]=$aFormValues;
  25. if (array_key_exists("username",$aFormValues))
  26. {
  27. return processAccountData($aFormValues);
  28. }
  29. else if (array_key_exists("firstName",$aFormValues))
  30. {
  31. return processPersonalData($aFormValues);
  32. }
  33. }
  34. function processAccountData($aFormValues)
  35. {
  36. $objResponse = new xajaxResponse();
  37. $bError = false;
  38. if (trim($aFormValues['username']) == "")
  39. {
  40. $objResponse->alert("Please enter a username.");
  41. $bError = true;
  42. }
  43. if (trim($aFormValues['newPass1']) == "")
  44. {
  45. $objResponse->alert("You may not have a blank password.");
  46. $bError = true;
  47. }
  48. if ($aFormValues['newPass1'] != $aFormValues['newPass2'])
  49. {
  50. $objResponse->alert("Passwords do not match. Try again.");
  51. $bError = true;
  52. }
  53. if (!$bError)
  54. {
  55. $_SESSION['newaccount']['username'] = trim($aFormValues['username']);
  56. $_SESSION['newaccount']['password'] = trim($aFormValues['newPass1']);
  57. $sForm = "<form id=\"signupForm\" action=\"javascript:void(null);\" onsubmit=\"submitSignup();\">";
  58. $sForm .="<div>First Name:</div><div><input type=\"text\" name=\"firstName\" /></div>";
  59. $sForm .="<div>Last Name:</div><div><input type=\"text\" name=\"lastName\" /></div>";
  60. $sForm .="<div>Email:</div><div><input type=\"text\" name=\"email\" /></div>";
  61. $sForm .="<div class=\"submitDiv\"><input id=\"submitButton\" type=\"submit\" value=\"done\"/></div>";
  62. $sForm .="</form>";
  63. $objResponse->assign("formDiv","innerHTML",$sForm);
  64. $objResponse->assign("formWrapper","style.backgroundColor", "rgb(67,149,97)");
  65. $objResponse->assign("outputDiv","innerHTML","\$_SESSION:<pre>".var_export($_SESSION,true)."</pre>");
  66. }
  67. else
  68. {
  69. $objResponse->assign("submitButton","value","continue ->");
  70. $objResponse->assign("submitButton","disabled",false);
  71. }
  72. return $objResponse;
  73. }
  74. function processPersonalData($aFormValues)
  75. {
  76. $objResponse = new xajaxResponse();
  77. $bError = false;
  78. if (trim($aFormValues['firstName']) == "")
  79. {
  80. $objResponse->alert("Please enter your first name.");
  81. $bError = true;
  82. }
  83. if (trim($aFormValues['lastName']) == "")
  84. {
  85. $objResponse->alert("Please enter your last name.");
  86. $bError = true;
  87. }
  88. 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']))
  89. {
  90. $objResponse->alert("Please enter a valid email address.");
  91. $bError = true;
  92. }
  93. if (!$bError)
  94. {
  95. $_SESSION['newaccount']['firstname'] = $aFormValues['firstName'];
  96. $_SESSION['newaccount']['lastname'] = $aFormValues['lastName'];
  97. $_SESSION['newaccount']['email'] = $aFormValues['email'];
  98. $objResponse->assign("formDiv","style.textAlign","center");
  99. $sForm = "Account created.<br />Thank you.";
  100. $objResponse->assign("formDiv","innerHTML",$sForm);
  101. $objResponse->assign("formWrapper","style.backgroundColor", "rgb(67,97,149)");
  102. $objResponse->assign("outputDiv","innerHTML","\$_SESSION:<pre>".var_export($_SESSION,true)."</pre>");
  103. }
  104. else
  105. {
  106. $objResponse->assign("submitButton","value","done");
  107. $objResponse->assign("submitButton","disabled",false);
  108. }
  109. return $objResponse;
  110. }
  111. $xajax->processRequest();
  112. ?>