Пример #1
0
 /**
  * Step by step form processing
  *
  * Returns false when $this->afterSaveRouteUrl is set during the
  * processing, which happens by default when the data is saved.
  *
  * @return boolean True when the form should be displayed
  */
 protected function processForm()
 {
     // Make sure there is $this->formData
     $this->loadFormData();
     // Make sure there is a $this->_form
     $this->loadForm();
     // Create $this->_saveButton
     $this->addSaveButton();
     // Use Csrf when enabled
     if ($this->useCsrf) {
         $this->addCsrf();
     }
     if ($this->request->isPost()) {
         //First populate the form, otherwise the saveButton will never be 'checked'!
         $this->populateForm();
         // If there is a save button it should be checked, otherwise just validate
         if (!$this->_saveButton || $this->_saveButton->isChecked()) {
             if ($this->_form->isValid($this->formData)) {
                 // Remove all unwanted data
                 $this->cleanFormData();
                 // Save
                 $this->afterSave($this->saveData());
                 // Reroute (always, override function otherwise)
                 $this->setAfterSaveRoute();
             } else {
                 $this->onInValid();
             }
         } else {
             //The default save button was NOT used, so we have a fakesubmit button
             $this->onFakeSubmit();
         }
     }
     return !$this->getRedirectRoute();
 }
 /**
  * Step by step form processing
  *
  * Returns false when $this->afterSaveRouteUrl is set during the
  * processing, which happens by default when the data is saved.
  *
  * @return boolean True when the form should be displayed
  */
 protected function processForm()
 {
     // Make sure there is $this->formData
     $this->loadFormData();
     if (isset($this->formData[$this->stepFieldName])) {
         $this->currentStep = $this->formData[$this->stepFieldName];
     }
     $this->originalStep = $this->currentStep;
     // Make sure there is a $this->_form
     $this->loadFormFor($this->currentStep);
     if ($this->request->isPost()) {
         // \MUtil_Echo::track($this->formData);
         if ($this->_cancelButton && $this->_cancelButton->isChecked()) {
             $this->setAfterSaveRoute();
         } elseif ($this->isPreviousClicked()) {
             $this->loadFormFor($this->currentStep - 1);
         } else {
             if ($this->validateForm()) {
                 $this->afterFormValidationFor($this->currentStep);
                 if ($this->isNextClicked()) {
                     $this->loadFormFor($this->currentStep + 1);
                 } else {
                     /*
                      * Now that we validated, the form is populated. But I think the step
                      * below is not needed as the values in the form come from the data array
                      * but performing a getValues() cleans the data array so data in post but
                      * not in the form is removed from the data variable.
                      */
                     $this->formData = $this->_form->getValues();
                     if ($this->_finishButton && $this->_finishButton->isChecked()) {
                         // Save
                         $this->saveData();
                         // Reroute (always, override function otherwise)
                         $this->setAfterSaveRoute();
                     }
                 }
             } else {
                 $this->onInValid();
             }
         }
     }
     return !$this->getRedirectRoute();
 }
Пример #3
0
 /**
  * Tests that the isChecked method works as expected when using a translator.
  * @group ZF-4073
  */
 public function testIsCheckedReturnsExpectedValueWhenUsingTranslator()
 {
     $translations = array('label' => 'translation');
     $translate = new Zend_Translate('array', $translations);
     $submit = new Zend_Form_Element_Submit('foo', 'label');
     $submit->setTranslator($translate);
     $submit->setValue($translations['label']);
     $this->assertTrue($submit->isChecked());
     $submit->setValue('label');
     $this->assertFalse($submit->isChecked());
 }