phpjoomlauploadjoomla3.0jform

Joomla 3.0 Component - Adding field input to JForm using JInput


I've added a field in my admin view to upload a file. The upload part is working fine but the form doesn't add the file's name to the database on saving. I've seen a similar problem here on stack overflow that has been answered but they are using JRequest::setVar which is now deprecated: How to Save Uploaded File's Name on Database

I need to add to the "jform" array but when I use: $jinput->set('jform',array('foo' => 'bar')); it overwrites the existing 'jform' array that contains the other data entered in the form:

JInput Object (
    [data:protected] => Array (
        [jform] => Array (
            [foo] => bar
            ...

Does anyone have any advice on how to add to the jform array and not overwrite it?


Solution

  • Ok so I feel a little foolish - I've solved my own question!

    What I did was to get all the other jform data with: $jinput->get('jform', NULL, NULL); and then used array_merge to add the other array.

    I then used: $jinput->post->set('jform',$mergedArray); to put the array back into the POST.

    Hope this helps someone