Setting default value for a form element

Let's say I have this:

$form->add(new Text('number'));

How do I set a default value, e.g 1?



83.4k

The default value is taken from the related entity:

<?php

class Contact 
{
    public function $telephone = '+44 123-456-789';
}

$form = new Form(new Contact());

$form->add(new Text('telephone'));


6.8k

Thanks, that works.

I guess you meant "public $telephone" and not "public function $telephone"

@BlueShark Phalcon first checks 'getTelephone' function, than public property 'telepone' if first doesn't exist. From Phalcon 1.1.0 you can set default value by $formElement->setDefault($value); (without using entity)