Development

Changeset 1387

You must first sign up to be able to contribute.

Changeset 1387

Show
Ignore:
Timestamp:
05/25/06 17:24:49 (3 years ago)
Author:
fabien
Message:

added new skip_fields, check_types and excludes_types parameter to fillin filter (closes #573 - based on a patch from pookey)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/filter/sfFillInFormFilter.class.php

    r1218 r1387  
    4444    } 
    4545 
     46    $skip_fields = $this->getParameter('skip_fields', array()); 
     47 
     48    $exclude_types = $this->getParameter('exclude_types', array('hidden', 'password')); 
     49    $check_types   = $this->getParameter('check_types',   array('text', 'checkbox', 'radio', 'password', 'hidden')); 
     50    $types = array_diff($check_types, $exclude_types); 
     51    $query = 'descendant::input[@name and (not(@type)'; 
     52    foreach ($types as $type) 
     53    { 
     54      $query .= ' or @type="'.$type.'"'; 
     55    } 
     56    $query .= ')] | descendant::textarea[@name] | descendant::select[@name]'; 
     57 
    4658    // find our form 
    4759    $xpath_query = $this->getParameter('name') ? '//form[@name="'.$this->getParameter('name').'"]' : '//form'; 
    4860    if ($form = $xpath->query($xpath_query)->item(0)) 
    4961    { 
    50       foreach($xpath->query('descendant::input[@name and (not(@type) or @type="text" or @type="checkbox" or @type="radio")] | descendant::textarea[@name] | descendant::select[@name]', $form) as $element) 
     62      foreach($xpath->query($query, $form) as $element) 
    5163      { 
     64        // skip fields specified in the 'skip_fields' attribute 
     65        if ($request->hasParameter($element->getAttribute('name')) && in_array($element->getAttribute('name'), $skip_fields)) 
     66        { 
     67          continue; 
     68        } 
     69 
    5270        if ($element->nodeName == 'input') 
    5371        { 
    54           if (!$element->hasAttribute('type') || $element->getAttribute('type') == 'text') 
    55           { 
    56             // text input 
    57             $element->removeAttribute('value'); 
    58             if ($request->hasParameter($element->getAttribute('name'))) 
    59             { 
    60               $element->setAttribute('value', $this->espaceRequestParameter($request, $element->getAttribute('name'))); 
    61             } 
    62           } 
    63           else if ($element->getAttribute('type') == 'checkbox' || $element->getAttribute('type') == 'radio') 
     72          if ($element->getAttribute('type') == 'checkbox' || $element->getAttribute('type') == 'radio') 
    6473          { 
    6574            // checkbox and radio 
     
    6978            { 
    7079              $element->setAttribute('checked', 'checked'); 
     80            } 
     81          } 
     82          else 
     83          { 
     84            // text input 
     85            $element->removeAttribute('value'); 
     86            if ($request->hasParameter($element->getAttribute('name'))) 
     87            { 
     88              $element->setAttribute('value', $this->espaceRequestParameter($request, $element->getAttribute('name'))); 
    7189            } 
    7290          } 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.