Question

I am working with Zend Form, and on the edit i want the values to be like ucfirst(values) ;. I found filters 'filters' => array('StringToUpper') but they work on the hole input. Any idea ? Thanks

Was it helpful?

Solution

No such filter exists but it would be trivial to create your own:

 class My_Filter_StringUCFirst implements Zend_Filter_Interface {
     public function filter($value){
         return ucfirst($value);
     }
 }

OTHER TIPS

Perhaps it's time for a custom filter.

Something like:

class UcFirstFilter implements Zend_Filter_Interface
{
    public function filter($value)
    {
        // perform some transformation upon $value to arrive on $valueFiltered
        $valueFiltered=ucfirst($value);
        return $valueFiltered;
    }
}
$filterChain = new Zend_Filter();
$filterChain->addFilter(new UcFirstFilter());

I found this solution , i've changed my populate function :

public function populate($data) {
 ....

    foreach ($data as $field => $value) {

            if (in_array($field, array("fields you want in ucfirst")) )
                $value=  ucfirst ($value);

            $this->{$field}->setValue($value);
      }

    return $this;
}

Hope this will help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top