Welcome Guest, Not a member yet? Register   Sign In
dynamic drop down list
#1

[eluser]cerberus478[/eluser]
I'm trying to create a drop down list that has all the menu titles and it has to be from the database.
It must show up on the pages create view.
It must also save the menu id to the pages table so that the two are linked.
I'm trying to do it in a hmvc structure.

When I try to view the pages create page I get these errors
I know with this error the dropdown is undefined, but wouldn't it be defined since I'm calling the menus module?
Quote:Severity: Notice

Message: Undefined variable: dropdown

Filename: views/create.php

Line Number: 24

and
Quote:Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: helpers/form_helper.php

Line Number: 331


menus controller
Code:
function dropdown(){
  $data['dropdown'] = $this->menus_model->get_dropdown_tags();
  return $data;
}

menus_model
Code:
function get_dropdown_tags()
{
$drop = $this->db->query('select title from menus');
$dropdowns = $drop->result();
foreach ($dropdowns as $dropdown)
{
$dropdownlist[$dropdown->title] = $dropdown->title;
}
$finaldropdown = $dropdownlist;
return $finaldropdown;
}

This is the pages controller
Code:
function create(){
        $update_id = $this->uri->segment(3);
        $submit = $this->input->post('submit', TRUE);
        
        if($submit=="Submit"){
            //person has submitted the form
            $data = $this->get_data_from_post();
        } else {
            if(is_numeric($update_id)){
                $data = $this->get_data_from_db($update_id);
            }
        }
        
        if(!isset($data)){
            $data = $this->get_data_from_post();
        }
  
  //Calls the get_menus function for the drop down list
  $this->get_menus();
  
        
        $data['update_id'] = $update_id;
        
        $data['view_file'] = "create";
        $this->load->module('template');
        $this->template->admin($data);
    }

     function get_menus(){
   $this->load->module('menus');
   $this->menus->dropdown();
}

my pages create view
Code:
[removed][removed]
[removed]bkLib.onDomLoaded(nicEditors.allTextAreas);[removed]
      
<h2>Create a page</h2>
&lt;?php
    

    echo validation_errors("<p  red;'>", "</p>");
    
    echo form_open('pages/submit/'.$update_id);
?&gt;
<table width="900" cellpadding="8" cellspacing="0" border="1">
    <tr>
        <td> Title:
            &lt;?php
   echo form_dropdown('dropdown', $dropdown);
            ?&gt;
        </td>
        
    </tr>
    <tr>
        <td> Title:
            &lt;?php
                $data = array(
                    'name' => 'title',
                    'id' => 'title',
                    'value' => $title,
                    'maxlength' => '230',
                    'size' => '50',
                    'style' => 'width: 320px;',
                );
                
                echo form_input($data);
            ?&gt;
        </td>
        <td> Meta Title:
            &lt;?php
                $data = array(
                    'name' => 'meta_title',
                    'id' => 'meta_title',
                    'value' => $meta_title,
                    'maxlength' => '230',
                    'size' => '50',
                    'style' => 'width: 320px;',
                );
                
                echo form_input($data);
            ?&gt;
        </td>
    </tr>
    
    <tr>
        <td colspan="2"> Keywords:
            &lt;?php
                $data = array(
                    'name' => 'keywords',
                    'id' => 'keywords',
                    'value' => $keywords,
                    'maxlength' => '230',
                    'size' => '50',
                    'style' => 'width: 800px;',
                );
                
                echo form_input($data);
            ?&gt;
        </td>
    </tr>
    
     <tr>
        <td colspan="2"> Meta Description:
            &lt;?php
                $data = array(
                    'name' => 'meta_description',
                    'id' => 'meta_description',
                    'value' => $meta_description,
                    'maxlength' => '230',
                    'size' => '50',
                    'style' => 'width: 700px;',
                );
                
                echo form_input($data);
            ?&gt;
        </td>
    </tr>
  
    <tr>
    
        <td colspan="2" id="content"> Content:
            &lt;?php
                $data = array(
                    'name' => 'content',
                    'id' => 'content',
                    'value' => $content,
                    'rows' => '30',
                    'cols' => '50',
                    'style' => 'width: 750px;',
                );
                
                echo form_textarea($data);
            ?&gt;
        </td>
    </tr>
    
    <tr>
        <td colspan="2" align="center">
            &lt;?php
                echo form_submit('submit', 'Submit');
            ?&gt;
        </td>
    </tr>
</table>

&lt;?php
    echo form_close();
#2

[eluser]Massaki[/eluser]
You have to modify pages controller:
Code:
//Calls the get_menus function for the drop down list
  $data['dropdown'] = $this->get_menus();
#3

[eluser]cerberus478[/eluser]
I ended up getting
Quote:Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: helpers/form_helper.php

Line Number: 331
#4

[eluser]Massaki[/eluser]
Then try var_dump on $dropdown before. Maybe it does not return any records from DB.




Theme © iAndrew 2016 - Forum software by © MyBB