PageRenderTime 37ms CodeModel.GetById 19ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

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