Hi,

I hope i am understanding you right but if you take a look at
Zend/Form/Element.php

You will find this:

 /**
     * Set element attribute
     *
     * @param  string $name
     * @param  mixed $value
     * @return Zend_Form_Element
     * @throws Zend_Form_Exception for invalid $name values
     */
    public function setAttrib($name, $value)
    {
        $name = (string) $name;
        if ('_' == $name[0]) {
            require_once 'Zend/Form/Exception.php';
            throw new Zend_Form_Exception(sprintf('Invalid attribute "%s";
must not contain a leading underscore', $name));
        }

        if (null === $value) {
            unset($this->$name);
        } else {
            $this->$name = $value;
        }

        return $this;
    }

so as you can see you cannot set a null value. But what you can do is set it
to an empty string maybe if that's something that you can work with.

On Fri, May 29, 2009 at 12:00 PM, samuel verdier
<[email protected]>wrote:

>
> $last_name->setValue('testsamy'); no set the value if the form after
> submitting, $last_name = $_POST['last_name'] ($_POST['last_name'] no exist
> because last_name is disable) and no testsamy. I want to force this value
> because element is disable and when there are errors on the form the
> element
> last_name has a null value.
>
>
> vince. wrote:
> >
> > Hi,
> >
> > I did not understand where you place the null value in the code above,
> But
> > if you do this:
> >
> >  $last_name->setAttrib('disable', null);
> >
> > this will unset the 'disable' element from the form. It doesn't accept
> > null
> > values.
> >
> > On Fri, May 29, 2009 at 1:07 AM, samuel verdier
> > <[email protected]>wrote:
> >
> >>
> >> hello,
> >>
> >> I want to set a value to an element after submitting the form.
> >> I need it because one element is disable and when there are errors on
> the
> >> form the element has a null value.
> >>
> >> this code doesn't works, value = null :
> >>
> >> class App_Form extends Zend_Form
> >> {
> >>        public function init()
> >>        {
> >>            $last_name = $this->createElement('text', 'last_name')
> >>            $last_name->setAttrib('disable', true);
> >>            $last_name->setValue('testsamy');
> >>
> >>            .............
> >>
> >>            return $this;
> >>        }
> >> }
> >>
> >> this code works, value = test:
> >>
> >> class App_Form extends Zend_Form
> >> {
> >>        public function init()
> >>        {
> >>            $last_name = $this->createElement('text', 'last_name')
> >>            $last_name->setAttrib('disable', true);
> >>            $last_name->setValue('testsamy');
> >>
> >>            .............
> >>
> >>            return $this;
> >>        }
> >>
> >>        public function isValid($data)
> >>        {
> >>            $valid = parent::isValid($data);
> >>
> >>            $this->getElement('last_name')->setValue('test');
> >>
> >>            return $valid;
> >>        }
> >> }
> >>
> >> How can i do without overloading the method isValid ?
> >>
> >> Thanks
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Zend_Form-setValue-tp23770977p23770977.html
> >> Sent from the Zend Framework mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Vincent Gabriel.
> > Lead Developer, Senior Support.
> > Zend Certified Engineer.
> > Zend Framework Certified Engineer.
> > -- http://www.vadimg.co.il/
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Zend_Form-setValue-tp23770977p23776593.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>


-- 
Vincent Gabriel.
Lead Developer, Senior Support.
Zend Certified Engineer.
Zend Framework Certified Engineer.
-- http://www.vadimg.co.il/

Reply via email to