Symfony Forms: How to Set a Default Value for a Textarea Widget

I am using Symfony 1.3.2 on Ubuntu 9.10

I want to set a default value for a textarea widget, with data read from adb.

My code snippet in the template looks like this:

<?php $form['notes']->render(); ?> 

API docs don't show how to do this - does anyone know how to do this?

+7
html forms symfony1 textarea
source share
1 answer

You can use this in your action or in a form class:

 $this->form = new yourForm(); // If its in your action $text = // data for prepopulating field, from db or anywhere $this->form->setDefault('notes', $text); 

... or if you have several fields:

 $this->form->setDefaults(array('notes' => $text, 'more_notes' => $more_text)); 

Or, if you prefer to declare it only once with a widget in your form class configuration (I think this is correct):

 $this->setWidgets(array( // widgets 'notes' => new sfWidgetFormTextArea(array('default' => $text)), // widgets )); 
+10
source share

All Articles