Error message is displayed for a validated field before form submission in view Page

Permalink
Hi all,

Here's the thing... I've been toying around with the idea of building applications with C5 and I exploring the use the built in validation mechanism using Single Pages and the corresponding Controllers.

My problem is very simple.... on the first visit to the landing page of the application, an error message is displayed for a validated field even without even submitting the form...

Here's a link to the page in question:

http://demos.cleverpixels.net/c5labs/index.php/webapp/form...

What am I missing out?

I have the following package structure set up
C5_Root/
-------/packages/
----------------/webapp/
-----------------------/controllers/
-----------------------------------/webapp
------------------------------------------/confirm.php
------------------------------------------/form.php
-----------------------/single_pages
------------------------------------/webapp/
-------------------------------------------/confirm.php
-------------------------------------------/form.php

I have the following code in the view method of the controller:

public function view() {
     $paymentOptions = array ("WEEKEND"=>'Weekend',"WEEKDAY"=>'Week Day');
     if ($this->validate() && !$this->DEBUG){
   $this->redirect('/webapp/', 'confirm');
     }
     $this->set('paymentOptions', $paymentOptions);
}
...
...


The validate method is as follows:

protected function validate() {
    $vt = Loader::helper('validation/strings');
    if (!$vt->notempty($this->post('firstName'))) {
        $this->error->add(t('First name is required.'));
    }
    if(!$this->error->has()){
      return TRUE;
    }else{
      return FALSE;
    }
}


I make the error object available to the view in the on_before_render() method as follows:

$this->set('error', $this->error);



Finally, the error message is rendered on the view page (form.php) as follows:
<?php if(!empty($errors)): ?>
   <div style="background: yellow; min-height:25px;">
   <?php echo $error->output()   ?>
   </div>
<?php endif; ?>