CodeIgniter Forums
No validation errors is shown online! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: No validation errors is shown online! (/thread-3189.html)



No validation errors is shown online! - El Forum - 09-14-2007

[eluser]kruse[/eluser]
Hello,

This is a function to create a new user. It works perfectly fine offline on PHP5
but online on my server PHP4 it does not display validation errors on the form!

What can be wrong? I searched for hours : ) Please check the code.

Code:
function do_signup()
    
    {
        
        ///////////////////////////////////////////////////////////
        //
        //  Get the language from the settings
        //
        ///////////////////////////////////////////////////////////

        $language = $this->config->item('site_language');
        
        ///////////////////////////////////////////////////////////
        //
        //  Load the language files
        //
        ///////////////////////////////////////////////////////////

        $this->lang->load('signup', $language);
        
        ///////////////////////////////////////////////////////////
        //
        //  Load the validation library
        //
        ///////////////////////////////////////////////////////////

        $this->load->library('validation');

        ///////////////////////////////////////////////////////////
        //
        //  Validate the input
        //
        ///////////////////////////////////////////////////////////
        
        $rules['forname']        = "required|min_length[2]";
        $rules['lastname']        = "required|min_length[2]";
        $rules['email']            = "required|valid_email";
        $rules['username']        = "required|callback_username_check";
        $rules['password']        = "required|min_length[5]";
    
        $this->validation->set_rules($rules);

        ///////////////////////////////////////////////////////////
        //
        //  Set the validation items
        //
        ///////////////////////////////////////////////////////////

        $fields['forname']            = $this->lang->line('signup_forname');
        $fields['lastname']            = $this->lang->line('signup_lastname');
        $fields['email']            = $this->lang->line('signup_email');
        $fields['username']            = $this->lang->line('signup_username');
        $fields['password']            = $this->lang->line('signup_password');
        
        $this->validation->set_fields($fields);
        $this->validation->set_error_delimiters('<div class="field_error">', '</div>');

        ///////////////////////////////////////////////////////////
        //
        //  Process the incoming fields
        //
        ///////////////////////////////////////////////////////////

        if ($this->validation->run() == FALSE)

        {

        ///////////////////////////////////////////////////////////
        //
        //  Get the language from the settings
        //
        ///////////////////////////////////////////////////////////

        $language = $this->config->item('site_language');
        
        ///////////////////////////////////////////////////////////
        //
        //  Load the language file
        //
        ///////////////////////////////////////////////////////////

        $this->lang->load('navigation', $language);      
        $this->lang->load('signup', $language);
        
        ///////////////////////////////////////////////////////////
        //
        //  Display the errors
        //
        ///////////////////////////////////////////////////////////
    
        $this->load->view('signup');

        } else {

        ///////////////////////////////////////////////////////////
        //
        //  Put the incoming date in variables
        //
        ///////////////////////////////////////////////////////////

        $pass = $_POST['password'];
        $pass = dohash($pass,'md5');
            
        $data = array(
                           'forname'             => $_POST['forname'] ,
                           'lastname'             => $_POST['lastname'] ,
                           'email'             => $_POST['email'] ,
                           'username'             => $_POST['username'] ,
                           'password'             => $pass ,
                           'points'             => 0 ,
                           'status'             => 1
                );

    
        ///////////////////////////////////////////////////////////
        //
        //  Save the new post
        //
        ///////////////////////////////////////////////////////////
    
        $this->db->insert('profiles', $data);

        ///////////////////////////////////////////////////////////
        //
        //  Redirect to previous page
        //
        ///////////////////////////////////////////////////////////
        
        
        redirect('login/form');
        


        }

    
    }



No validation errors is shown online! - El Forum - 09-14-2007

[eluser]kruse[/eluser]
The View:

Code:
&lt;?php $this->load->view('inc_header'); ?&gt;

&lt;body&gt;

<div id="wrapper">

<div id="navigation_container">
<table cellpadding="0" cellspacing="0" id="navigation">
<tr>
<td>

&lt;?php $this->load->view('inc_navigation'); ?&gt;

</td>
</tr>
</table>
</div>

<div id="container">

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

<div id="content_white">

{{info_main}}

</div>

<div id="content_pen">

<div class="input_container">
<div class="label">{{signup_forname}}</div>
<div class="input">&lt;input type="text" class="textbox" name="forname" value="&lt;?php if (isset($this-&gt;validation->forname)){ echo $this->validation->forname; } ?&gt;" /></div>
&lt;?php if (isset($this->validation->forname_error)){ echo $this->validation->forname_error; } ?&gt;
</div>

<div class="input_container">
<div class="label">{{signup_lastname}}</div>
<div class="input">&lt;input type="text" class="textbox" name="lastname"  value="&lt;?php if (isset($this-&gt;validation->lastname)){ echo $this->validation->lastname; } ?&gt;" /></div>
&lt;?php if (isset($this->validation->lastname_error)){ echo $this->validation->lastname_error; } ?&gt;
</div>

<div class="input_container">
<div class="label">{{signup_email}}</div>
<div class="input">&lt;input type="text" class="textbox" name="email" value="&lt;?php if (isset($this-&gt;validation->email)){ echo $this->validation->email; } ?&gt;" /></div>
&lt;?php if (isset($this->validation->email_error)){ echo $this->validation->email_error; } ?&gt;
</div>

<div class="input_container">
<div class="label">{{signup_username}}</div>
<div class="input">&lt;input type="text" class="textbox" name="username" value="&lt;?php if (isset($this-&gt;validation->username)){ echo $this->validation->username; } ?&gt;" /></div>
&lt;?php if (isset($this->validation->username_error)){ echo $this->validation->username_error; } ?&gt;
</div>

<div class="input_container">
<div class="label">{{signup_password}}</div>
<div class="input">&lt;input type="password" class="textbox" name="password" value="&lt;?php if (isset($this-&gt;validation->password)){ echo $this->validation->password; } ?&gt;" /></div>
&lt;?php if (isset($this->validation->password_error)){ echo $this->validation->password_error; } ?&gt;
</div>

<div class="input_container">
<div class="label"> </div>
<div class="input">&lt;input type="submit" class="submit" value="{{signup_submit}}"&gt;</div>
</div>


<div class="clear"></div>

</div>

&lt;?php $this->load->view('inc_footer'); ?&gt;

</div>

&lt;/form&gt;

</div>


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



No validation errors is shown online! - El Forum - 09-15-2007

[eluser]alpar[/eluser]
I don't think that this is the problem, just a tip, you don't need to check to see if the field values are checked, you can simply use echo $this->validation->fieldname,after you call the run() method, they get set with an empty string, it will make your views a bit cleaner


No validation errors is shown online! - El Forum - 09-15-2007

[eluser]kruse[/eluser]
Yeah, I tried it the "cleaner" way but the resulted in errors about empty strings or something so I had to do it this way : )


No validation errors is shown online! - El Forum - 09-15-2007

[eluser]alpar[/eluser]
I experienced that when it gives errors, there is a typo somewhere or you didn't set a field/rule for it. So that could be a potential problem