Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.2k views
in Q2A Core by
edited by

qa-base.php has a line that throws a warning if a $_POST entry is an array:

            foreach ($_POST as $key => $value)
                $_POST[$key]=stripslashes($value);

This doesn't work for a <select> field that has the "multiple" attribute and a name ending in [], e.g.:

<select name="myselect[]" multiple>

since this passes the post variable as an array:

stripslashes() expects parameter 1 to be string, array given in /var/www/q2a/qa-include/qa-base.php on line 158

Any solution?

EDIT: okay, I found one workaround, also realized it is only a problem for wordpress integration, since the above line is trying to change some wordpress behaviour.  The workaround is to add the folowing to my qa-config.php file:

    foreach($_POST as $i => $p)
        if(is_array($p))
            $_POST[$i] = implode(',',$p);

 
and then re-explode the string later.  Unfortunately, that doesn't help when creating a plugin...

Q2A version: 1.5
by
That's odd, since stripslashes should only be called if magic_quotes is detected, otherwise you're removing too much. Incidentally, magic_quotes is no longer in the latest version of PHP.

Let's just try \" and \'
EDIT: well it didn't strip the slashes I put on those quotes...
by
no, the problem is that the select value is being passed as array to $_POST, and you can't perform stripslashes on an array...
by
I understood that. I was just wondering why it calls stripslashes in the first place anyway...
by
The comment says:

             // Undo WordPress's addition of magic quotes to various things (leave $_COOKIE as is since WP code might need that)

1 Answer

+1 vote
by
selected by
 
Best answer
Thanks for this. I'll try to fix it for Q2A 1.5.1. You're right that plugins can't do much about this, since it all happens before they are loaded.
...