My Validation class is
use Phalcon\Validation,
Phalcon\Validation\Validator\PresenceOf,
Phalcon\Validation\Validator\Email;
use Phalcon\Validation\Validator\Regex;
class MemberBulkFormAddVal extends Validation
{
public function initialize()
{
for ($i = 1; $i <= MEMBER_BULK_ADD_COUNT; $i++) {
$this->add('member_first_name_$i', new PresenceOf(array(
'message' => "The First name is required $i"
)));
$this->add('member_first_name_$i', new Regex(array(
'message' => "The First name is invalid $i",
'pattern' => '/^[A-Za-z ]*$/'
)));
$this->add('member_last_name_$i', new PresenceOf(array(
'message' => "The Last name is required $i"
)));
}
}
}
My Form Class is
use Phalcon\Forms\Form,
Phalcon\Forms\Element\Text,
Phalcon\Forms\Element\Select,
Phalcon\Forms\Element\Hidden,
Phalcon\Forms\Element\Password,
Phalcon\Forms\Element\Submit;
use Phalcon\Validation;
use Phalcon\Forms\Element\Check;
class MemberBulkAddForm extends Form
{
/**
* Forms initializer
*
* @param Member $user
* @param array $options
*/
public function initialize($user, $options)
{
for ($i = 1; $i <= MEMBER_BULK_ADD_COUNT; $i++) {
$fname = new Text("member_first_name_$i", array('maxlength' => 30 ));
$this->add($fname);
$lname = new Text("member_last_name_$i", array('maxlength' => 30 ));
$this->add($lname);
}
$submit = new Submit("submit");
$this->add($submit);
}
}
Thanks