0

I have a web app built on Codeigniter but I don't know which version it is. My job is just adding a simple form for this web app. The form should look like this:

enter image description here


And then here's my VIEW:

<div class="box">
            <h4 class="white">ADD CIT Details</h4>
        <div class="box-container">
            <div class="modal-body form">


        <form action="#" id="formcit" class="form-horizontal">
        <?php echo form_open('insert_cit_ctrl'); ?>
          <div class="form-body">
          <?php if (isset($message)) { ?>
            <CENTER><h3 style="color:green;">Data inserted successfully</h3></CENTER><br>
            <?php } ?>

            <div class="form-group">
              <label class="control-label col-md-3">Terminal ID</label> <?php echo form_error('dterminalid'); ?>
              <div class="col-md-9">
                <?php echo form_input(array('id' => 'dterminalid', 'name' => 'dterminalid')); ?>
              </div>
            </div>

            <div class="form-group">
              <label class="control-label col-md-3">CIT</label>
              <div class="col-md-9">
                <select class="form-control" id="selectcit" >
                  <option value="none">-- Select CIT --</option>
                  <option value="CMS">1. CMS</option>
                  <option value="ALPHA">2. ALPHA</option>
                </select>
              </div>
            </div>

            <div class="form-group">
              <label class="control-label col-md-3">Branch</label> <?php echo form_error('dbranch'); ?>
              <div class="col-md-9">
                <?php echo form_input(array('id' => 'dbranch', 'name' => 'dbranch')); ?>
              </div>
            </div>

            <div class="form-group">
              <label class="control-label col-md-3">COMM</label> <?php echo form_error('dcomm'); ?>
              <div class="col-md-9">
                <?php echo form_input(array('id' => 'dcomm', 'name' => 'dcomm')); ?>
              </div>
            </div>

             <div class="form-group">
              <label class="control-label col-md-3">Machine Type</label> <?php echo form_error('dmachinetype'); ?>
              <div class="col-md-9">
                <?php echo form_input(array('id' => 'dmachinetype', 'name' => 'dmachinetype')); ?>
              </div>
            </div>

            <?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>


          </div>
          <?php echo form_close(); ?>
        </form>
          </div>
        </div><!-- end of div.box-container -->
        </div> <!-- end of div.box -->  

And then this is my controller:

function insert_cit_ctrl() {
        $this->load->library('form_validation');

        $this->form_validation->set_error_delimiters('<div class="error">', '</div>');

        $this->form_validation->set_rules('dterminalid', 'Terminal ID', 'required');
        $this->form_validation->set_rules('dcit', 'CIT', 'required');
        $this->form_validation->set_rules('dbranch', 'Branch', 'required');
        $this->form_validation->set_rules('dcomm', 'COMM', 'required');
        $this->form_validation->set_rules('dmachinetype', 'Machine Type', 'required');

        if ($this->form_validation->run() == FALSE) {
        echo "<script>alert('Something wrong with your input');</script>";
        } else {
        //Setting values for tabel columns
        $data = array(
        'terminal_id' => $this->input->post('dterminalid'),
        'cit' => $this->input->post('dcit'),
        'branch' => $this->input->post('dbranch'),
        'comm' => $this->input->post('dcomm'),
        'machine_type' => $this->input->post('dmachinetype')
        );
        //Transfering data to Model
        $this->cit_model->modeladdcit($data);
        $data['message'] = 'Data Inserted Successfully';
        //Loading View
        $this->load->view('template', $data);
        }
    }

And here's my model:

<?php
class Cit_model extends CI_Model{
function __construct() {
parent::__construct();

}

function modeladdcit($data){
    $this->load->database('database_office', 'TRUE');
    $this->db->insert('tbl_cit', $data);
    }
}
?>

And the result? Here's my database:

enter image description here

There's no error at all. It's just that after I submit the data, it won't appeared on my database, not a single data. Meaning, that data is not even INSERT INTO the database.

I don't understand. What is wrong with my code?


UPDATE:

Ok, so I followed your tips guys, like this:

<form action="<?php echo base_url("evangelion/insert_cit_ctrl"); ?>" id="formcit" method="POST" class="form-horizontal">

What actually happened was... NOTHING. I mean, the data still not inserted into the database. And worse, the page ruined, it called only the function, not the whole page like it used to.

2 Answers 2

1

add the action and method to your form

<form action="<?php echo base_url("controller_name/function_name"); ?>" id="formcit" method="POST" class="form-horizontal">
Sign up to request clarification or add additional context in comments.

1 Comment

Hello, I've updated my post, can you help me one more time?
0
First try to display errors like this

you can find where you are wrong..

where you call controller in codeigniter you must call controller

action="controllername/actionname"

 <?php
        echo ini_get('display_errors');

       if (!ini_get('display_errors')) {
        ini_set('display_errors', '1');
         }

           echo ini_get('display_errors');
          ?>

i thought you did not mention method type in form

method ="POST"

1 Comment

Hello, I've updated my post, can you help me one more time? Also, about the error, it's not even showing any errors. I asked my co-worker to look into it and he said that the function skip the IF FALSE part.

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.