Skip to content

Instantly share code, notes, and snippets.

@bshaffer
Created May 20, 2010 22:36
Show Gist options
  • Save bshaffer/408209 to your computer and use it in GitHub Desktop.
Save bshaffer/408209 to your computer and use it in GitHub Desktop.
handy makeReadOnly() function to put in BaseForm
<?php
class BaseForm extends sfFormSymfony
{
public function makeReadOnly($field = null)
{
if ($field instanceof sfWidget)
{
$field->setAttribute('disabled', 'disabled');
if ($field instanceof sfWidgetFormSchemaDecorator)
{
foreach ($field->getFields() as $key => $childWidget)
{
$this->makeReadOnly($childWidget);
}
}
}
else
{
if ($field === null)
{
$field = array_keys($this->widgetSchema->getFields());
}
foreach ((array) $field as $name)
{
$this->makeReadOnly($this->widgetSchema[$name]);
unset($this->validatorSchema[$name]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment