Commit 55d5a5d4 authored by Ad Schellevis's avatar Ad Schellevis

add Phalcon validators to model

parent d9e78ccb
......@@ -55,6 +55,10 @@ abstract class BaseField
*/
protected $internalReference = "";
/**
* @var string validation message string
*/
protected $internalValidationMessage = null;
/**
* @return bool returns if this a container type object (no data)
......@@ -120,6 +124,23 @@ abstract class BaseField
return $this->internalValue;
}
/**
* default setter
* @param $value set field value
*/
public function setValue($value)
{
$this->internalValue = $value;
}
/**
* @return array child items
*/
public function getChildren()
{
return $this->internalChildnodes;
}
/**
* set Default field value
* @param $value default value
......@@ -130,20 +151,19 @@ abstract class BaseField
}
/**
* default setter
* @param $value set field value
* @param $msg validation message (on failure)
*/
public function setValue($value)
public function setValidationMessage($msg)
{
$this->internalValue = $value;
$this->internalValidationMessage = $msg;
}
/**
* @return array child items
* @return array returns validators for this field type (empty if none)
*/
public function getChildren()
public function getValidators()
{
return $this->internalChildnodes;
return array();
}
}
\ No newline at end of file
<?php
/*
# Copyright (C) 2015 Deciso B.V.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------
package : Frontend Model Base
function: Email field type
*/
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\Email;
class EmailField extends BaseField
{
/**
* @var bool marks if this is a data node or a container
*/
protected $internalIsContainer = false;
/**
* @return array returns Email validator
*/
public function getValidators()
{
if ($this->internalValidationMessage == null) {
$msg = "email address invalid for " . $this->internalReference;
} else {
$msg = $this->internalValidationMessage;
}
return array(new Email(array('message' => $msg)));
}
}
\ No newline at end of file
......@@ -8,8 +8,9 @@
<Mask>[A-Z]</Mask>
</tag1>
<tagX>
<tag1 type="TextField">
<tag1 type="EmailField">
<Default>test1234</Default>
<ValidationMessage>you should input this!</ValidationMessage>
</tag1>
<tag2>
<tagZ></tagZ>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment