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

Textarea content

Hi,

I use Phalcon Form class in my forms controllers and i still got a problem to set the content of a textarea. I saw many things about it but nothing works for me. My others fields are fill with an entity and i need the same for textarea, any suggestions ?

Hi alex0910,

Have you tried setting the default content in the controller using:

$this->tag->setDefault("my_textarea", "My default content");

Then in the view, simply refer to the form element by name:

{{ text_area('my_textarea') }}

Hope it helps.

Oups. Look like it's eating my underscores. Using the proper markup, last code line should be:

{{ text_area('my_textarea') }} 


8.2k

Hi dturcott, thanks for your answer :)

Here is the way i use the form component (example with input text) :

$title = $this->add(new Text("title", array( "class" => "form-control" )));

And in volt:

{{ form.render('title') }}

My form class extends Phalcon\Forms\Form and i pass my entity to the form for having default value in fields. It works very well for input text but no way to have it the same way for textarea

Hi alex 0910, I'm not sure I understand you problem. The example above does not set a default value. Are you have the user 'enter' the default values? Otherwise, you can add default values either at the form entity creation: e.g.

    $form->add(new TextArea('comments',  array( 'value' => 'Default', "class" => "form-control" ))); 

or in the view:

    {{ form.render('comments', ['value':'Default']) }} 

What version of Phalcon are you using?



8.2k

I use my entity as parameter in form to use attributes to fill elements, it works very well :

$robot = Robots::findFirst();

$form = new Form($robot);

$form->add(new Text("name"));

$form->add(new Text("year"));

I already tried your solution with "value" key both in controller or view but it doesn't work.

I'm using the v1.3.2

Hummm. Are you sure your Robots model has the parameter you are trying to access with the text area entity?. If so, then it may be an issue with v1.3.2. I'm using v1.3.4 and the following is working right:

$instruments = Instruments::findFirst();

$form = new Form($instruments);

$form->add(new Text("brand"));

$form->add(new TextArea("model"));

$this->view->setVar("form", $form);

with view:

{{ form.render('brand') }}

<br>

{{ form.render('model') }}

Page is generated with 'brand' in a text box and 'model' in a text area. Both are populated with the values of the first Instrument in the database.



8.2k

Yep, i tried with string to be sure! Maybe i have to update my version, i guess it can be the good solution as i tried everything and same as you! I'll do that and give you a return!