Skip to content

Instantly share code, notes, and snippets.

@harikt
Created February 25, 2010 17:06
Show Gist options
  • Save harikt/314732 to your computer and use it in GitHub Desktop.
Save harikt/314732 to your computer and use it in GitHub Desktop.
<?php
// include auto-loader class
require_once 'Zend/Loader/Autoloader.php';
//register auto-loader
$loader = Zend_Loader_Autoloader::getInstance();
//setView
$view = new Zend_View();
$view->setEncoding("ISO-8859-1");
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->setView($view);
$form = new Zend_Form();
$form->setAction('')
->setMethod('post')
->setView($view);
// Create and configure username element:
$username = $form->createElement('text', 'username');
$username->addValidator('alnum')
->addValidator('regex', false, array('/^[a-z]+/'))
->addError("Only characters")
->addValidator('stringLength', false, array(6, 20))
->addError("Minimum 5 characters")
->setRequired(true)
->addFilter('StringToLower')
->setLabel('Username');
// Create and configure password element:
$password = $form->createElement('password', 'password');
$password->addValidator('StringLength', false, array(6))
->setRequired(true)
->setLabel('Password');
// Add elements to form:
$form->addElement($username)
->addElement($password)
->addDisplayGroup( array('username', 'password'),
'loginDetails',
array('legend' => 'Login Details'));
// use addElement() as a factory to create 'Login' button:
//->addElement('submit', 'login', array('label' => 'Login'));
if( $form->isValid($_POST) ) {
// success!
$success = "Success";
} else {
// failure!
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Testing Zend form</title>
</head>
<body>
<?php echo $form; ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment