Results 1 to 6 of 6

Thread: Widget error positioning tip

  1. #1
    User winanscreative's Avatar
    Join Date
    06-21-09.
    Location
    Massachusetts, United States
    Posts
    261

    Default 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.

  2. #2
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Re: Widget error positioning tip

    Useful tip, Blair! Thanks

  3. #3
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Widget error positioning tip

    Good on you Blair

  4. #4

    Default Re: Widget error positioning tip

    Had I known this before ... :roll:
    OM MANI PEME HUNG! how many has to die for freedom and dignity. Save this world

  5. #5
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default 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

  6. #6
    User winanscreative's Avatar
    Join Date
    06-21-09.
    Location
    Massachusetts, United States
    Posts
    261

    Default 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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •