Help with controller and view
Hello,
I am trying to create a page with a form which will be submitted to the database.
I created a view file called: test.php
And this is my controller:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->library('form_builder');
if (!empty($_POST) AND $_SERVER['SERVER_ADDR'] == $_SERVER['REMOTE_ADDR'])
{
if ($this->_process($_POST))
{
redirect('test');
}
}
$fields = array();
$fields['category'] = array('required' => TRUE);
$fields['adtype'] = array('required' => TRUE, 'type'=>'select');
$this->form_builder->set_fields($fields);
// will set the values of the fields if there is an error... must be after set_fields
$this->form_builder->set_validator($this->validator);
$this->form_builder->set_field_values($_POST);
$this->form_builder->display_errors = TRUE;
$this->form_builder->required_text = '*required fields';
$vars['form'] = $this->form_builder->render();
// use Fuel_page to render so it will grab all opt-in variables and do any necessary parsing
$page_init = array('location' => 'test');
$this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init);
$this->fuel_page->add_variables($vars);
$this->fuel_page->render();
}
When I go to this page in the browser, the page is empty, there is no form in it.
Can you please help?
Comments
echo $form;
in my view.Thanks