Welcome Guest, Not a member yet? Register   Sign In
[Closed] CI Form Validation Still Not Working
#1

[eluser]riwakawd[/eluser]
Hello I have got the form validation way user guide says but not Displaying Errors, for form. I also use HMVC so not sure if that is effecting it.

Code:
public function index()
    {

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

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

        $this->form_validation->set_rules('db_driver', 'db_driver', 'required');
        $this->form_validation->set_rules('db_hostname', 'db_hostname', 'required');
        $this->form_validation->set_rules('db_username', 'db_username', 'required');
        $this->form_validation->set_rules('db_password', 'Password');
        $this->form_validation->set_rules('db_database', 'db_database', 'required');
        $this->form_validation->set_rules('db_prefix', 'db_prefix');


        if ($this->form_validation->run() == false)
        {
            $this->load->view('template/step_3');
        } else
        {
            $dbconfig['hostname'] = $this->input->post('db_hostname');
            $dbconfig['username'] = $this->input->post('db_username');
            $dbconfig['password'] = $this->input->post('db_password');
            $dbconfig['database'] = $this->input->post('db_database');
            $dbconfig['dbprefix'] = $this->input->post('db_prefix');
            //$dbconfig['pconnect'] = ($this->input->post('pconnect')) ? TRUE : TRUE;            
            $dbconfig['dbdriver'] = 'mysqli';


            $this->CI = &get;_instance();
            $this->CI->load->helper('file');

            $prototype = array(
                'hostname' => '',
                'username' => '',
                'password' => '',
                'database' => '',
                'dbdriver' => '',
                'dbprefix' => '',
                'pconnect' => true,
                'db_debug' => false,
                'cache_on' => false,
                'cachedir' => '',
                'char_set' => 'utf8',
                'dbcollat' => 'utf8_general_ci');
            // Now we read the file data as a string
            $config_file = read_file(self::$path);
            //self::$content = $config_file;
            //$this->set_config('hostname','localhost');
            // Dollar signs seem to create a problem with our preg_replace
            // so we'll temporarily swap them out
            $config_file = str_replace('$', '@s@', $config_file);
            // Cycle through the newconfig array and swap out the data
            if (count($dbconfig) > 0)
            {
                $active_group = 'default';
                foreach ($dbconfig as $key => $val)
                {
                    if ($val === 'y')
                    {
                        $val = true;
                    } elseif ($val == 'n')
                    {
                        $val = false;
                    }

                    if (is_bool($val))
                    {
                        $val = ($val == true) ? 'TRUE' : 'FALSE';
                    } else
                    {
                        $val = '\'' . $val . '\'';
                    }
                    $val .= ';';

                    // Update the value
                    $config_file = preg_replace("#(\@s\@db\[(['\"])" . $active_group . "\\2\]\[(['\"])" .
                        $key . "\\3\]\s*=\s*).*?;#", "\\1$val", $config_file);
                }
            }

View file

Code:
<form method="post" role="form" acti echo base_url('step_3/index');?>">

<p>1. Please enter your database connection details.</p>

<fieldset>

<div class="form-group required">
<label for="input-db-driver" class="control-label">DB Driver</label>
&lt;input type="text" name="db_driver" value="" id="input-db-driver" class="form-control" &gt;
</div>

<div class="form-group required">
&lt;?php echo form_error('db_driver', '<div class="error">', '</div>'); ?&gt;
</div>

<div class="form-group required">
<label for="input-db-hostname" class="control-label">Hostname</label>
&lt;input type="text" name="db_hostname" value="localhost" id="input-db-hostname" class="form-control" &gt;
</div>

<div class="form-group required">
&lt;?php echo form_error('db_hostname', '<div class="error">', '</div>'); ?&gt;
</div>

<div class="form-group required">
<label for="input-db-username" class="control-label">Username</label>
&lt;input type="text" name="db_username" value="" id="input-db-username" class="form-control" &gt;
</div>

<div class="form-group">
&lt;?php echo form_error('db_username', '<div class="error">', '</div>'); ?&gt;
</div>

<div class="form-group">
<label for="input-db-password">Password</label>
&lt;input  name="db_password" value="" id="input-db-password" class="form-control" /&gt;
</div>

<div class="form-group">
&lt;?php echo form_error('db_password', '<div class="error">', '</div>'); ?&gt;
</div>

<div class="form-group required">
<label for="input-db-database" class="control-label">Database</label>
&lt;input type="text" name="db_database" value="" id="input-db-database" class="form-control" /&gt;
</div>

<div class="form-group">
&lt;?php echo form_error('db_database', '<div class="error">', '</div>'); ?&gt;
</div>

<div class="form-group">
<label for="input-db-prefix">Prefix</label>
&lt;input type="text" name="db_prefix" value="" id="input-db-prefix" class="form-control" &gt;
</div>

<div class="form-group">
&lt;?php echo form_error('db_prefix', '<div class="error">', '</div>'); ?&gt;
</div>

</fieldset>
&lt;/form&gt;
#2

[eluser]Patroklo[/eluser]
Yes, it has to do. HMVC has a "problem" with codeigniter form validation:

http://ellislab.com/forums/viewthread/161740/#776983

There it's explained how to deal with it.
#3

[eluser]riwakawd[/eluser]
[quote author="Patroklo" date="1400218692"]Yes, it has to do. HMVC has a "problem" with codeigniter form validation:

http://ellislab.com/forums/viewthread/161740/#776983

There it's explained how to deal with it.[/quote]

Still nothing controller is MX_Controller Same issue when running CI_Controller Just not validating
#4

[eluser]Patroklo[/eluser]
Checking your code, first you have
Code:
$this->CI = &get;_instance();
, that should be
Code:
$this->CI = &get;_instance();

Then, why do you have a get_instance in a controller? You don't need it.

Code:
$this->load->helper('file');

That should do it instead of the

Code:
$this->CI = &get;_instance(); $this->CI->load->helper('file');

EDIT: all right, the get_instance it's a forum's problem, because i'm trying to get rid of the ; and I also can't.

I'm checking the rest of the code...
#5

[eluser]Patroklo[/eluser]
Checked your code and it works just fine in my web.

the view: http://pastie.org/9180921

the controller: http://pastie.org/9180925

and the proof: http://imgur.com/Ui1FrUg

Try this code and let us know if it works for you.
#6

[eluser]riwakawd[/eluser]
[quote author="Patroklo" date="1400225492"]Checked your code and it works just fine in my web.

the view: http://pastie.org/9180921

the controller: http://pastie.org/9180925

and the proof: http://imgur.com/Ui1FrUg

Try this code and let us know if it works for you.
[/quote]


Seems strange will not work I will have to re think it and look at it. Might be what cause problem is codeigniter-bcrypt. Or MX I have add ($this) == FASLE. I will think about it.

I will have to investigate.
#7

[eluser]Patroklo[/eluser]
Have you tried the code I posted you? It worked?
#8

[eluser]riwakawd[/eluser]
[quote author="Patroklo" date="1400229609"]Have you tried the code I posted you? It worked?[/quote]

Yes did not work.

I truly think must be something down my end.

Is there away to get this $prototype that you fixed work as a model rather than load direct on controller.

Because I know when loading via model I can get errors working.
#9

[eluser]Patroklo[/eluser]
Yes I can:

Controller: http://pastebin.com/3ycefNCY
Model: http://pastebin.com/UumQcBP0

The view doesn't change.

Just to be sure... I have only tried the form with all fields empty.
#10

[eluser]riwakawd[/eluser]
[quote author="Patroklo" date="1400232301"]Yes I can:

Controller: http://pastebin.com/3ycefNCY
Model: http://pastebin.com/UumQcBP0

The view doesn't change.

Just to be sure... I have only tried the form with all fields empty.[/quote]

Thanks will have ago.




Theme © iAndrew 2016 - Forum software by © MyBB