CodeIgniter Forums

Full Version: CodeIgniter appears to have a BUG.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is the coding in the Controller;

PHP Code:
public function index()
{
    
$error 0;
    
$realname "";
    
$username "";
    
$word "";

    
$this->load->helper(array('form''url','file'));
    
$this->load->library('form_validation');

    
$config = array(
    array(
'field' => 'rname''label' => 'RealName''rules' => 'required''errors' => array( 'required' => 'Provide%s')),
    array(
'field' => 'uname''label' => 'Username''rules' => 'required''errors' => array( 'required' => 'Provide%s')),
    array(
'field' => 'word''label' => 'Word''rules' => 'required''errors' => array( 'required' => 'Provide%s')));

        
$this->form_validation->set_rules($config);
        if (
$this->form_validation->run() == FALSE)

            {
            
$this->load->view('names');
            }

        
$realname $this->input->post('rname');
        
$username $this->input->post('uname');
        
$word $this->input->post('word');

        if(!
file_exists("C:xampp/htdocs/file1/$realname")) exit ("$realname DoesNotExist");
        if(!
file_exists("C:xampp/htdocs/file2/$realname/$username")) exit ("$username DoesNotExist");
        if(!
file_exists("C:xampp/htdocs/file3/$realname/$word")) exit ("$word DoesNotExist");

        if(isset(
$_POST['submit'])) redirect(BASE_URL.'home');


If I comment out by //if(isset.. the form validation works OK but I need the "isset" for the other coding to work.

There are two functions in the coding above, one ensures the text boxes are filled in and not left empty (form validation), and the other ensures the text boxes are filled in correctly (if !file_exits). Both functions work good individually but they wont work together.

In other words if I run the code and one box is empty and not validated that redirects when it shouldn't. Validation should stop the redirecting when a box is empty.

It appears to be a bug in CodeIgniter that has not yet been detected.

Maybe some change within CodeIgniter's system file may fix both functions to work together.
You don't have an else. Therefor it always run, even thought your validation failed.

PHP Code:
public function index()
{
    
$error 0;
    
$realname "";
    
$username "";
    
$word "";

    
$this->load->helper(array('form''url','file'));
    
$this->load->library('form_validation');

    
$config = array(
        array(
'field' => 'rname''label' => 'RealName''rules' => 'required''errors' => array( 'required' => 'Provide%s')),
        array(
'field' => 'uname''label' => 'Username''rules' => 'required''errors' => array( 'required' => 'Provide%s')),
        array(
'field' => 'word''label' => 'Word''rules' => 'required''errors' => array( 'required' => 'Provide%s'))
    );

    
$this->form_validation->set_rules($config);
    if (
$this->form_validation->run() == FALSE)
    {
        
$this->load->view('names');
    }
    else
    {
        
$realname $this->input->post('rname');
        
$username $this->input->post('uname');
        
$word $this->input->post('word');

        if(!
file_exists("C:xampp/htdocs/file1/$realname")) exit ("$realname DoesNotExist");
        if(!
file_exists("C:xampp/htdocs/file2/$realname/$username")) exit ("$username DoesNotExist");
        if(!
file_exists("C:xampp/htdocs/file3/$realname/$word")) exit ("$word DoesNotExist");

        if(isset(
$_POST['submit'])) redirect(BASE_URL.'home');
    }

(09-18-2019, 10:26 AM)jreklund Wrote: [ -> ]You don't have an else. Therefor it always run, even thought your validation failed.

PHP Code:
public function index()
{
 
$error 0;
 
$realname "";
 
$username "";
 
$word "";

 
$this->load->helper(array('form''url','file'));
 
$this->load->library('form_validation');

 
$config = array(
 array(
'field' => 'rname''label' => 'RealName''rules' => 'required''errors' => array( 'required' => 'Provide%s')),
 array(
'field' => 'uname''label' => 'Username''rules' => 'required''errors' => array( 'required' => 'Provide%s')),
 array(
'field' => 'word''label' => 'Word''rules' => 'required''errors' => array( 'required' => 'Provide%s'))
 );

 
$this->form_validation->set_rules($config);
 if (
$this->form_validation->run() == FALSE)
 {
 
$this->load->view('names');
 }
 else
 {
 
$realname $this->input->post('rname');
 
$username $this->input->post('uname');
 
$word $this->input->post('word');

 if(!
file_exists("C:xampp/htdocs/file1/$realname")) exit ("$realname DoesNotExist");
 if(!
file_exists("C:xampp/htdocs/file2/$realname/$username")) exit ("$username DoesNotExist");
 if(!
file_exists("C:xampp/htdocs/file3/$realname/$word")) exit ("$word DoesNotExist");

 if(isset(
$_POST['submit'])) redirect(BASE_URL.'home');
 }


Thanks jreklund, your simple solution is my savior. Everything works good now in my testing environment although I expect it to be the same in the overall development.

(09-18-2019, 02:54 PM)daveĀ friend Wrote: [ -> ]I answered this question on Stack Overflow.

Yes you did answer in Stack Overflow but the solution from jreklund above is much more simpler.