Widget error positioning tip
Ever wondered how to put your error message on your form inputs below the widget instead of the default, which is above?
Simply create a new form_widget.tpl template and change the default from
<?php echo $this->generateWithError(); ?>
to:
<?php echo $this->generateWithError(true); ?>
The "true" tells it to switch positions with the widget/input. I usually do this because it makes the errors easier to style with CSS in most occasions without having them break my layout.
Re: Widget error positioning tip
Useful tip, Blair! Thanks
Re: Widget error positioning tip
Re: Widget error positioning tip
Had I known this before ... :roll:
Re: Widget error positioning tip
It makes me wonder if something is fundamentally wrong with the default html output of error messages?
Trying to style error messages has been driving me crazy for ages - but I put it down to my mimimal knowledge of CSS.
Would it be worth asking Leo to make generateWithError(true); the default do you think????
(although I do suspect a change would throw a lot of existing site out).
What say you all on the subject
Re: Widget error positioning tip
I think the default output is probably fine for a basic user, and there are plenty of functions available for advanced users to customize the output. It really comes down to having documentation (at least in English).
For example, you can customize the output even more by using this. Say you wanted the error to come before both the label and widget and you wanted it in a DIV and not a P tag:
Code:
//Error as string if there are errors
<?php if($this->hasErrors()): ?>
<div class="error"><?php echo $this->getErrorAsString(); ?></div>
<?php endif; ?>
//Label
<?php echo $this->generateLabel(); ?>
//Widget only without error
<?php echo $this->generate(); ?>
It's pretty customizable. The generateWithError(true) is just a quick option but theoretically you can render the output however you want by just looking at some of the functions available in the Widget Library.