Welcome Guest, Not a member yet? Register   Sign In
Validation variables missing
#1

[eluser]Wohlstand Applications[/eluser]
I am using CI validation class in my app. It works on my development server (XAMPP PHP5) but when I put it on my host server (PHP4) the variables for fields set do not get passed through. The page loads, and I get a warning variable not initialized variable.

In my controller I have:
Code:
//set validation fields
$fields['username'] = 'Username';
$this->validation->set_fields($fields);
        
//load view
$data['page_title'] = "User Login";
$data['page'] = "users/login.php";
$this->load->view('template/template_no_nav.php',$data);

And in the view (no method used) I have:
Code:
<input name="username" id="username" type="text" value="<?php echo $this->validation->username; ?>" />

The resulting page is this, and I've added var_dump($this->validation) to it: http://smartgoals.net/index.php/users

The first line of the var_dump seems to tell the whole story:

ON DEV SERVER: object(CI_Validation)#14 (14) {
ON HOST SERVER: object(ci_validation)(10) {

The var_dump is so long its hard to find what is missing, I believe it is the "output" array or something of that sort.

I tend to think the problem is with PHP INI settings on the server? Any ideas?
#2

[eluser]tonanbarbarian[/eluser]
rather than doing a vardump, which will be very long and confusing because of the back reference to the controller do the following code instead

Code:
$properties = get_object_vars($this->validation);
foreach ($properties as $property=>$value) {
  echo $property.'=>';
  if (is_object($property)) {
    echo 'object';
  } else {
    echo '<pre>'.print_r($value, true).'</pre>';
  }
  echo '<br />';
}

This will display all of the properties of the validation class (or any other with modification) and it will ignore any objects that exist in the class, thereby reducing the output because it will not show the controller which has a lot of stuff in it if dumped

Hmmm In fact I think I might make a helper or plugin for this that I can use when debugging
#3

[eluser]Wohlstand Applications[/eluser]
Thanks. I have updated the page using your code and its a lot simple to read now. Now I will try to compare to the working development server output and see what is missing.
#4

[eluser]Wohlstand Applications[/eluser]
Anyone have ideas on what server configs might cause CI to have problems?
#5

[eluser]Wohlstand Applications[/eluser]
The property "_fields" is empty on the Live server while it reads as below on the Dev server:

Code:
_fields=>

Array
(
    [username] => Username
)


Here is a link to phpinfo for my live server: http://smartgoals.net/phpinfo.php
#6

[eluser]Wohlstand Applications[/eluser]
I have not been able to find a solution to this *yet*. For anyone with similar issues, two work around options are either to use isset() to test for the variable in the View page, or to reduce the error reporting level. I've chosen to use the isset() method for now.

Anyone with insight into why this may occur, please let me know!
#7

[eluser]t'mo[/eluser]
I noticed a similar problem with the Validation's error messages. When I do:

Code:
print_r($this->validation);

from within the Controller class, all the error messages are present. However, when I attempt to do the same thing from within the View, the messages are an empy Array.

I actually need the error messages to show up in the view, so the suggested workaround to check for "isset(...)" won't be very useful.

Update This (http://ellislab.com/forums/viewthread/67539/) looks like the same issue...

Update 2

Works: load Validation class in the Controller method(s) where required, *do not* load
Validation class in either the constructor or autoload.php

Code:
class MyClass extends Controller
{
  function do_stuff()
  {
    $this->load->library('validation');
    // ...setup rules, etc.

    if ($this->validation->run() == FALSE) {
      $this->load->view('view_name'); // view echo's $this->validation->error_string
    }
  }
}

Doesn't work (2 examples):

#1: load Validation class in Controller constructor

Code:
class MyClass extends Controller
{
  function MyClass()
  {
    parent::Controller();
    $this->load->library('validation');
  }

  function do_stuff()
  {
    // ...setup validation rules, etc.; note *absence* of this->load->library('validation')

    if ($this->validation->run() == FALSE) {
      $this->load->view('view_name'); // this->validation->error_string in view will be empty
    }
  }
}

#2: autoload Validation

Code:
// in autoload.php...
$autoload['libraries'] = array('database', 'validation');

And a few further details: running CodeIgniter 1.5.4, Apache 1.3.31 and...
Code:
$ php -v
PHP 4.3.7 (cli) (built: Jun  5 2004 00:11:51)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
#8

[eluser]t'mo[/eluser]
See updates in my previous post (...new post, just so it floats to the top of the list...)
#9

[eluser]scott9s[/eluser]
I Had the same issue. CodeIgniter worked great on my PHP5 dev box, but when I go to deploy, I get all sorts of errors. I come to find out my production box is PHP4.

After a few hours or wringing CodeIgniter's neck, I found this post.

This worked for me:

====
*do not* load Validation class in either the constructor or autoload.php
====

In fact, I was not able to load the database class either in autoload either for PHP4, but I was not too worried about that.

I had to adjust a few items in code regarding string manipulation, but that was my code specific. Thanks for your post.
#10

[eluser]Wohlstand Applications[/eluser]
Absolutely fantastic! Thank you so much! That solved the problem instantly!




Theme © iAndrew 2016 - Forum software by © MyBB