By Someone4 on
Hi,
I create a form with Drupal API. The form print good, but I receive this error :
Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen() (line 441 of C:\wamp\www\drupal-7.8\includes\unicode.inc).
I think, this error come from the name of this input :
$form['channel_'.$i]['proportion'] = array('#title' => '','#type' => 'textfield','#size' => 10,'#id' => 'prop_'.$i ,'#name' => 'proportion[channel_'.$i.']');
The name 'proportion[channel_'.$i.']', looks like an array for Drupal. But I need it for my *_submit() function. Someone has an idea ? And can help me ? Thanks.
Comments
Hi, you can not use attribute
Hi,
you can not use attribute '#name' for 'textfield' element.
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....
Thanks for your response. How
Thanks for your response.
How can I recover informations of my formulaire ? I used the '#name' attribute, because I thought that the _submit() methode use the name of the textfield to bring informations back.
My _submit() methode looks like that :
So, I recover informations of my textfield, like that : $form_state['values']['proportion'][$key] (the key value is 'channel_1', 'channel_2',... )
My textfield :
I haven't found an other way to bring informations back. I thought that $form_state use the name of the element. I am wrong ?
Seeing as you haven't showed
Seeing as you haven't showed us any code with mb_strlen() in it, it's hard to tell you what is going wrong.
Contact me to contract me for D7 -> D10/11 migrations.
Yes, the $form_state use the
Yes, the $form_state use the name of the element.
in your form, the name of element is 'proportion' and not 'channel_1', channel_2....
I show you my form :<?php/***
I show you my form :
I construct my form in a foreach, for every channels I have 'name', 'proportion', 'commission', 'monthly cost',... elements. I name these elements like that : $form['channel_'.$i]['name'], the channel id and next the element.
Finally in the _submit method, I can't just display the proportion with : $form_state['values']['proportion'],
I use : $form_state['values']['proportion'][$key]; (and this method works, values are found, but I have the error)
Do you understand better why the name of my element must be 'proportion[channel_1]', rather than only 'proportion'? If it's only 'proportion', I can't bring back differents proportions for different channels.
Your comment about the #name attribute, is right. But if I can't modify the name of the element, I don't know how recover informations... Because all proportion elements will have the same name 'proportion'
I show you what my form looks like :
http://data.imagup.com/10/1134827538.jpg
Thanks.
Ok.... I fix it. I use the
Ok.... I fix it.
I use the '#name' attribute for an other element and I didn't note it... when I tried to change code, the error persisted...
I use this method for naming textfield element : $form['channel_'.$i]['proportion_'.$id]. I differentiate proportion element with the $id.