Welcome Guest, Not a member yet? Register   Sign In
validation_errors() returning an empty string after upgrading to 2.1.0
#5

[eluser]ToddyBoy[/eluser]
I was hoping this would solve my problem as well, but it didn't.

I'm getting the validation errors appearing in my view before the validation is being called.

Here's my controller:
Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

if ( ! class_exists('Controller'))
{
class Controller extends CI_Controller {}
}

class Entrar extends Controller {

function __construct()
{
  parent::__construct();
  $this->load->library('file_upload');
  $this->load->library('session');
  $this->load->helper(array('form', 'url'));
  $this->load->library('form_validation');
}

public function test()
{
  // Validate form input
  $this->form_validation->set_rules('username', 'Username', 'trim|required');
  $this->form_validation->set_rules('password', 'Password', 'trim|required');

  if ($this->form_validation->run() == true){
   // If the validation is successful
   $this->session->set_flashdata('message', 'Validation successful');
   redirect('entrar', 'refresh');
  } else {
   // Display the form
   // Set the flash data error message if there is one
   $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

   $this->data['username'] = array('name' => 'username',
    'id' => 'username',
    'type' => 'text',
    'value' => $this->form_validation->set_value('username'),
   );
   $this->data['password'] = array('name' => 'password',
    'id' => 'password',
    'type' => 'password',
   );

   $this->load->view('media/test', $this->data);
  }

}

Here's my view:
Code:
<!DOCTYPE HTML>
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;

&lt;title&gt;&lt;/title>

&lt;meta name="Description" content="" /&gt;
&lt;meta name="Keywords" content="" /&gt;

&lt;/head&gt;

&lt;body&gt;
  
&lt;?php if ($message) { if($message == "<p>Validation successful</p>"){ ?&gt;
<div id="success">&lt;?php echo $message;?&gt;</div>
&lt;?php } else { ?&gt;
<div id="error">&lt;?php echo $message;?&gt;</div>
&lt;?php } } ?&gt;
   &lt;?php echo form_open("entrar");?&gt;
    <fieldset>
     <label for="username">Username</label>
     &lt;?php echo form_input($username);?&gt;
     <br>
     <label for="password">Password</label>
     &lt;?php echo form_input($password);?&gt;
     <br>
     <label for="remember">Remember Me</label>
     &lt;?php echo form_checkbox('remember', '1', FALSE, 'id="remember"');?&gt;
     <br>
     &lt;?php echo form_submit('submit', 'Login', 'id="submit"');?&gt;
    </fieldset>
   &lt;?php echo form_close();?&gt;

&lt;/body&gt;
&lt;/html&gt;

Here's the rendered html when the page loads with the error messages appearing:
Code:
<!DOCTYPE HTML>
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;

&lt;title&gt;&lt;/title>

&lt;meta name="Description" content="" /&gt;
&lt;meta name="Keywords" content="" /&gt;

&lt;/head&gt;

&lt;body&gt;
  
<div id="error"><p>The Username field is required.</p>
<p>The Password field is required.</p>
</div>
   &lt;form action="https://mysite.com/entrar" method="post" accept-charset="utf-8"&gt;    <fieldset>
     <label for="username">Username</label>
     &lt;input type="text" name="username" value="" id="username"  /&gt;     <br>
     <label for="password">Password</label>
     &lt;input type="password" name="password" value="" id="password"  /&gt;     <br>
     <label for="remember">Remember Me</label>
     &lt;input type="checkbox" name="remember" value="1" id="remember" /&gt;     <br>
     &lt;input type="submit" name="submit" value="Login" id="submit" /&gt;    </fieldset>
   &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

I've used this code on another installation and it works fine. The other installation I KNOW is 2.1.0. This current installation I THINK is 2.0.2.

I downloaded a 2.1.0 installation from github and copied the form_validation helper from 2.1.0 into the not working version and I didn't get anything rendered at all. So I backed out that change and am back to square one.

When I actually go through the form and enter a username, for example, and click submit, I only get the error for the password being required. Entering data into both fields, I get the successful validation message.


Messages In This Thread
validation_errors() returning an empty string after upgrading to 2.1.0 - by El Forum - 02-22-2012, 10:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB