Welcome Guest, Not a member yet? Register   Sign In
Explanation about errors, please?

Tried to find an answer in the user guide and forums ... No success!

My problem is with the errors/messages which are displayed after a form submission. And in all the examples / tutorials I can find only one solution.

There is always a div, for example:
<div id="message">&lt;?php echo $message; ?&gt;</div>

So far, so good. But I want to style this div with CSS, adding some beauty in it Smile
And the problem is... It is hardcoded in the template (the view file I mean). So if there is no style, then yes. The div is not visible, until it is populated with some text from the message. But when I add some style, then it is always visible.

Maybe my explanation was not good enough. But I am looking for a way, not only to display the error/message as a text. I need a whole div, which is showing after there is a post (form submit). This div to appear then, with the design and styles. And then maybe I will hide it with some jQuery stuff Smile

Any ideas, or links to such kind of approach? I mean examples, or tutorials ...

Thanks in advance!

I assume you are trying to display messages/errors to the user only when such are set. I have approached it in my application in the following way.
In my helper functions, I have created a function set_msg() that adds any messages to $this->data['messages'] multidimensional array. In my views or controllers (or models) all I have to do is set_msg('Example of text to display','message type'). For example, when I call set_msg('Invalid Login','error') I will get this->data['messages']['errors'][0] => 'Invalid Login'. Then, in my header, where I want to display the messages:

foreach($messages as $type=>$messages){
  echo "<div class='".$type."'>";
   foreach($messages as $key=>$message)
    echo '<p>'.$message.'</p>';
  echo "</div>";

This will allow you to have each type of message group in their own div with separate CSS styling.

Thanks, @Ki! I am looking for something like this, correct. I don't want this div to stay always in my header. I need it only after submitting a form. Then the div can display error or info message. Can you give me some hint about the helper, connected with this?

Theme © iAndrew 2016 - Forum software by © MyBB