0
   function form_submit (){

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

            $this->form_validation->set_rules('cname', 'Company Name', 'required');
            $this->form_validation->set_rules('cpname', 'Contact Person Name', 'required');
            $this->form_validation->set_rules('add1', 'Address Line 1 ', 'required'); 

  if($this->form_validation->run() == TRUE) {
       echo 'sucess';
              }
          else {

     echo validation_errors();
         }

 } 

here is my form

                          <form id="form_sub"  action="controller/form_submit">
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <label>Company Name <span>*</span></label>
                                            <input name="cname"  type="text"   value=""  maxlength="100"  />
                                            <div class="clear"></div>
                                        </div>

                                        <div class="col-sm-6">
                                            <label>Contact Person <span>*</span></label>
                                            <input  name="cpname"   type="text"    value=""  maxlength="100" />
                                            <div class="clear"></div>
                                        </div>
                                        <div class="col-sm-6">
                                            <label>Address Line 1 <span>*</span></label>
                                            <input   name="add1"   type="text"  value=""  maxlength="100"  />
                                            <div class="clear"></div>
                                        </div>
                                        <input type="submit" value="submit" />
                                        </div>
                                        </form>

All the time $this->form_validation->run() is returning false . What am i missing here , even if i give correct values and submit the form it gives error

vellai durai
  • 1,019
  • 3
  • 16
  • 38

1 Answers1

2

You missed the method attribute in form tag. It should be

<form id="form_sub"  action="<?php echo site_url('controller/form_submit');?>" method="POST">
Rejoanul Alam
  • 5,435
  • 3
  • 39
  • 68
  • 1
    Very true. [In addition to this answer](http://stackoverflow.com/questions/2314401/what-is-the-default-form-http-method). – Tpojka Oct 15 '16 at 16:10
  • 1
    Also check the return values of `$this->form_validation->run() == TRUE` with a strict comparison (===) – L.H Oct 15 '16 at 22:06