Location: PHPKode > projects > pMH > pmh/src/user/actCreateLoginForm.php
<?php 
/*

$Header: /cvs/hol/src/user/actCreateLoginForm.php,v 1.6 2005/04/12 17:08:06 jakuza Exp $

<fusedoc fuse="actCreateQLogin.php">

   <responsibilities>
      Creates quick login form object
   </responsibilities>

   <properties>
      <history author="" date="2003 December 10" email="" type="create" />
      <note>
      </note>
   </properties>

   <io>
      <in>
         <string name="self" optional="false" />
         <string name="XFA_Login" scope="request" optional="false" comment="" />
		 <string name="XFA_RegistrationForm" scope="request" optional="false" comment="" />
      </in>
      <out>
         <structure name="login" scope="request" optional="false" comment="" />
		 <structure name="password" scope="request" optional="false" comment="" />
		 <structure name="logit" scope="request" optional="false" comment="" />
      </out>
   </io>

</fusedoc>
*/

// TODO Code duplication: actCreateLoginForm.php and actCreateQLogin do the same thing. They had to be splitted due to form conflicts. This should be improved.

$MainLogin = new jForm('MainLogin', $GLOBALS['language']['forms']['formdouble']);

$MainLogin->ACTION = fa($XFA['XFA_Login']);

# Give a name to hidden input field so you can tell whether the form is to
# be outputted for the first or otherwise it was submitted by the user.
$MainLogin->AddInput(array(
	'TYPE' => 'hidden',
	'NAME' => 'logit',
	'VALUE' => 1
));

# Hidden field to keep final destination after login
if (isset($_GET['returnFuseaction']) && eregi("^.*\..*$", $_GET['returnFuseaction']))
	$returnFuseaction = $_GET['returnFuseaction'];	// TODO Validation!!!
else $returnFuseaction = '';	// TODO No static XFA's....

# Set fuseaction to return to after login
$MainLogin->AddInput(array(
	'TYPE'	=>	'hidden',
	'NAME'	=>	'returnFuseaction',
	'VALUE'	=>	$returnFuseaction
));

# Hidden field to keep final destination GET parameters after login
if (isset($_GET['returnParams']))
	$returnParams = $_GET['returnParams'];	// TODO Validation!!!
else $returnParams = '';	// TODO No static XFA's....

# Set GET parameters to add to redirection URL after login
$MainLogin->AddInput(array(
	'TYPE' => 'hidden',
	'NAME' => 'returnParams',
	'VALUE' => urldecode($returnParams)
));

$MainLogin->AddInput(array(
	'TYPE'	=>	'text',
	'NAME'	=>	'username',
	'ID'	=>	'username',
	'LABEL'	=>	$GLOBALS['language']['forms']['label']['username'],
	'VALUE'	=>	'',	// $GLOBALS['language']['forms']['label']['username'],
	'MAXLENGTH'	=>	$GLOBALS['CONFIG']['MAXUSERNAME'],
	'CLASS'	=>	'loginbox',
	'ONCLICK'	=>	"javascript: this.value=''",
	'ValidateAsNotEmpty'	=>	1,
	'ValidateAsNotEmptyErrorMessage'	=>	$GLOBALS['language']['forms']['label']['username'].$GLOBALS['language']['forms']['empty'],
	'ValidateMinimumLength'	=>	$GLOBALS['CONFIG']['MINUSERNAME'],
	'ValidateMinimumLengthErrorMessage'	=>	$GLOBALS['language']['forms']['label']['username'].$GLOBALS['language']['forms']['tooshort'],
	'ValidateRegularExpression'	=>	'^[a-zA-Z0-9_]+$',
	'ValidateRegularExpressionErrorMessage'	=>	$GLOBALS['language']['forms']['label']['username'].$GLOBALS['language']['forms']['invalid'],
	'ValidateErrorMessage'	=>	$GLOBALS['language']['forms']['label']['username'].$GLOBALS['language']['forms']['error']
));

$MainLogin->AddInput(array(
	'TYPE'	=>	'password',
	'NAME'	=>	'password',
	'ID'	=>	'password',
	'LABEL'	=>	$GLOBALS['language']['forms']['label']['password'],
	'MAXLENGTH'	=>	$GLOBALS['CONFIG']['MAXPASSWD'],
	'CLASS'	=>	'loginbox',
	'ValidateAsNotEmpty'	=>	1,
	'ValidateAsNotEmptyErrorMessage'	=>	$GLOBALS['language']['forms']['label']['password'].$GLOBALS['language']['forms']['empty'],
	'ValidateMinimumLength'	=>	$GLOBALS['CONFIG']['MINPASSWD'],
	'ValidateMinimumLengthErrorMessage'	=>	$GLOBALS['language']['forms']['label']['password'].$GLOBALS['language']['forms']['tooshort'],
	'ValidateRegularExpression'	=>	'^[a-zA-Z0-9_]+$',
	'ValidateRegularExpressionErrorMessage'	=>	$GLOBALS['language']['forms']['label']['password'].$GLOBALS['language']['forms']['invalid'],
	'ValidateErrorMessage'	=>	$GLOBALS['language']['forms']['label']['password'].$GLOBALS['language']['forms']['error']
));

$MainLogin->AddInput(array(
	'TYPE'	=>	'submit',
	'NAME'	=>	'submit',
	'ID'	=>	'mlsubmit',
	'VALUE'	=>	$GLOBALS['language']['user']['loginsubmit']
));

$MainLogin->LoadInputValues($MainLogin->WasSubmitted('logit'));

# Collect data submitted by quick login form
if (isset($_POST['qlusername']) && isset($_POST['qlpassword'])) {
	$MainLogin->SetInputValue('username', $_POST['qlusername']);
	$MainLogin->SetInputValue('password', $_POST['qlpassword']);
}

# Empty the array that will list the values with invalid field after validation.
$verify = array();

# Check if the global array variable corresponding to hidden input field is
# defined, meaning that the form was submitted as opposed to being displayed
#for the first time.
if ($MainLogin->WasSubmitted('logit')) {
	# Therefore we need to validate the submitted form values.
	if (($MainLogin->errorMsg = $MainLogin->Validate($verify)) == "") {
		# It's valid, set the $this->searchit flag variable to 1 to tell the form is ready to be processed.
		$logit = 1;
	} else {
		/* It's invalid, set the $this->searchit flag to 0 and encode the returned error message
		 * to escape any non-ASCII ISO-latin 1 characters and HTML special characters.
		 */
		$logit = 0;
		$MainLogin->errorMsg = HtmlEntities($MainLogin->errorMsg);
	}
} else {
	/* The form is being displayed for the first time, so it is not ready to be processed
	 * and there is no error message to display.
	 */
	$MainLogin->errorMsg = "";
	$logit = 0;
}

$fuseFailure = !$logit;

?>
Return current item: pMH