Fix dynamic form validation behaviour, fix documentaion, fix correct isValid() call

- When a dynamic form is modified, no validation is performed, but
  the form is being populated with $this->populate.
- changed parent::isValid to $this->isValid, otherwise no custom validation
  logic could be implemented
- Updated documentation
- Fix CSRF protection by removing the time

refs #4439
This commit is contained in:
Jannis Moßhammer 2013-08-06 14:57:29 +02:00
parent 66592ecabf
commit ff62a82895
3 changed files with 17 additions and 3 deletions

View File

@ -24,11 +24,22 @@ In here you can add elements to your form, add validations and filters of your
choice. The creation method is invoked lazy just before a form is rendered or
*isValid()* is called.
In order to let icingaweb create a submit button for you (which is required for using the *isSubmittedAndValid*
method) you have to call the *setSubmitLabel($label)* method, which will add a
Zend_Form_Element_Submit element to your form.
#### Calling is *isSubmittedAndValid()*
*isSubmittedAndValid()* is used to check whether the form is ready to be processed or not.
It ensures that the current request method is POST, that the form was manually submitted
and that the data provided in the request is valid and gets repopulated in case its invalid.
and that the data provided in the request is valid and gets repopulated in case its invalid. This only works when
the sumbit button has been added with the *setSubmitLabel($label)* function, otherwise a form is always considered to be
submitted when a POST request is received.
If the form has been updated, but not submitted (for example, because the a button has been pressed that adds or removes
some fields in the form) the form is repopulated but not validated at this time. is SubmittedAndValid() returns false
in this case, but no errors are added to the created form.
#### Pre validation

View File

@ -294,13 +294,14 @@ abstract class Form extends Zend_Form
}
if ($submitted) {
// perform full validation if submitted
$this->preValidation($checkData);
return $this->isValid($checkData);
} else {
// only populate if not submitted
$this->populate($checkData);
return false;
}
}
/**

View File

@ -39,7 +39,8 @@ class DelayNotificationFormFormTest extends BaseFormTest
public function testInvalidMinuteValue()
{
$form = $this->getRequestForm(array(
'minutes' => 'SCHAHH-LAHH-LAHH'
'minutes' => 'SCHAHH-LAHH-LAHH',
'btn_submit' => 'foo'
), 'Monitoring\Form\Command\DelayNotificationForm');
$form->buildForm();
@ -50,6 +51,7 @@ class DelayNotificationFormFormTest extends BaseFormTest
);
$errors = $form->getErrors('minutes');
$this->assertCount(1, $errors, "Asserting an error to be added when the minutes value is invalid");
$this->assertEquals('notBetween', $errors[0], "Assert correct error message");
}
}