validation - Symfony Validator modify form fields -


i have validator looks this:

    class validuspsaddressvalidator extends constraintvalidator     {         public function validate($protocol, constraint $constraint)         {             $verify = new uspsaddressverify('*******');             $uspsaddress = new uspsaddress();             $apartment = $protocol->getapartment();             $address = $protocol->getaddress();             $city = $protocol->getcity();             $state = $protocol->getstate();             $zip = $protocol->getzip();               $uspsaddress->setapt($apartment);             $uspsaddress->setaddress($address);             $uspsaddress->setcity($city);             $uspsaddress->setstate($state);             $uspsaddress->setzip5($zip);             $uspsaddress->setzip4('');             $verify->addaddress($uspsaddress);              $verify->verify();             $response = $verify->getarrayresponse();             $responseaddress = $response['addressvalidateresponse']['address'];               if ($verify->iserror()) {                 $this->context->buildviolation($constraint->message)                     ->addviolation();             }else{                 $protocol->setaddress($responseaddress['address2']);                 $protocol->setcity($responseaddress['city']);                 $protocol->setstate($responseaddress['state']);                 $protocol->setzip($responseaddress['zip5']);                  //****** below if ******************                 if($responseaddress['address2'] != $address || $responseaddress['city'] != $city || $responseaddress['state'] != $state || $responseaddress['zip5'] != $zip){                     $this->context->buildviolation($constraint->verify)                         ->addviolation();                 }              }         }     } 

looking @ final if statement , code within it... trying set fields usps response , validator gives user 1 last chance see updated data modify fields , re-validate again , long data matches usps data persist it. problem protocol->setxxxxx() sets data on object persisted, doesn't show data in fields when re-displays form...

the point of validator validate object, maybe try using data transformers or form listeners or event listeners, , skip doing kind of logic inside of validator.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -