I am trying to create a master & view page layout, with Header, left menu, right content view & a footer. Each content page is written in <div>s in separate pages.
With respect to my left menu link clicks, the corresponding page is loaded in content view. I used jQuery for this purpose, but when I use form_open() in content view <div>, it returns:
undefined function form_open()
I have tried both
$autoload['helper'] = array('url','form');
and
$this->load->helper('form');
But neither are working.
When I use form_open() in a view page and load it via $this->load->view()
in controller, I'm able to use the form_open method
Here is controller class, template.php & content.php files
class Home extends CI_Controller {
public function index(){
$this->load->helper('form');
$this->load->library('form_validation');
$this->view();
}
public function view() {
$this->load->view('templates/template');
.
.
.
}
application/views/templates/template.php
.
.
.
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#leftmenu_main ul li a').click(function(){
$('#content_main').load('<?=base_url()?>application/views/templates/content.php #' + $(this).attr('href'));
return false;
});
}
<div id="leftmenu">
<div id="leftmenu_main">
<ul>
<li><a href="createnewuser">Create New User</a></li>
<li><a href="createnewtask">Create New Task</a></li>
</ul>
</div>
</div>
<div id="content_main">
.
.
.
</div>
application/views/templates/content.php
<div id="createnewuser">
<?=form_open(controller/method);?>
.
.
.
<?=form_close();?>
</div>
<div id="createnewtask">
<?=form_open(controller/method);?>
.
.
.
<?=form_close();?>
</div>
When i use view() of Home Controller like the following, & place one of my div's "content" as a page in views/pages/ , it works & 'm able to use the form_open() tag ...
public function view() {
$page = 'createnewtask';
$this->load->view('templates/header');
$this->load->view('pages/'.$page);
$this->load->view('templates/footer');
}
I have searched a lot for this but unable to find a solution.
Is there something which I need to load / configure for using form_open() in a separate page <div>?
form_openis. You say you are using jQuery. Are you using AJAX? Are you having the AJAX load the view file directly? You can't do that. You need to have the AJAX load the controller and have the controller load the view with$this->load->view.$('#content_main').loadis AJAX.