Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save calvin/3922130 to your computer and use it in GitHub Desktop.
Save calvin/3922130 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 = '%content%';
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' : '',
));
}
}
@calvin
Copy link
Author

calvin commented Oct 20, 2012

Show embedded forms.

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