By i-sultan on
Hello, 2 days I have been developing module and a function within, which provides processing operations for this form
function lingvist_add_words($prefix, $code = 0) {
$my_base = drupal_get_path('module', 'codelist');
$msg = '';
if ($code == 0) {
return drupal_set_message('Incorrect request, please provide valid data.');
}
// form processing
if (isset($_POST['code']) && is_numeric($_POST['code'])) {
//... ...
//... ...
//... ...
$code = check_plain($_POST['code']);
$result = db_query("SELECT MAX(`code_id`) AS `id` FROM `codes` WHERE `code`=%d LIMIT 1", $code);
$last_code_id = db_fetch_array($result);
$msg .= $last_code_id['id'];
//... ...
//... ...
//... ...
}
// HERE I GOT NOTHING in $msg
//...
//...
//...
}
and drupal fires warning like
warning: mb_strlen() expects parameter 1 to be string, array given in /home/drupal/www/includes/unicode.inc on line 405.
I guess this is a little bug. Does anyone knows how to tackle this problem?
Thanks in advance
With best,
Sultan
Comments
My guess would be this linte
My guess would be this linte : $code = check_plain($_POST['code']);
Double check the value for $_POST['code'] and make sure it's not an array.
cheers
I think that cannot be the
I think that cannot be the problem, because the check_plain is inside a
if (isset($_POST['code']) && is_numeric($_POST['code'])). (can you http POST an array anyway?)Line 405 of unicode.inc is the drupal_strlen() function (http://api.drupal.org/api/function/drupal_strlen/6). However I don't see where your code would call this function directly or indirectly. Can you paste the complete code, and maybe do a backtrace?
Code
This is the full code of function
code at unicode.inc line 405
and var_dump($_POST['code']) says
THANKS
Big thanks to You guys :) I have solved this problem, article closed :)
With best,
please share
I'm glad you solved it. Can you tell us what the problem/solution was? That way you share your knowledge with the community. Thanks.
Solution
My function function lingvist_add_words as You could see call drupal_get_form function to get my form rendered. And by the way this function tries to handle form submission itself, here was the main problem because I had to separate form handler function from function which generates this form and never the less I traced all of the POST variables for an array type but I still can not localize what sometime really happens because of code
works properly and
$_POST['code']is not a array type, also I have been digging this problems alongside with my usual work schedule :)In that case I think you
In that case I think you should look a little better at the Form API. The FAPI allows you to define your own submit handler and submission validators. Start reading here: http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6.