CodeIgniter Forums
[SOLVED] One form across multiple divs/tabs ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: [SOLVED] One form across multiple divs/tabs ? (/thread-35122.html)



[SOLVED] One form across multiple divs/tabs ? - El Forum - 10-19-2010

[eluser]Brandt1981[/eluser]
I think I have gotten myself in too deep here...

I am using CI w/ Doctrine plugin.

I have multiple tabs on my page, each containing a form with text boxes and a submit type button. Each form represents a table in the database. I am trying to do CRUD with these forms. I don't know how to explain it other than to show the code:

View home.php:

Code:
<div class="container">
    <div class="tab_container">

        <div id="tab1" class="tab_content">
            <h2>Personal</h2>

&lt;?php echo form_open('home/'.$submit); ?&gt;

<p>
<label for="username">Employee ID: </label><br/>
&lt;?php $data = array(
                    'name'        => 'empid',
                    'value'       => set_value('empid',$employee['pk_emp_id']),
                    'readonly'     => 'readonly',
                    );

        echo form_input($data); ?&gt;
</p>
<p>
<label for="username">First Name: </label>
<label for="username">Last Name: </label><br/>
&lt;?php echo form_input('firstnm',set_value('firstnm',$employee['emp_f_nm'])); ?&gt;

...

</p>
   <p>
      &lt;?php echo form_submit('submit','Update'); ?&gt;
   </p>
&lt;?php echo form_close(); ?&gt;

        </div>


        <div id="tab2" class="tab_content">
            <h2>Employment</h2>

&lt;?php echo form_open('home/'.$submit); ?&gt;
<p>
<label for="username">Employee ID: </label><br/>
&lt;?php $data = array(
                    'name'        => 'empid',
                    'value'       => set_value('empid',$employee['pk_emp_id']),
                    'readonly'     => 'readonly',
                    );
        echo form_input($data); ?&gt;
</p>
<p>
<label for="username">Hire Date: </label>
<label for="username">Termination Date: </label><br/>
&lt;?php echo form_input('hiredt',set_value('hiredt',$employment['hire_dt'])); ?&gt;

...

</p>
<p>
&lt;?php echo form_submit('submit','Update'); ?&gt;
</p>
&lt;?php echo form_close(); ?&gt;


Controller home.php:

Code:
public function index() {

                        $q = Doctrine_Core::getTable('Employee_info')

                        ->createQuery('e')
                        ->where('e.pk_emp_id = ?', NULL);

                        $vars['employee']= $q->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
                        $vars['employment']= $q->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
                        $vars['performance']= $q->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
                        $vars['timeoff']= $q->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
                        $vars['salary']= $q->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);

                        $vars['submit']='create';
                        $this->load->view('home',$vars);
                }

                public function update() {

                  $user_id = $this->input->post('empid');

                  $emp_f_nm = $this->input->post('firstnm');
                  $employee = Doctrine::getTable('Employee_info')->find($user_id);
                  $employee->emp_f_nm = $emp_f_nm;
                  $employee->save();

                  $hire_dt = $this->input->post('hiredt');
                  $employment = Doctrine::getTable('Employment_info')->find($user_id);
                  $employment->hire_dt = $hire_dt;
                  $employment->save();
  
                  $vars['employee'] = Doctrine::getTable('Employee_info')->find($user_id);
                  $vars['employment'] = Doctrine::getTable('Employment_info')->find($user_id);
                  $vars['performance'] = Doctrine::getTable('Employee_performance')->find($user_id);
                  $vars['timeoff'] = Doctrine::getTable('Employee_time_off')->find($user_id);
                  $vars['salary'] = Doctrine::getTable('Salary')->find($user_id);
                  $vars['submit']='update';

                  $this->load->view('home', $vars);

                }

                public function query() {
                        $user_id = $this->input->post('query');


                        $vars['employee'] = Doctrine::getTable('Employee_info')->find($user_id);
                        $vars['employment'] = Doctrine::getTable('Employment_info')->find($user_id);
                        $vars['performance'] = Doctrine::getTable('Employee_performance')->find($user_id);
                        $vars['timeoff'] = Doctrine::getTable('Employee_time_off')->find($user_id);
                        $vars['salary'] = Doctrine::getTable('Salary')->find($user_id);
                        $vars['submit']='update';

                        $this->load->view('home', $vars);


                }
              
                public function create() {
                         $firstnm = $this->input->post('firstnm');
                         $e = new Employee_info();
                         $e->emp_f_nm = $firstnm;

                         $conn = Doctrine_Manager::connection();
                         $conn->flush();

                         $vars['employee'] = Doctrine::getTable('Employee_info')->findOneByemp_f_nm($firstnm);
                        $vars['employment'] = Doctrine::getTable('Employment_info')->findOneByemp_f_nm($firstnm);
                        $vars['performance'] = Doctrine::getTable('Employee_performance')->findOneByemp_f_nm($firstnm);
                        $vars['timeoff'] = Doctrine::getTable('Employee_time_off')->findOneByemp_f_nm($firstnm);
                        $vars['salary'] = Doctrine::getTable('Salary')->findOneByemp_f_nm($firstnm);

                         $vars['submit']='update';
                         $this->load->view('home', $vars);

                }
        }



[SOLVED] One form across multiple divs/tabs ? - El Forum - 10-19-2010

[eluser]Brandt1981[/eluser]
From what you can see, when the page first loads, the forms are blank. and the submit url is set to 'home/create'


When a result from a primary key query is returned the textboxes in all the tabs are filled with the data and the submit url is set to 'home/update'

When the data in a text box is modified and submitted it goes to 'home/update'


This is easy enough with one form, but with multiple forms calling the same functions, I get confused...

I was hoping to put all the tabs in one form element, but that didn't seem to work. The CSS got all screwed up.


I guess I can create multiple functions for each form, but is this the right way to go?


EDIT: I ended up creating multiple functions for each form instead of some sort of javascript form collector...