Modifying Form Elements in Symfony 1.2
As I found in recent development of an app, I needed to change one of Symfony’s form on the fly (more specifically, I needed to change a drop-down, sfWidgetFormSelect). After some looking, there wasn’t much documentation on this that I could find. My final solution was easy enough:
<?php
$form = new SomeFancyForm();
$new_choices = array('Selection 1', 'Selection 2', 'Selection 3');
$widget = $form->getWidget('select_widget_name');
$widget->setOption('choices', $new_choices);
Of course, that can easily be adapted to modify any option on any form – this was just the relevant example.
Relevant Documentation:
(Hey! Reading the real PHP code is useful
)