Skip to content

Instantly share code, notes, and snippets.

@malteo
Created November 11, 2011 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save malteo/1357580 to your computer and use it in GitHub Desktop.
Save malteo/1357580 to your computer and use it in GitHub Desktop.
Symfony form formatter to use with Twitter Bootstrap CSS
<?php
/**
* A FormSchemaFormatter to use with Twitter Bootstrap CSS.
*
* @author malteo
*/
class sfWidgetFormSchemaFormatterBootstrap extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = "<div class=\"clearfix%row_class%\">\n %label%\n <div class=\"input\">\n %field%\n %error%\n %help%\n %hidden_fields%\n </div>\n</div>\n",
$errorRowFormat = '%errors%',
$errorListFormatInARow = "<span class=\"help-inline\">%errors%</span>\n",
$errorRowFormatInARow = "%error% ",
$namedErrorRowFormatInARow = "%name%: %error% ",
$helpFormat = '<span class="help-block">%help%</span>',
$decoratorFormat = '';
public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null)
{
$row = parent::formatRow(
$label,
$field,
$errors,
$help,
$hiddenFields
);
return strtr($row, array(
'%row_class%' => (count($errors) > 0) ? ' error' : '',
));
}
}
@tdb85
Copy link

tdb85 commented Nov 22, 2011

Fantastic, thanks!
My solution was far less elegant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment