title: Magento adding custom error message
body: <p>I want to add custom error message when specific it satisfies specific condition. Below is the code I wrote on controller. The error message is getting displayed when i navigate to some other page,however this is not showing error message in same page.</p>
  
  <p>Ideally it should show error message on the same page and don't want to show error anywhere else. </p>
  
  <pre><code>public function testAction(){
  
        $this-&gt;loadLayout()-&gt;_initLayoutMessages('customer/session'); 
  
        if(!isset($_FILES['docname']['name']) &amp;&amp; $_FILES['docname']['name'] == ''){
          Mage::getSingleton('customer/session')-&gt;addError('Custom error message');
        }
  
        $this-&gt;renderLayout();
  }
  </code></pre>