0

I am new to code Igniter, I am facing with a little problem while validating form. The problem which i am facing is that the view with error is displayed with the original view. I don't know how to fix it. here is my code

<?php
class Tender extends CI_Controller {
function __construct()
{
    parent::__construct();
    $this->is_logged_in();
}
function add_nit()
{  
    $data['title'] = 'Add NIT';
    $data['main_content'] = 'tendermanager/add_nit'; 
    $this->load->view('includes/main_template',$data);

    if(isset($_POST['name']))
    {
            $this->form_validation->set_rules('name', 'name', 'required');

            $this->form_validation->set_error_delimiters('<p class="alert alert-danger">', '</p>');

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

        {

            $this->load->view('tendermanager/add_nit');

        }   
        else
        {
        //  redirect('tendermanager/tender/add_nit'); 
            }
    }

} }

View 1 (dashboard)

<?php $this->load->view('includes/main_header');?>
<div class="container-fluid" style="padding-top:90px;">
<div class="row-fluid">
<? echo $this->load->view('sidebar');?>

</div>

<div class="span9 well" style="background:#fff;">



<div class="page-header">

  <h1>add <small></small></h1>

</div>

 <?php $this->load->view('tendermanager/add_nit');?>

</div>

View 2 (add_nit)

<?php
echo form_open('tendermanager/tender/add_nit');?>
<div class="form-group">
<label>Office Name</label>
<input type="text" name="name" value="<?php echo set_value('name'); ?>" size="50" />
<?php echo form_error('name'); ?>
<br/>
<input type="submit" name='basicdetails' value="Get NIT Number" class="btn btn-primary"></button>
<?php echo form_close();?>

1 Answer 1

3

Your validation is not working because you not include form library inside your constructor

Read Form Validation

function __construct()
{
    parent::__construct();
    $this->load->library('form_validation');
    $this->is_logged_in();
}
Sign up to request clarification or add additional context in comments.

2 Comments

Dear validation is working properly. Giving error messages as well. but the issue is that the form with error is displayed with the original form. I mean the original form is not replaced with the form having errors Instead again the same form is displayed having errors on it.
if validation is incorrect please load it to same view where it comes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.