Skip to content

Instantly share code, notes, and snippets.

@phalcon phalcon/form.php
Created Jul 9, 2013

Embed
What would you like to do?
<?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
You can’t perform that action at this time.