We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Form Builder values

Hi Guys,

I've started playing with the Form Builder feature and I seem to be missing something very obvious here. How do you set a field value?

Let's say I have a simple class:

    class PageEditForm extends Form
    {                      
        public function initialize()
        {                              
            $this->add(new TextArea("html"));                        
        }
    }

Just like in the form builder example from the documentation, I can then create an object of this class in my controller. But how could I set a value for the field I've created here? Is there a way to do it through the form class? Like:

$form->setValue('html', 'my value');

Or do I need to go explicitly through \Phalcon\Tag?

Phalcon\Tag::setDefaults

Thanks



2.9k

Hi.

value from entity.

class PageEditForm extends Form{
    public $html = 'this is html';
    public function initialize(){
        $this->setEntity($this);
        $this->add(new TextArea("html")); 
    }
}

value from parameter.

class PageEditForm extends Form{
    public function initialize(){
        $this->add(new TextArea("html", array('value'=>'this is html'))); 
    }
}