Skip to content

Instantly share code, notes, and snippets.

@phalcon
Created July 9, 2013 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phalcon/5961217 to your computer and use it in GitHub Desktop.
Save phalcon/5961217 to your computer and use it in GitHub Desktop.
<?php
use Phalcon\Forms\Element\Password,
Phalcon\Validation\Validator\PresenceOf,
Phalcon\Validation\Validator\StringLength,
Phalcon\Validation\Validator\Confirmation;
class MyForm extends Phalcon\Forms\Form
{
public function initialize()
{
$password = new Password('password', array(
'required' => true,
'class' => 'span12'
));
$password->addValidators(array(
new PresenceOf(array(
'message' => 'password required',
)),
new StringLength(array(
'min' => 8,
'messageMinimum' => 'Password is too short. Minimum 8 characters'
)),
new Confirmation(array(
'message' => 'Password doesn\'t match confirmation',
'with' => 'repassword'
))
));
$this->add($password);
}
}
$myForm = new MyForm();
if (!$myForm->isValid(array())) {
foreach ($myForm->getMessages() as $message) {
echo $message->getType(), ': ', $message->getMessage(), '<br>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment