I am trying to submit my form using post method in codingniter , and my form is called from the main view when i submit the form i get 404 Page is not found .
This is my header form :
<form class="form-horizontal" id="sendform" role="form" action="<?php echo `base_url('/pages/insert_into_db') ;?>" method="post" >`
and in the controller i have this function controller :
pages.php :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pages extends CI_Controller {
public function view ($page='gurantee'){
if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$this->load->view('pages/'.$page);
}
public function index ()
{
$this->load->helper('url');
$this->load->view('Welome');
}
public function display () {
$this->load->model('ektreemodel');
$data['query']=$this->ektreemodel->display();
$this->load->view('table',$data);
}
public function insert_to_db()
{
$this->load->helper('url');
$this->load->model('ektreemodel');
$this->ektreemodel->insert_into_db();
$this->load->view('gurantee');
}
public function dis () {
$this->load->helper('url');
$this->load->view('registration');
}
}
and the url is :
http://localhost:8888/index.php/pages/index.php/pages/display
it was working fine when i submit my form the main first view , is there something i have to change or , is there some way i can use javascript , so when i will use post method it will call display function from the controller ?
Solution 1
<form class="form-horizontal" id="sendform" role="form" action="<?php echo site_url('pages/display') ;?>" method="post" >`
Use this code that has site_url()
rather than base_url()
Solution 2
If that doesn't work a more logical way would be:
echo form_open('pages/display', 'class="form-horizontal" id="sendform"');
This would generate the form tag for you. Hope this helps :)
Solution #3:
Make "p" capital in pages.php
making it Pages.php
Try this
<form class="form-horizontal" id="sendform" role="form" action="<?php echo base_url().'/pages/display' ;?>" method="post" >
To use base_url(), you must first have the URL Helper loaded.
$this->load->helper('url');
Also make sure site's base url is provided in application/config/config.php.
The problem was because i call view from another view i did not have to use base_ur since it will call localhost/index.php/controller.
i n my example i am in the place where my url is has been already call from the first view .
So all what i need to do is change the form method post into :
" method="post" >
Where it will call directly : http://localhost:8888/index.php/pages/insert_to_db
where http://localhost:8888/index.php/pages/ it called already before , so need to call base_url from the start .