I am using symfony 1.4.
I have a form like this:
validator:
$this->setValidator('name', new sfValidatorString(array('required' => true)));
view:
<?php echo $form['name']->renderError() ?>
How do i change the default "required" error message to, for example, "This field is required" ?
Edit: Also, how do i get rid of <ul> and <li> tags generated by the renderError(). method ? I just want the text to be displayed, no additional markup.
Note: This is an obvious question, but since I took a long time to find out, i think the question diserves to be asked here.
1.Change the required message:
new sfValidatorString(
array(
'required' => true,
),
array(
'required'=>'You custom required message'
));
2.Create a new formatter class.
3.Redefine the attribute you want.
<?php
class myWidgetFormSchemaFormatter extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = '',
$helpFormat = '%help%',
$errorRowFormat = '%errors%',
$errorListFormatInARow = " <ul class=\"error_list\">\n%errors% </ul>\n",
$errorRowFormatInARow = " <li>%error%</li>\n",
$namedErrorRowFormatInARow = " <li>%name%: %error%</li>\n",
$decoratorFormat = '',
$widgetSchema = null,
$translationCatalogue = null;
4.In the configure method of your symfony form add
$oDecorator = new myWidgetFormSchemaFormatter($this->getWidgetSchema());
$this->getWidgetSchema()->addFormFormatter('myCustom', $oDecorator);
$this->getWidgetSchema()->setFormFormatterName('myCustom');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With