He Folks,
is it possible to manipulate a form with events?
I want to mark all labels as required, i think this is a very common
task. i tried to do it as central as it could be, therefore im willing
to use the sfEventDispatcher...
here is my approach:
class ProjectConfiguration extends sfProjectConfiguration
{
/**
* setup the symfony system
*/
public function setup()
{
$this->registerEvents();
}
/**
* register all events
*/
protected function registerEvents()
{
$this->dispatcher->connect('form.post_configure',
array('BaseForm', 'markLabelsRequired'));
}
}
<?php
class BaseForm extends sfFormSymfony
{
/**
* marks all labels as required
*/
public static function markLabelsRequired(sfEvent $event)
{
$frm = $event->getSubject();
/* @var sfForm $frm */
foreach($frm->getFormFieldSchema()->getWidget()->getFields() as
$key => $object)
{
$label = $frm->getFormFieldSchema()->offsetGet($key)-
>renderLabelName();
if($frm->getValidatorSchema()->offsetGet($key) && $frm-
>getValidatorSchema()->offsetGet($key)->getOption('required') == true)
{
$frm->getWidgetSchema()->setLabel($key,'<span
class="required">'.$label.'</span>');
}
}
}
}
But, what a wonder a wont work, cause i dont have the form as
reference :( how could it be done in another way? through the
sfForm::configure cascade, it doesnt works as expected (depending on
where to call it), in a deep inheritance system, its nearly
impossible. the event approach is the finest i could think of, but how
can a manipulate the form within an event?
maybe someone could help?
cheerz
robert
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en