I want to change the background color of my field when an error occurs.
In Java Struts, I can do something like this:
<s:textfield name="parameter" cssClass="normal_css_class" cssErrorClass="class_on_error" cssErrorStyle="style_on error"/>
I want to be able to perform something like above. The tag renders the field cssErrorClass when the field parameter has errors. No more additional Javascript is required.
Currently I have the following (very dirty) code in my template:
<?php if($form['bill_to']->hasError()): ?>
<?php echo $form['bill_to']->render(array('style' => 'background-color: red')) ?>
<?php else: ?>
<?php echo $form['bill_to']->render() ?>
<?php endif; ?>
<?php echo $form['bill_to']->renderError() ?>
The above code works but is there a way to implement it so that I just have to call:
<?php echo $form['bill_to']->render() ?>
and it will then perform the setting of the styles? I'm thinking of overriding the render() method but I am not sure if it is the right approach.