Welcome Guest, Not a member yet? Register   Sign In
Form validation not running
#1

Hi all,

I'm trying to figure out why my form_validation_run function isn't returning true after I submit my form.

Here is my form:

Code:
<?php echo validation_errors(); ?>
   <?php echo form_open('admin/'.$section_data->name); ?>
   
   <textarea class="a"><?php echo $section_data->body; ?></textarea>
   
   <nav class="navbar navbar-default navbar-fixed-bottom">
       <div class="container">
           <button type="submit" class="btn btn-success navbar-btn navbar-right">Save</button>
           </form>
       </div>
   </nav>


And here is my Controller:
Code:
class Admin extends CI_Controller {
   
   public function __construct()
   {
       parent::__construct();
       $this->load->library('session');
       $this->load->helper('url');
       $this->load->model('section_model');
   }
   
   public function index($section = 'news')
   {
       $this->load->helper('form');
       $this->load->library('form_validation');
       
       $data['all_sections'] = $this->section_model->get_section();
       $data['section_data'] = $this->section_model->get_section($section);
       
       if ($this->form_validation->run() == FALSE) {
           $this->load->view('admin_home', $data);
       }
       else
       {
           $this->load->view('boom');
       }
   }


...

Everytime I submit the form, the admin_home view shows and not the boom view.

Any help appreciated, thanks.
Reply
#2

(12-29-2015, 01:29 AM)Domcsore Wrote: Hi all,

I'm trying to figure out why my form_validation_run function isn't returning true after I submit my form.

Here is my form:

Code:
<?php echo validation_errors(); ?>
   <?php echo form_open('admin/'.$section_data->name); ?>
   
   <textarea class="a"><?php echo $section_data->body; ?></textarea>
   
   <nav class="navbar navbar-default navbar-fixed-bottom">
       <div class="container">
           <button type="submit" class="btn btn-success navbar-btn navbar-right">Save</button>
           </form>
       </div>
   </nav>


And here is my Controller:
Code:
class Admin extends CI_Controller {
   
   public function __construct()
   {
       parent::__construct();
       $this->load->library('session');
       $this->load->helper('url');
       $this->load->model('section_model');
   }
   
   public function index($section = 'news')
   {
       $this->load->helper('form');
       $this->load->library('form_validation');
       
       $data['all_sections'] = $this->section_model->get_section();
       $data['section_data'] = $this->section_model->get_section($section);
       
       if ($this->form_validation->run() == FALSE) {
           $this->load->view('admin_home', $data);
       }
       else
       {
           $this->load->view('boom');
       }
   }


...

Everytime I submit the form, the admin_home view shows and not the boom view.

Any help appreciated, thanks.

Have you set any validation rule for your textarea? You could read more about form validation from CI doc here
Reply
#3

Additionally, any control which you want posted in your form needs a name attribute to define the key used to access the value of the control in the posted data.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB