本文整理汇总了PHP中FormValidator::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP FormValidator::isValid方法的具体用法?PHP FormValidator::isValid怎么用?PHP FormValidator::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormValidator
的用法示例。
在下文中一共展示了FormValidator::isValid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
/**
* Handles requested "/" route
*/
public function indexAction()
{
// handle contact form
if (!empty($_POST['form_submit'])) {
$formValidator = new FormValidator($_POST['form'], $this->view);
// if there were no errors
if ($formValidator->isValid()) {
// format user submitted data
$data = array();
$data[] = '<table>';
foreach ($_POST['form'] as $field => $value) {
$data[] = '<tr><th>' . ucwords(str_replace(array('-', '_'), ' ', $field)) . '</th><td>' . nl2br($value) . '</td></tr>';
}
$data[] = '</table>';
// send message
$mailer = new Mailer();
$result = $mailer->sendSystemMessage(implode("\n", $data), $_POST['form_submit']);
if ($result) {
$this->router->redirect('/thanks');
die;
}
} else {
$this->errorMessages = $formValidator->getFormattedErrors();
}
}
}
示例2: isValid
/**
* @see Validator::isValid()
* @param $value mixed
* @return boolean
*/
function isValid()
{
// check if generally formatted as a date and if required
if (!parent::isValid()) {
return false;
}
// if parent::isValid is true and $value is empty, this value is optional
$fieldValue = $this->getFieldValue();
if (!$fieldValue) {
return true;
}
$validator = parent::getValidator();
return $validator->isValid($fieldValue, $this->_scopeMin, $this->_scopeMax);
}
示例3: testIsValid
/**
* @covers FormValidator::isValid
*/
public function testIsValid()
{
// We don't need to test the case where a validator is set, this
// is sufficiently tested by the other FormValidator* tests.
// Test default validation (without internal validator set and optional values)
$formValidator = new FormValidator($this->form, 'testData', FORM_VALIDATOR_OPTIONAL_VALUE, 'some.message.key');
self::assertTrue($formValidator->isValid());
// Test default validation (without internal validator set and required values)
$formValidator = new FormValidator($this->form, 'testData', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key');
self::assertFalse($formValidator->isValid());
$this->form->setData('testData', array());
$formValidator = new FormValidator($this->form, 'testData', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key');
self::assertFalse($formValidator->isValid());
$this->form->setData('testData', 'some value');
$formValidator = new FormValidator($this->form, 'testData', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key');
self::assertTrue($formValidator->isValid());
$this->form->setData('testData', array('some value'));
$formValidator = new FormValidator($this->form, 'testData', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key');
self::assertTrue($formValidator->isValid());
}