当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Form::isValidPartial方法代码示例

本文整理汇总了PHP中Zend_Form::isValidPartial方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form::isValidPartial方法的具体用法?PHP Zend_Form::isValidPartial怎么用?PHP Zend_Form::isValidPartial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Form的用法示例。


在下文中一共展示了Zend_Form::isValidPartial方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSubFormTranslatorPreferredOverDefaultTranslator

 /**
  * @group ZF-9540
  */
 public function testSubFormTranslatorPreferredOverDefaultTranslator()
 {
     $defaultTranslations = array('isEmpty' => 'Default message');
     $subformTranslations = array('isEmpty' => 'SubForm message');
     $defaultTranslate = new Translator('ArrayAdapter', $defaultTranslations);
     $subformTranslate = new Translator('ArrayAdapter', $subformTranslations);
     Registry::set('Zend_Translator', $defaultTranslate);
     $this->form->addSubForm(new SubForm(), 'subform');
     $this->form->subform->setTranslator($subformTranslate);
     $this->form->subform->addElement('text', 'foo', array('required' => true));
     $this->assertFalse($this->form->isValid(array('subform' => array('foo' => ''))));
     $messages = $this->form->getMessages();
     $this->assertEquals('SubForm message', $messages['subform']['foo']['isEmpty']);
     $this->assertFalse($this->form->isValidPartial(array('subform' => array('foo' => ''))));
     $messages = $this->form->getMessages();
     $this->assertEquals('SubForm message', $messages['subform']['foo']['isEmpty']);
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:20,代码来源:FormTest.php

示例2: testErrorMessagesFromPartialValidationAreLocalizedWhenTranslateAdapterPresent

 public function testErrorMessagesFromPartialValidationAreLocalizedWhenTranslateAdapterPresent()
 {
     $this->_checkZf2794();
     $translations = (include dirname(__FILE__) . '/_files/locale/array.php');
     $translate = new Zend_Translate('array', $translations, 'en');
     $translate->setLocale('en');
     $this->form->addElements(array('foo' => array('type' => 'text', 'options' => array('required' => true, 'validators' => array('NotEmpty'))), 'bar' => array('type' => 'text', 'options' => array('required' => true, 'validators' => array('Digits')))))->setTranslator($translate);
     $data = array('foo' => '');
     if ($this->form->isValidPartial($data)) {
         $this->fail('Form should not validate');
     }
     $messages = $this->form->getMessages();
     $this->assertTrue(isset($messages['foo']));
     $this->assertFalse(isset($messages['bar']));
     foreach ($messages['foo'] as $key => $message) {
         if (array_key_exists($key, $translations)) {
             $this->assertEquals($translations[$key], $message);
         } else {
             $this->fail('Translation for ' . $key . ' does not exist?');
         }
     }
 }
开发者ID:vicfryzel,项目名称:zf,代码行数:22,代码来源:FormTest.php

示例3: testElementTranslatorPreferredOverDefaultTranslator

 /**
  * @group ZF-9364
  */
 public function testElementTranslatorPreferredOverDefaultTranslator()
 {
     $defaultTranslations = array('isEmpty' => 'Default message');
     $formTranslations = array('isEmpty' => 'Form message');
     $elementTranslations = array('isEmpty' => 'Element message');
     $defaultTranslate = new Zend_Translate('array', $defaultTranslations);
     $formTranslate = new Zend_Translate('array', $formTranslations);
     $elementTranslate = new Zend_Translate('array', $elementTranslations);
     Zend_Registry::set('Zend_Translate', $defaultTranslate);
     $this->form->setTranslator($formTranslate);
     $this->form->addElement('text', 'foo', array('required' => true, 'translator' => $elementTranslate));
     $this->form->addElement('text', 'bar', array('required' => true));
     $this->assertFalse($this->form->isValid(array('foo' => '', 'bar' => '')));
     $messages = $this->form->getMessages();
     $this->assertEquals(2, count($messages));
     $this->assertEquals('Element message', $messages['foo']['isEmpty']);
     $this->assertEquals('Form message', $messages['bar']['isEmpty']);
     $this->assertFalse($this->form->isValidPartial(array('foo' => '', 'bar' => '')));
     $messages = $this->form->getMessages();
     $this->assertEquals(2, count($messages));
     $this->assertEquals('Element message', $messages['foo']['isEmpty']);
     $this->assertEquals('Form message', $messages['bar']['isEmpty']);
 }
开发者ID:stunti,项目名称:zf2,代码行数:26,代码来源:FormTest.php

示例4: testCanValidatePartialNestedFormsWithElementsBelongingToArrays

    public function testCanValidatePartialNestedFormsWithElementsBelongingToArrays()
    {
        $form = new Zend_Form();
        $form->setElementsBelongTo('foobar');

        $form->addElement('text', 'firstName')
             ->getElement('firstName')
             ->setRequired(false);

        $form->addElement('text', 'lastName')
             ->getElement('lastName')
             ->setRequired(true);

        $subForm = new Zend_Form_SubForm();
        $subForm->setElementsBelongTo('foobar[baz]');
        $subForm->addElement('text', 'email')
                ->getElement('email')
                ->setRequired(true)
                ->addValidator('NotEmpty');

        $subSubForm = new Zend_Form_SubForm();
        $subSubForm->setElementsBelongTo('foobar[baz][bat]');
        $subSubForm->addElement('checkbox', 'home')
                   ->getElement('home')
                   ->setRequired(true)
                   ->addValidator('NotEmpty');

        $subForm->addSubForm($subSubForm, 'subSub');

        $form->addSubForm($subForm, 'sub')
             ->addElement('submit', 'save', array('value' => 'submit'));


        $data = array('foobar' => array(
            'lastName'  => 'Cow',
        ));
        $this->assertTrue($form->isValidPartial($data));
        $this->assertEquals('Cow', $form->lastName->getValue());
        $firstName = $form->firstName->getValue();
        $email     = $form->sub->email->getValue();
        $home      = $form->sub->subSub->home->getValue();
        $this->assertTrue(empty($firstName));
        $this->assertTrue(empty($email));
        $this->assertTrue(empty($home));

        $form->sub->subSub->home->addValidator('StringLength', false, array(4, 6));
        $data['foobar']['baz'] = array('bat' => array('home' => 'ab'));

        $this->assertFalse($form->isValidPartial($data), var_export($form->sub->subSub->home, 1));
        $this->assertEquals('1', $form->sub->subSub->home->getValue());
        $messages = $form->getMessages();
        $this->assertFalse(empty($messages));
        $this->assertTrue(isset($messages['foobar']['baz']['bat']['home']), var_export($messages, 1));
        $this->assertTrue(isset($messages['foobar']['baz']['bat']['home']['stringLengthTooShort']));
    }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:55,代码来源:FormTest.php

示例5: isValid

 /**
  * Overridden isValid() method for pre-validation code
  *
  * @param array $formData data typically from a POST or GET request
  *
  * @return bool
  */
 public function isValid($formData = array())
 {
     // Check if all 3 pieces of info are supplied
     $asn = isset($formData['letting_agent_asn']) ? preg_replace('/[^\\d]/', '', $formData['letting_agent_asn']) : '';
     $irn = isset($formData['tenant_reference_number']) ? preg_replace('/[^\\d]/', '', $formData['tenant_reference_number']) : '';
     $dob = isset($formData['tenant_dob']) ? preg_replace('/[^\\d\\/]/', '', $formData['tenant_dob']) : '';
     // If the IRN is not actually an IRN, but an IRIS reference number (i.e. prefixed with HLT)
     if (preg_match('/^HLT\\d+$/', $formData['tenant_reference_number'])) {
         return self::IRIS_LOGIN;
     }
     if ($dob != '') {
         try {
             //Check for a valid date of birth. If this causes an exception, end
             //the process here rather than passing up to the overriden method,
             //otherwise the same exception will be thrown again.
             $isDobError = false;
             $dob = new Zend_Date($dob);
         } catch (Zend_Exception $e) {
             $isDobError = true;
         }
         if ($isDobError) {
             $this->getElement('tenant_dob')->addError('Please provide a valid date of birth.');
             // Validate other fields, to keep the error messages consistent
             unset($formData['tenant_dob']);
             $dummy = parent::isValidPartial($formData);
             return false;
         }
     }
     //Continue the validation.
     $displayErrorMessage1 = false;
     $displayErrorMessage2 = false;
     $displayErrorMessage3 = false;
     $displayErrorMessage4 = false;
     if ($asn != '' && $irn != '' && $dob != '') {
         // Check if a record can be found
         $tatManager = new Manager_Referencing_Tat($irn);
         if ($tatManager->isLoginValid($asn, $dob)) {
             // Check if user allowed to login
             if (!$tatManager->isTatApplicable()) {
                 // Can't log in. Check if this is because the TAT has expired.
                 if ($tatManager->isTatExpired()) {
                     $displayErrorMessage1 = true;
                 } else {
                     //If the reference is of type INSIGHT or XPRESS, then provide a specific error message.
                     $referenceManager = new Manager_ReferencingLegacy_Munt();
                     $reference = $referenceManager->getReference($irn);
                     $product = $reference->productSelection->product;
                     if (isset($product->variables[Model_Referencing_ProductVariables::CREDIT_REFERENCE])) {
                         $displayErrorMessage2 = true;
                     } else {
                         //Set the generic form-level error.
                         $displayErrorMessage3 = true;
                     }
                 }
             }
         } else {
             // Can't find a record, set a form-level error
             $displayErrorMessage3 = true;
         }
     } else {
         // One or more fields are empty (when filtered), set a form-level error
         $displayErrorMessage4 = true;
     }
     //Display the error message if appropriate.
     if ($displayErrorMessage1) {
         $this->addError('Unfortunately we only hold information on the Tenant Application Tracker for 30 days and we believe
                          that your application was completed over a month ago. If you have any questions about your tenancy
                          application please speak directly with your letting agent.');
     } else {
         if ($displayErrorMessage2) {
             $this->addError('Oops, we\'re unable to match the information you\'ve entered, please check your details and try again.');
         } else {
             if ($displayErrorMessage3) {
                 $this->addError('I\'m sorry we\'ve been unable to find your application with the details that you\'ve provided. Please check the details that you entered and try again.');
             } else {
                 if ($displayErrorMessage4) {
                     $this->addError('Please ensure you complete all 3 fields before selecting submit.');
                 }
             }
         }
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:91,代码来源:Login.php

示例6: isValidPartial

 /**
  * Wrappter to track if the form has undergone a partial validation attempt
  *
  * @param array $data
  * @return type
  */
 public function isValidPartial(array $data)
 {
     $bValidPartial = parent::isValidPartial($data);
     $this->_bHasBeenValidated = true;
     return $bValidPartial;
 }
开发者ID:tlandn,项目名称:akvo-web,代码行数:12,代码来源:Form.php

示例7: testCanGetMessagesOfNestedFormsWithMultiLevelElementsBelongingToArrays

 public function testCanGetMessagesOfNestedFormsWithMultiLevelElementsBelongingToArrays()
 {
     $this->_checkZf2794();
     $form = new Zend_Form();
     $form->setElementsBelongTo('foo[bar]');
     $form->addElement('text', 'firstName')->getElement('firstName')->setRequired(false);
     $form->addElement('text', 'lastName')->getElement('lastName')->setRequired(true);
     $subForm = new Zend_Form_SubForm();
     $subForm->setElementsBelongTo('baz');
     $subForm->addElement('text', 'email')->getElement('email')->setRequired(true)->addValidator('NotEmpty');
     $subSubForm = new Zend_Form_SubForm();
     $subSubForm->setElementsBelongTo('bat[quux]');
     $subSubForm->addElement('checkbox', 'home')->getElement('home')->setRequired(true)->addValidator('InArray', false, array(array('1')));
     $subForm->addSubForm($subSubForm, 'subSub');
     $form->addSubForm($subForm, 'sub')->addElement('submit', 'save', array('value' => 'submit'));
     $data = array('foo' => array('bar' => array('lastName' => 'Cow')));
     $form->sub->subSub->home->addValidator('StringLength', false, array(4, 6));
     $data['foo']['bar']['baz'] = array('bat' => array('quux' => array('home' => 'ab')));
     $form->isValidPartial($data);
     $messages = $form->getMessages();
     $this->assertFalse(empty($messages));
     $this->assertTrue(isset($messages['foo']['bar']['baz']['bat']['quux']['home']), var_export($messages, 1));
     $this->assertTrue(isset($messages['foo']['bar']['baz']['bat']['quux']['home']['notInArray']), var_export($messages, 1));
 }
开发者ID:lortnus,项目名称:zf1,代码行数:24,代码来源:FormTest.php


注:本文中的Zend_Form::isValidPartial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。