Changeset 2122

Show
Ignore:
Timestamp:
10/10/07 14:37:43 (15 months ago)
Author:
david
Message:

Fixed an issue where forms with the same action would both get error messages inserted under certain circumstances, thanks Ross for the hint. Also, errors that could ultimately not be inserted are now stored in request attribute "orphaned_errors", namespace "org.agavi.filter.FormPopulationFilter?". Refs #303

Location:
branches/0.11
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/CHANGELOG

    r2119 r2122  
    55 
    66ADD: __sleep() and __wakeup() magic methods for AgaviModel to prevent Context serialization (#581) (David) 
    7 ADD: Ability to insert error messages into forms automatically using FormPopulationFilter (#303) (David) 
     7ADD: Ability to insert error messages into forms automatically using FormPopulationFilter (#303) (David, Ross Lawley) 
    88ADD: AgaviWebResponse::unsetCookie() (#577) (David, Ross Lawley) 
    99ADD: AgaviDoctrineDatabase (#381) (David, Ross Lawley) 
  • branches/0.11/src/filter/AgaviFormPopulationFilter.class.php

    r2121 r2122  
    242242      $forms = $this->xpath->query('//' . $this->ns . 'form[@action]'); 
    243243    } 
     244     
     245    // an array of all validation incidents; errors inserted for fields or multiple fields will be removed in here 
     246    $allIncidents = $vm->getIncidents(); 
     247     
    244248    foreach($forms as $form) { 
    245249      if($populate instanceof AgaviParameterHolder) { 
     
    270274      $remember = array(); 
    271275 
    272       // an array of all validation incidents; errors inserted for fields or multiple fields will be removed in here 
    273       $allIncidents = $vm->getIncidents(); 
    274        
    275276      // build the XPath query 
    276277      $query = 'descendant::' . $this->ns . 'textarea[@name] | descendant::' . $this->ns . 'select[@name] | descendant::' . $this->ns . 'input[@name and (not(@type) or @type="text" or (@type="checkbox" and not(contains(@name, "[]"))) or (@type="checkbox" and contains(@name, "[]") and @value) or @type="radio" or @type="password" or @type="file"'; 
     
    473474 
    474475      // now output the remaining incidents 
    475       if(!$this->insertErrorMessages($form, $errorMessageRules, $allIncidents)) { 
    476         $rq->setAttribute('lolz', $allIncidents, 'org.agavi.filter.FormPopulationFilter'); 
    477       } 
    478     } 
     476      if($this->insertErrorMessages($form, $errorMessageRules, $allIncidents)) { 
     477        $allIncidents = array(); 
     478      } 
     479    } 
     480     
     481    $rq->setAttribute('orphaned_errors', $allIncidents, 'org.agavi.filter.FormPopulationFilter'); 
     482     
    479483    if($xhtml) { 
    480484      $fiveTwo = version_compare(PHP_VERSION, '5.2', 'ge'); 
     
    579583  protected function insertErrorMessages(DOMElement $element, array $rules, array $incidents) 
    580584  { 
     585    if(!count($incidents)) { 
     586      // nothing to do here 
     587      return true; 
     588    } 
     589     
    581590    $errorMessages = array(); 
    582591    foreach($incidents as $incident) {