Skip to content

Instantly share code, notes, and snippets.

@kriswallsmith
Created July 18, 2009 07:40
Show Gist options
  • Save kriswallsmith/149463 to your computer and use it in GitHub Desktop.
Save kriswallsmith/149463 to your computer and use it in GitHub Desktop.
<?php
class BaseDoctrineForm extends sfFormDoctrine
{
// ...
protected function getRequiredFields(sfValidatorSchema $validatorSchema = null,
$format = null)
{
if (is_null($validatorSchema))
{
$validatorSchema = $this->validatorSchema;
}
if (is_null($format))
{
$format = $this->widgetSchema->getNameFormat();
}
$fields = array();
foreach ($validatorSchema->getFields() as $name => $validator)
{
$field = sprintf($format, $name);
if ($validator instanceof sfValidatorSchema)
{
// recur
$fields = array_merge(
$fields,
$this->getRequiredFields($validator, $field.'[%s]')
);
}
else if ($validator->getOption('required'))
{
// this field is required
$fields[] = $field;
}
}
return $fields;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment