Welcome Guest, Not a member yet? Register   Sign In
Form_Dropdown() help
#1

[eluser]Unknown[/eluser]
Hi, I've just started using codeIgniter afew days ago and am currently doing up a website based on videos and stuff therefore I'd want a drop box to be in place so that I'll be able to let users select the categories they want to view.

This is the view code

Code:
<?= $state ?>
   <form name="Choose" method="post" action="<?=base_url() ."/index.php/user/choice"?>">

<?php
    echo "<table>";
    echo "<tr>";
    echo "<td valign="top"><font face="comic sans MS" color="#FFCC00">Category</font>:</td>"
    echo "<td valign='top'>" .form_dropdown($options) ."</td>";
    echo "</tr>";
    echo "</table>";

&lt;?

    [removed]
        function chosen(){

            if (choice.form_dropdown('Shows', $choice, 'Cat1'))
            echo form_open('video/sort_category/7/all');
            else
            redirect(('video/sort_category/13/all');    
    
        }

    [removed]
    &lt;input type="submit" value="Go!"&gt;
    &lt;/form&gt;

And this is what I've placed in the controller file

Code:
function choice(){
    
$options = array(
        'Cat1' => 'Comedy',
        'Cat2' => 'Variety',
        'Cat3' => 'News',
        'Cat4' => 'Drama',
        'Cat5' => 'Info/educational',
        'Cat6' => 'Movie',
        'Cat7' => 'Sports',
        'Cat8' => 'Cartoon'
                );
$choice = array('Cat1', 'Cat2', 'Cat3', 'Cat4', 'Cat5', 'Cat6', 'Cat7');
$this->load->view("choice", $data);
}

So sorry to disturb, but I'm really confused over the Form_dropdown function >< .
#2

[eluser]GSV Sleeper Service[/eluser]
ok, first of all read this page thoroughly, there's a perfect working example of how to use form_dropdown.
http://ellislab.com/codeigniter/user-gui...elper.html

you are passing $data to your view, but $data is empty. you need to change your controller slightly.
Code:
$data['options'] = array(
        'Cat1' => 'Comedy',
        'Cat2' => 'Variety',
        'Cat3' => 'News',
        'Cat4' => 'Drama',
        'Cat5' => 'Info/educational',
        'Cat6' => 'Movie',
        'Cat7' => 'Sports',
        'Cat8' => 'Cartoon'
                );
$data['choice'] = array('Cat1', 'Cat2', 'Cat3', 'Cat4', 'Cat5', 'Cat6', 'Cat7');
$this->load->view("choice", $data);

I would advise against using redirect() in your views. The font tag was deprecated long ago, and comic sans?! are you insane? Wink
#3

[eluser]Unknown[/eluser]
Haha, was just playing around with fonts earlier on and decided it to be comic sans for now. Anyway thanks for the help and I'll try the code later at work Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB