Welcome Guest, Not a member yet? Register   Sign In
Best practise for forms and multiple views?
#1

[eluser]Unknown[/eluser]
Hi, a hopefully easy question about how best to use a Controller and multiple Views to display a Form and submit it.

We are converting a small app to CI and not 100% sure how to best go about it, here is one example of a page that has a 8 views, as I've broken up our previous page into separate chunks as you can see below.

1. Is this best practise? It seems messy and unnecessary to have so many different views...

2. Also for my form, its 1/2 way down the page and preferably could be called from the 'keyword2/table' view to get it in the right spot for HTML code, but I know this is a big no no...

3. Should I be saving details to the DB in the Controller, as shown in my PHP comments?

Suggestions are welcomed.

Controller

Code:
function table($website_name = '', $website = '')
    {
        $data['website'] = $website;
        $data['website_name'] = $website_name;

        // load our Custom SEO Library
        $this->load->library('seo');

        $data['meta_title'] = 'Dashboard';
        $this->load->view('header', $data);
        $this->load->view('menu_top', $data);

        $data['engine_id'] = $this->seo->get_engine_default();
        $this->load->view('website/dashboard', $data);
        $this->load->view('keyword2/table', $data);

        // edit Keyword Ranking form
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');

    // form validation, will get to this
    //$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('keyword2/edit', $data);
        }
        else
        {
            // save stuff to db I guess?

            // ..then show Success view
            $this->load->view('keyword2/edit/success', $data);
        }

        // Footer
        $this->load->view('keyword2/footer');
        $this->load->view('footer', $data);

    }

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB