run() public méthode

The array is expected to have keys named after fields. This function will call reset() before it runs.
Since: 2.0
public run ( array $data, Fuel\Validation\ResultInterface $result = null ) : Fuel\Validation\ResultInterface
$data array
$result Fuel\Validation\ResultInterface
Résultat Fuel\Validation\ResultInterface
Exemple #1
0
 /**
  * Validates a dataset
  *
  * @param [] $data
  *
  * @throws InvalidArgumentException
  */
 public function validate(array $data)
 {
     $result = $this->validator->run($data);
     if ($result->isValid() === false) {
         $error = $result->getErrors();
         $error = reset($error);
         throw new InvalidArgumentException($error);
     }
 }
Exemple #2
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());
 }
Exemple #3
0
 public function testNestedValidatorFailure()
 {
     $validator = new Validator();
     $validator->addField('test')->maxLength(5);
     $this->object->addField('child')->validator($validator);
     $this->object->addField('foobar')->required();
     $result = $this->object->run(['foobar' => 'test', 'child' => ['test' => '1234567890']]);
     $this->assertFalse($result->isValid());
     $this->assertEquals(['foobar'], $result->getValidated());
     $this->assertEquals(['child.test' => 'The field is longer than the allowed maximum length.'], $result->getErrors());
 }
Exemple #4
0
    $heading = $params->get('heading', false);
    $subHeading = $params->get('subheading', false);
}
// Check for post data
if ($post = JRequest::getVar('query', false, 'post')) {
    // Check honeypot
    if (!empty($_POST['birthday'])) {
        return true;
    }
    // Validate
    $val = new Validator();
    $val->addField('name')->required();
    $val->addField('number')->required()->number();
    $showSuburb ? $val->addField('suburb')->required() : null;
    $showProvince ? $val->addField('province')->required() : null;
    $result = $val->run($post);
    if ($result->isValid()) {
        // Save data and check token
        if (QueryHelperDatabase::save($post)) {
            // Email data
            QueryHelperMailer::send($params, $post);
            // We done
            print '<div class="ui message"><i class="ui circular checkmark icon"></i>Sent successfully, we will be in touch.</div>';
            // Dont show the formn
            return null;
        }
        // Message
        //JFactory::getApplication()->enqueueMessage('Please check that all required fields have been completed.', 'success');
    }
}
// Display data