Fuel\Validation\Validator::addField PHP Method

addField() public method

Adds a new field to the validation object
Since: 2.0
public addField ( string | Fuel\Validation\FieldInterface $field, string $label = null )
$field string | Fuel\Validation\FieldInterface
$label string Field name to use in messages, set to null to use $field
    public function addField($field, $label = null)
    {
        if (is_string($field)) {
            $field = new Field($field, $label);
        }
        if (!$field instanceof FieldInterface) {
            throw new InvalidArgumentException('VAL-007: Only FieldInterfaces can be added as a field.');
        }
        $this->fields[$field->getName()] = $field;
        $this->lastAddedField = $field;
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testValidateFieldWithEmptyString()
 {
     $this->object->addField('tel_no')->number();
     $data = array('tel_no' => '');
     $result = $this->object->run($data);
     $this->assertTrue($result->isValid());
     $data = array('tel_no' => '0');
     $result = $this->object->run($data);
     $this->assertTrue($result->isValid());
 }
All Usage Examples Of Fuel\Validation\Validator::addField