Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony Form: Set default/value on error?
    primarykey
    data
    text
    <p>My crazy designer would like the message "Required" displaying (in red) inside a field if the form has been submitted and it is invalid because of an empty field.</p> <p>The form in question is a login prompt and I'm using a custom class that extends sfGuardFormSignin</p> <p>I've managed to set the value and add a class with..</p> <pre><code>$this->widgetSchema['username']->setAttribute('class','red'); $this->widgetSchema['username']->setDefault('Required');</code></pre> <p>..but how do I do this only when the username field is invalid and because of the Required error?</p> <p>I assume it's the same for the password field?</p> <p>Many thanks in advance</p> <p><strong>EDIT:</strong></p> <p>Thanks for the advice greg0ire. I've had a play with that but the formatRow method of sfWidgetFormSchemaFormatter doesn't seem to be getting hit. Is this because my form extends sfGuardFormSignin and using the sfGuardAuth plugin?</p> <pre><code>class FrontendsfGuardFormSignin extends sfGuardFormSignin { public function configure() { parent::configure(); // This works! $this->widgetSchema['username']->setLabel('Email'); // I copied this from the link you pasted $decorator = new myWidgetFormSchemaFormatterCustom($this->getWidgetSchema()); $this->widgetSchema->addFormFormatter('custom', $decorator); $this->widgetSchema->setFormFormatterName('custom'); } }</code></pre> <p>/lib/widget/myWidgetFormSchemaFormatterCustom.class.php</p> <pre><code>class myWidgetFormSchemaFormatterCustom extends sfWidgetFormSchemaFormatter { public function __construct(sfWidgetFormSchema $widgetSchema) { parent::__construct($widgetSchema); } public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null) { // Nothing happens!? var_dump($errors); die(); parent::formatRow($label, $field, $errors, $help, $hiddenFields); } }</code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload