CodeIgniter Forums
Dynamically insert a form view into a template view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Dynamically insert a form view into a template view (/showthread.php?tid=38818)



Dynamically insert a form view into a template view - El Forum - 02-19-2011

[eluser]imcl[/eluser]
Haven't been able to figure this out yet:

I have a view file (main_view.php) which I use as my template.

It has a left-sided div for the menu, and another div for content:

Code:
<td width="200">
                    <div class="">
                        &lt;?= $menu ?&gt;
                        </div>
</td>

<td width="700">
                    <div class="">
                        &lt;?= $content ?&gt;
                        </div>
</td>

Say the left menu shows the following links:

Code:
- Update email
- Update Password
- Update Profile


How do I make different forms appear in the &lt;?= $content?&gt; div when each menu item is clicked?

I have no idea how to pass the following code to &lt;?= $content?&gt; (this is the change_email_form view from Tank_auth).

Any suggestions are much appreciated!

Code:
&lt;?php
$password = array(
    'name'    => 'password',
    'id'    => 'password',
    'size'    => 30,
);
$email = array(
    'name'    => 'email',
    'id'    => 'email',
    'value'    => set_value('email'),
    'maxlength'    => 80,
    'size'    => 30,
);
?&gt;
&lt;?php echo form_open($this->uri->uri_string()); ?&gt;
<table>
    <tr>
        <td>&lt;?php echo form_label('Password', $password['id']); ?&gt;</td>
        <td>&lt;?php echo form_password($password); ?&gt;</td>
        <td style="color: red;">&lt;?php echo form_error($password['name']); ?&gt;&lt;?php echo isset($errors[$password['name']])?$errors[$password['name']]:''; ?&gt;</td>
    </tr>
    <tr>
        <td>&lt;?php echo form_label('New email address', $email['id']); ?&gt;</td>
        <td>&lt;?php echo form_input($email); ?&gt;</td>
        <td style="color: red;">&lt;?php echo form_error($email['name']); ?&gt;&lt;?php echo isset($errors[$email['name']])?$errors[$email['name']]:''; ?&gt;</td>
    </tr>
</table>
&lt;?php echo form_submit('change', 'Send confirmation email'); ?&gt;
&lt;?php echo form_close(); ?&gt;



Dynamically insert a form view into a template view - El Forum - 02-20-2011

[eluser]gvillavizar[/eluser]
Easy enough, you can load a view into a variable using the third parameter in codeigniter.

So if you are passing a parameter to the controller via the url you only need to do a switch or something.

Code:
switch($parameter)
{
    case 'update_email';
    $data['content'] = $this->load->view('update_email', TRUE);
    break;

    case 'update_password';
    $data['content'] = $this->load->view('update_password', TRUE);
    break;

    case 'update_profile';
    $data['content'] = $this->load->view('update_profile', TRUE);
    break;
}

Something like that.


Dynamically insert a form view into a template view - El Forum - 02-20-2011

[eluser]imcl[/eluser]
thanks GV -- I finally solved the issue using Colin Williams Template class, with some tweaking here and there. But the switch method seems to be a good alternative.