Unable to get value of foreign key dropdown in simple module

edited April 2014 in Modules
Hi Guys,

I am developing a site with Fuel CMS and so far, its been awesome except for this stumbling block.. I have created several simple modules for basic database interactions.. In one of my modules, I use a foreign key so which automatically displays a select dropdown field on my create/edit page for my module... But, the problem is, I cant get the value from the dropdown. Below is my code snippet contained in the on_before_validate function -

$values['package_name'] = $values['package_id'] ;

where package_id is the id value for the foreign key dropdown.... Using inspect element on my browser, I can see the values for each dropdown options but somehow, I just cant seem to get the value in PHP.. It returns an undefined index error..

Pls, any help with be greatly appreciated..

Comments

  • edited 2:31AM
    So just to be clear, you have a field in your table of "package_id" and in your model, you have something like:
    public $foreign_keys = array('package_id' => 'packages_model');
    Then in your on_before_validate method you have something like:
    function on_before_validate($values) { $values['package_name'] = $values['package_id'] ; return $values; }
    If so, is the package_id showing up in the $_POST variable (you could test it in the on_before_validate method)?
  • edited 2:31AM
    Exactly...Below is my on_before_validate function

    function on_before_validate($values){

    //$values['product_package_id'] = $values['package_id'] ;
    if(isset($values['package_id'] )){
    $values['package_name'] = $values['package_id'] ;

    }
    return $values;
    }

    I had to test with the isset function just to turn off the undefined index error...Still not getting the value

    Thanks for your response!!
  • edited 2:31AM
    Is it coming through in the $_POST at all?
  • edited 2:31AM
    No, I dont think it is else my package_name value would have been updated. So, nothing at all. Am I missing something?
  • edited 2:31AM
    Still no fix here... I created a custom select dropdown field with form_fields function and I still get the same error.. Any idea what might be causing this?
  • edited 2:31AM
    Oh well, I finally got the value through $this->input->post.... any specific reason why I couldnt get it through the values[] array?

    Cheers and big ups to a awesome CMS....
  • edited 2:31AM
    Hmm... that is strange especially if you are able to get it through the $_POST (or $this->input->post). The $values array is essentially the $_POST values filtered down to just those applicable for the table to save. In your case, you had a package_id field so it should have come through. To debug further, I think a look at what gets sent to the MY_Model::save method initially would be a good place to look.
Sign In or Register to comment.