-1

autoload:

$autoload['libraries'] = array('database','form_validation');

controller:

class Adminlogin extends CI_controller
{
public function new_user()
        {
            $this->form_validation->set_rules('name','name','required');
            $this->form_validation->set_rules('email','email','required|valid_email');
            $this->form_validation->set_rules('password','password','required|min_length[8]|max_length[15]');

            if ($this->form_validation->run())
            {

                $Name    = $this->input->POST('name');  
                $Email = $this->input->POST('email');
                $Password = $this->input->POST('password');

                $data = array('Name' => $Name, 'Email' => $Email, 'Password' => $Password);
                $this->load->model('login_model');              
                $this->login_model->newuser_data($data);

                //redirect('public/login_form');
                $data['message'] = 'Data Inserted Successfully';
            }
            else
            {
                echo "not done";
            }
        }

if I remove condition from validation then form works and data in traveled and when I apply condition on validation then form not working data is also not traveling without showing any error.

model:

public function newuser_data($data)
    {
        $this->db->insert('users', $data);
        $query = $this->db->insert_id();
    }

view:

 <?php echo form_open('adminlogin/new_user'); ?>
            <div class="col-md-4">
                                    <center><h3>Create User!</h3>

                <div class="form-group">
                    <?php echo form_input(['type'=>'name','name'=>'name','placeholder'=>'Name','class'=>'form-control contact-form','value'=>set_value('name')]) ?>
                    <?php echo form_error('name'); ?>
                </div>
                <div class="form-group">
                    <?php echo form_input(['type'=>'email','name'=>'email','placeholder'=>'Email','class'=>'form-control contact-form','value'=>set_value('Email')]) ?>
                    <?php echo form_error('email'); ?>
                </div>
                <div class="form-group">
                    <?php echo form_input(['type'=>'Password','name'=>'password','placeholder'=>'Password','class'=>'form-control contact-form','value'=>set_value('Password')]) ?>
                    <?php echo form_error('password'); ?> 
                </div>
                <div class="form-group text-right button-submit btn-submit">
                    <?php echo form_submit(['name'=>'submit','value'=>'Login','class'=>'btn btn-primary']) ?>
                </div>
            </div>

5 Answers5

1
class Adminlogin extends CI_controller
{
public function new_user()
        {
            $this->form_validation->set_rules('name','name','required');
            $this->form_validation->set_rules('email','email','required|valid_email');
            $this->form_validation->set_rules('password','password','required|min_length[8]|max_length[15]');

            if ($this->form_validation->run()!=FALSE)
            {

                $Name    = $this->input->POST('name');  
                $Email = $this->input->POST('email');
                $Password = $this->input->POST('password');

                $data = array('Name' => $Name, 'Email' => $Email, 'Password' => $Password);
                $this->load->model('login_model');              
                $this->login_model->newuser_data($data);

                //redirect('public/login_form');
                $data['message'] = 'Data Inserted Successfully';
            }
            else
            {
                echo "not done";
            }
        }

Change in if condition

if ($this->form_validation->run()) 

to

if ($this->form_validation->run()!=FALSE)
usersn
  • 127
  • 1
  • 14
0

change this to

if ($this->form_validation->run())

to

if ($this->form_validation->run() != FALSE)

Read - Form Validation in codeigniter.com

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

Change your line

if ($this->form_validation->run())

to

if ($this->form_validation->run()===TRUE)
NSJ
  • 13
  • 7
  • When you try does it echo the message "not done" as you've defined? If not, put this if ($this->form_validation->run()===TRUE) as I mentioned before, and check whether you have configured the "form_validation" library. That is; $autoload['libraries'] = array('form_validation'); – NSJ May 30 '18 at 06:18
0

Change your statement

From

if ($this->form_validation->run())

To

if ($this->form_validation->run() == TRUE)

OR

if ($this->form_validation->run() != FALSE)
Danish Ali
  • 2,354
  • 3
  • 15
  • 26
0

Try using this controller

class Adminlogin extends CI_controller
{
public function new_user()
        {
            $this->form_validation->set_rules('name','name','required');
            $this->form_validation->set_rules('email','email','required|valid_email');
            $this->form_validation->set_rules('password','password','required|min_length[8]|max_length[15]');

            if ($this->form_validation->run()===FALSE)
            {

                echo 'Not done';
            }
            else
            {
                $Name    = $this->input->POST('name');  
                $Email = $this->input->POST('email');
                $Password = $this->input->POST('password');

                $data = array('Name' => $Name, 'Email' => $Email, 'Password' => $Password);
                $this->load->model('login_model');              
                $this->login_model->newuser_data($data);


            $data['message'] = 'Data Inserted Successfully';
        }
    }
NSJ
  • 13
  • 7