• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Navigation and subcategory

#1
[eluser]Référencement Google[/eluser]
Hi,

I would like to get some advices before starting doing this:
I have in a backend an "edit profile" page where I can edit user informations.
As it has a lot of things, I organised things in Tabs, and each tab have a different form.

Let's say for exemple, Tab 1 is for editing public profile infos, Tab 2 for the photos of the member, Tab 3 his videos, and Tab 4 some private infos

In this, I have a common part to all tabs that show a small thumbnail, the member name and some extra infos (let's say a small resume)

My url looking like that to reach the profile editing:
http://www.website.com/admin/profiles/edit/14 (where 14 is the profile ID)

How should I organise controllers functions and views that each forms post and validate to a specific fonction? Wich kind of Url would I have? I am not really sure on how to do things. (I was think of having url like: http://www.website.com/admin/profiles/edit/14/tab1

Here is a screenshot so maybe this help you to understand what I want to do:
http://www.imageultra.net/images/eliteme...enshot.jpg

Thanks for any help or advices

#2
[eluser]xwero[/eluser]
why not make one big form and tab them with javascript. Get the fields you need according with the name of the button.
This way you only need one controller and function.

#3
[eluser]Référencement Google[/eluser]
There are 2 problems making this. There is really too much datas and to manage this will be very difficult, I would really prefer to have independant forms. Second problem is how I will do to display again the form part of the Tab with JS ? I mean for exemple if validation fail, how with JS will I get the right tab opened showing validation errors?

Looks very complicate with JS.

#4
[eluser]xwero[/eluser]
The tabs don't have to be difficult. If you use the tabs plugin of jquery it has a function to open a page an the right tab via an url.

If there are a lot of fields you are right wanting them in different forms it would weight to much on you traffic if it is used a lot.
There are two ways to go, as far as i know:
- dedicate a controller to your tabs
multiform/tab1, multiform/tab2, ...
- split up one function for your tabs
somecontroller/multiform/tab1, somecontroller/multiform/tab2, ...

If you follow the small function rule you should use a controller and take care of one form per function.
But if you use one function you can group the validation and the processing of the form.
Code:
function multiforms()
{
    $this->load->library('validation');
    switch($this->uri->segment(3))
    {
        case 'tab1':
           $rules['username']    = "required";
        $rules['password']    = "required";
        $rules['passconf']    = "required";
        $rules['email']        = "required";
           break;
        case 'tab2':
           $rules['username']    = "required";
        $rules['password']    = "required";
        $rules['passconf']    = "required";
        $rules['email']        = "required";
           break;
    }
    $this->validation->set_rules($rules);
    switch($this->uri->segment(3))
    {
        case 'tab1':
           if ($this->validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
           break;
        case 'tab2':
           if ($this->validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
           break;
    }
}

It depends on how you like to maintain code.

#5
[eluser]Référencement Google[/eluser]
Ok, nice solution, thank you Xwero!

#6
[eluser]xwero[/eluser]
I just woke up when i made the sugesstion. i think this one is even better, less clutter more grouping.

Code:
function multiforms()
{
    $this->load->library('validation');
    switch($this->uri->segment(3)) // rules
    {
        case 'tab1':
           $rules['username']    = "required";
        $rules['password']    = "required";
        $rules['passconf']    = "required";
        $rules['email']        = "required";
           break;
        case 'tab2':
           $rules['username']    = "required";
        $rules['password']    = "required";
        $rules['passconf']    = "required";
        $rules['email']        = "required";
           break;
    }
    $this->validation->set_rules($rules);
    if ($this->validation->run() == FALSE) // error
    {
       switch($this->uri->segment(3))
       {
           case 'tab1':
               $this->load->view('myform');
               break;
           case 'tab2':
               $this->load->view('myform');
               break;
        }
    }
    else  // success
    {
        switch($this->uri->segment(3))
       {
           case 'tab1':
               $this->load->view('myform');
               break;
           case 'tab2':
               $this->load->view('myform');
               break;
        }
    }

#7
[eluser]Référencement Google[/eluser]
Ok, little bit late, I already coded the previous one, but anyway thanks, it will be usefull for some people reading forums.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.