Welcome Guest, Not a member yet? Register   Sign In
validation_errors() is not showing erroe message.
#1

[eluser]ToXXXic[/eluser]
Hi,

I am using the CI form tutorial but for some reason the validation_errors() is not echoing anything. I am using PHP 5.3 do you guys think that could be the reason? The validation check works fine it is just that no error is displayed when the fileds are emty.

Controller:

Code:
<?php

class Form extends Controller {
    

    
    function Form(){
    parent::Controller();
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('form_validation');
}
    
    function index()
    {
        //$this->load->helper(array('form', 'url'));
        
        
            
        $this->form_validation->set_rules('username', 'Username', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required');
            
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
}
?>

View file

Code:
<html>
<head>
<title>My Form</title>
</head>
<body>

<?php //echo validation_errors();?>

&lt;?php echo validation_errors('<p>Testing','</p>'); ?&gt;

&lt;?php echo form_open('form'); ?&gt;



<h5>Username</h5>
&lt;input type="text" name="username" value="" size="50" /&gt;

<h5>Password</h5>
&lt;input type="text" name="password" value="" size="50" /&gt;

<h5>Password Confirm</h5>
&lt;input type="text" name="passconf" value="" size="50" /&gt;

<h5>Email Address</h5>
&lt;input type="text" name="email" value="" size="50" /&gt;

<div>&lt;input type="submit" value="Submit" /&gt;&lt;/div>

&lt;/form&gt;

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

success page
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h3>Your form was successfully submitted!</h3>

<p>&lt;?php echo anchor('form', 'Try it again!'); ?&gt;</p>

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

Thanks in advance
#2

[eluser]Bas Vermeulen[/eluser]
Not sure why they are not working, but I can confirm that it's not because of PHP 5.3.
#3

[eluser]ToXXXic[/eluser]
Anyone? come on CodeIgniter you need to sell it to me, if this simple thing is not working how am I gonna trust it with any bigger projects?

T
#4

[eluser]WanWizard[/eluser]
What is not working where? What do you do? What is the outcome?

If I copy/paste the controller and view here, load the page, leave all fields emtpy, and click submit, the form returns with this at the top:
Code:
TestingThe Username field is required.

TestingThe Password field is required.

TestingThe Password Confirmation field is required.

TestingThe Email field is required.

So the code works as advertised (tested on a new CI 1.7.2. install).
#5

[eluser]ToXXXic[/eluser]
[quote author="WanWizard" date="1287069539"]What is not working where? What do you do? What is the outcome?


So the code works as advertised (tested on a new CI 1.7.2. install).[/quote]

I run the code exactly as it is, I manage to get the validation work and everything else but if I leave the boxes empty the error messages are simply not displayed . If I fill them out I can submit the form and it moves to the next page correctly.

Did you try this on PHP5? If yes, what can possibly wrong on my server?
#6

[eluser]WanWizard[/eluser]
My dev environment runs PHP 5.3.3.

In your controller, after loading the form_validation library, can you do a
Code:
var_dump( $this->form_validation->_get_validation_object() );

What is the result?
#7

[eluser]ToXXXic[/eluser]
@WanWizard, okay this is what I did:

Code:
function Form(){
    parent::Controller();
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('form_validation');
    var_dump( $this->form_validation->_get_validation_object());
}

and it displays a blank page.

Thanks for your help mate.

T
#8

[eluser]WanWizard[/eluser]
A blank page? Error reporting enabled? Display errors on in your php.ini? Any errors in the log?
You should have received an error message, since I made a mistake. Very difficult to debug if you have error reporting disabled.

It should have been:
Code:
var_dump( _get_validation_object() );
since it's a function in the form helper, not a part of the form_validation library...
#9

[eluser]ToXXXic[/eluser]
I enabled the error display, and updated the code. It now displays a long array list or something:

Code:
object(CI_Form_validation)#12 (9) { ["CI"]=>  &object;(Form)#9 (12) { ["_ci_scaffolding"]=>  bool(false) ["_ci_scaff_table"]=>  bool(false) ["config"]=>  &object;(CI_Config)#3 (2) { ["config"]=>  &array;(34) { ["base_url"]=>  string(39) "http://projects.lewispr.com/CodeIgniter" ["index_page"]=>  string(9) "index.php" ["uri_protocol"]=>  string(4) "AUTO" ["url_suffix"]=>  string(0) "" ["language"]=>  string(7) "english" ["charset"]=>  string(5) "UTF-8" ["enable_hooks"]=>  bool(false) ["subclass_prefix"]=>  string(3) "MY_" ["permitted_uri_chars"]=>  string(14) "a-z 0-9~%.:_\-" ["enable_query_strings"]=>  bool(false)

it is a full page long. It also displays the form at the end of the page.

Thanks

T
#10

[eluser]WanWizard[/eluser]
Looks ok to me.

After you ran the validation rules, what does
Code:
var_dump( _get_validation_object()->_error_array );
tell you?




Theme © iAndrew 2016 - Forum software by © MyBB