7

I am using Symfony 1.3.2 on Ubuntu 9.10

I want to set the default value of a textarea widget, with data read froma adb.

My code snippet in the template looks likes this:

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

The API docs dont show how to do this - does anyone know how to do this?

morpheous
  • 16,270
  • 32
  • 89
  • 120
  • Did you look at this? http://forum.symfony-project.org/index.php/m/64073/#msg_64073 – Christopher Altman May 02 '10 at 18:48
  • Yes, I saw that post. I ignored it because it is a hack... I will have to manually reimplement all of my widgets and validators if I inherit from sfForm instead of the base object, which becomes a maintenance nightmare if the underlying model properties changes. – morpheous May 03 '10 at 08:19

1 Answers1

11

You can use this in your action or the 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've got multiple fields:

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

Or if you prefer declaring it just once with the widget in your form class configuration (I think this is right):

$this->setWidgets(array(
  // widgets
  'notes' => new sfWidgetFormTextArea(array('default' => $text)),
  // widgets
));
Tom
  • 30,090
  • 27
  • 90
  • 124