Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gestadieu/301458 to your computer and use it in GitHub Desktop.
Save gestadieu/301458 to your computer and use it in GitHub Desktop.
<?php
class sfWidgetFormSchemaFormatterDef extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = '<div class="row %row_class%">%label%%field%%help%%hidden_fields%</div>',
$helpFormat = '<span>%help%</span>',
$errorRowFormat = '%errors%',
$errorListFormatInARow = '<ul>%errors%</ul>',
$errorRowFormatInARow = '<li>%error%</li>',
$namedErrorRowFormatInARow = '<li>%name%: %error%</li>',
$decoratorFormat = '';
/**
* Takes the default rendered row and adds error class if it contains errors. Also it adds the type
* of the input as class like radio checkbox text password or textarea if it is a textarea.
*
* @see sfWidgetFormSchemaFormatter::formatRow([....])
*/
public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null)
{
$row = parent::formatRow($label, $field, $errors, $help, $hiddenFields);
if (!preg_match('/type="([a-z]+)"/', $row, $matches)) {
$matches[1] = 'textarea';
}
return strtr($row, array(
'%row_class%' => count($errors) ? 'error ' . $matches[1] : $matches[1],
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment