1

I'm writing an accessory to replace the category image field with a file browser that enables the user to navigate through folders to select their image (because the native category image field is restricted to a single upload directory).

Everything is nearly OK on the front end except that I'm getting

Severity: Warning
Message: Illegal string offset 'value'
Filename: cp/admin_content.php
Line Number: 2223

when submitting the form and looking in the database, the value is d.

When using the native category image field, after choosing an existing image from the file manager, the updated HTML looks like:

<input type="hidden" name="cat_image_hidden" value="file_name.jpg">
<input type="hidden" name="cat_image_hidden_dir" value="1">

and that's what the HTML looks like too after I update using my method so I don't understand what's going on.

The code for my accessory looks like:

$this->EE->cp->add_to_head('
    <script src="/themes/third_party/category_image_file_browser/js/jquery.easing.min.js"></script>
    <script src="/themes/third_party/category_image_file_browser/js/jqueryFileTree.js"></script>
    <link rel="stylesheet" href="/themes/third_party/category_image_file_browser/css/jqueryFileTree.css">

    <script>
        $(document).ready( function() {

            function copy_file_path(file) {
                var newpath = file.replace("../images/", "");
                $("[name=cat_image_hidden]").val(newpath);
            }

            $("[name=cat_image_hidden_dir]").val("1");
            $(".category_field .no_file select,.category_field .modifiers.js_show p,.category_field .file_set.js_hide .filename,.category_field .file_set.js_hide .sub_filename").hide();
            $(".category_field .file_set.js_hide").show();
            $(".category_field .modifiers.js_show").fileTree({ root: "../images/", script: "/themes/third_party/category_image_file_browser/connectors/jqueryFileTree.php" }, function(file) {
                copy_file_path(file);
            });
        });
    </script>
');

I've looked through the HTML and don't see any other form inputs I should be updating, but I've obviously missed something.

Anyone know what that is?

For reference, I'm using http://www.abeautifulsite.net/blog/2008/03/jquery-file-tree/ for the file browser. This part, selecting the value, all works fine; it's only saving to EE that I'm having trouble with.

1

This error message appears to be something added with PHP 5.4, to indicate when array values aren't filled in.

It may be that you already understand that, from what you've said, but if not, looking through comments and answers here may illuminate and offer tips:

https://stackoverflow.com/questions/9869150/illegal-string-offset-warning-php

Now, how to find out what's missing? The best way to do it may be on your browser, rather than in PHP, especially as you've manipulated with JQuery.

I'm using Firebug on Firefox, and I can see what fields there are by inspecting the appropriate area of the screen. Then I can see the value of each by clicking on that tag and using the DOM listing on the right to discover the value in it.

I think that should show you what's empty in what becomes the returned fields array in EE, and let you solve the problem.

Be sure to write your answer and accept when you do find it, so that this question clears on EESE. As I think it will be you who actually locates the fault.

edit: whoops, I intended this to be a comment, rather than answer. But see if it gets you there anyway. CNS

3
  • I've already been using Chrome's Inspector and can see that the inputs I think are involved are being populated with data correctly. I've been all up and down the DOM of the form that controls updating the category and can't see any other form inputs involved but there must be something that I'm missing.
    – Tyssen
    Apr 29 '13 at 10:14
  • Well, I guess rather than guessing in the dark on a thing like this, putting a debugger on EE would be the next step, so you can see what's in the environment where you get the fail. Aptana works well with the usual Xdebug dll enabled on your server php. Good fortune -- as you know it's always a simple thing when you find it (mostly). Apr 29 '13 at 18:35
  • p.s. one thing that keeps bothering me is that your jquery modification looks set to run on page load. It seems it should be a function to run after the file browser closes. Perhaps the browser close causes page reload, solving this. Also, since your problem occurs on submitting, and you are anyway manually checking field values that you know about, this shouldn't be the root of it. Apr 29 '13 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.