0

i don't know why form helper is not working, it doesn't submit data its just refreshing the same page and shows some field in url "http://localhost:8080/login/index.php/location/add?country_name=vfwq&city_name=csa&currency=f&symbol=w&mysubmit=Submit+Form"....

View add.php

<form class="form-horizontal">
                            <fieldset>
                            <?php echo form_open('location/add_data'); ?>

                              <div class="control-group">
                                <label class="control-label" for="country_name">`enter code here`<?=$this->lang->line('location_countryname')?></label>
                                <div class="controls">
                                  <input class="input-xlarge focused" id="country_name" type="text" name="country_name" value="<?=set_value('country_name')?>">
                                </div><br>
                                <div class="control-group">
                                <label class="control-label" for="city_name"><?=$this->lang->line('location_cityname')?></label>
                                <div class="controls">
                                  <input class="input-xlarge focused" id="city_name" type="text" name="city_name" value="<?=set_value('city_name')?>">
                                </div><br>
                                <div class="control-group">
                                <label class="control-label" for="currency"><?=$this->lang->line('location_currency')?></label>
                                <div class="controls">
                                  <input class="input-xlarge focused" id="currency" type="text" name="currency" value="<?=set_value('currency')?>">
                                </div><br>
                                <div class="control-group">
                                <label class="control-label" for="symbol"><?=$this->lang->line('location_symbol')?></label>
                                <div class="controls">
                                  <input class="input-xlarge focused" id="symbol" type="text" name="symbol" value="<?=set_value('symbol')?>">
                                </div>

                              <div class="form-actions">
                                <button class="btn btn-primary"  <?php echo form_submit('submit'); ?> <?=$this->lang->line('location_savechange')?></button>
                                <button class="btn"><?=$this->lang->line('location_cancel')?></button>
                              </div>

                              <?php echo form_close(); ?>
                            </fieldset>
                          </form>   

controller location.php class Location extends CI_Controller {

public function index()
{   
    $this->load->model('location_m');
    $data['record']=$this->location_m->view();
    $data['mian_content'] = 'location/index';       
    $this->load->view('components/view_index', $data);

}




public function add()
{   
    $data['mian_content'] = 'location/add';     
    $this->load->view('components/view_index', $data);
}





public function add_data()
{   
    if ($this->input->post('mysubmit')) {
    $data = array(
    'country_name'=>$this->input->post('country_name'),
    'city_name'=>$this->input->post('city_name'),
    'currency'=>$this->input->post('currency'),
    'symbol'=>$this->input->post('symbol'),
    );
    $this->load->model('location_m');
    $this->location_m->add($data);
    $data['mian_content'] = 'location/index';       
    $this->load->view('components/view_index', $data);
    redirect('location/index', 'refresh');
    }

model location_m

class Location_m extends CI_Model{

public function view()
{       
    $q = $this->db->get('country'); 
     if($q->num_rows() > 0){
        foreach($q->result() as $row) {
            $data[]=$row;
        }
    }
    return $data;


}

public function add($data)
{       
    $q = $this->db->insert('country',$data);

    return;
}
3
  • 1
    you have form inside of form? Commented Feb 26, 2016 at 17:19
  • thanks men i rewired the hole code like for hundreds of times and it was just this silly mistake.. Commented Feb 26, 2016 at 17:26
  • 1
    its working now Thanks again... Commented Feb 26, 2016 at 17:26

2 Answers 2

0

You need to close your div tags (the ones that have control-group as class).

Those errors are very easy to solve by properly indenting your code when you write it!

Sign up to request clarification or add additional context in comments.

Comments

0

You should take only one form. nested form is not working.

<form class="form-horizontal" method="post" action="location/add_data">
                              <div class="control-group">
                                <label class="control-label" for="country_name">`enter code here`<?=$this->lang->line('location_countryname')?></label>
                                <div class="controls">
                                  <input class="input-xlarge focused" id="country_name" type="text" name="country_name" value="<?=set_value('country_name')?>">
                                </div><br>
                                <div class="control-group">
                                <label class="control-label" for="city_name"><?=$this->lang->line('location_cityname')?></label>
                                <div class="controls">
                                  <input class="input-xlarge focused" id="city_name" type="text" name="city_name" value="<?=set_value('city_name')?>">
                                </div><br>
                                <div class="control-group">
                                <label class="control-label" for="currency"><?=$this->lang->line('location_currency')?></label>
                                <div class="controls">
                                  <input class="input-xlarge focused" id="currency" type="text" name="currency" value="<?=set_value('currency')?>">
                                </div><br>
                                <div class="control-group">
                                <label class="control-label" for="symbol"><?=$this->lang->line('location_symbol')?></label>
                                <div class="controls">
                                  <input class="input-xlarge focused" id="symbol" type="text" name="symbol" value="<?=set_value('symbol')?>">
                                </div>

                              <div class="form-actions">
                                <button class="btn btn-primary"  <?php echo form_submit('submit'); ?> <?=$this->lang->line('location_savechange')?></button>
                                <button class="btn"><?=$this->lang->line('location_cancel')?></button>
                              </div>


</form>

Comments

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.