By TuTToWeB on
Hi everyone,
i'm coding a drupal module, in particular a callback function for drupal_get_form.
This function is coded like that:
function dipendenze_royalty($form,$id)
{
$query = db_query ("SELECT `a`.`name` AS `subagente`, `b`.`name` AS `superagente`
FROM `{users}` AS `a`, `{users}` AS `b`
WHERE `a`.`uid` = %d AND
`b`.`uid` = (SELECT `uid` FROM `{dipendenze}` WHERE `have` = %d)",$id,$id);
$obj = db_fetch_object($query);
$form['fields'] = array(
'#type' => 'fieldset',
'#title' => sprintf('Applica royalty a %s, subagente di <b>%s</b>',$obj->subagente,$obj->superagente)
);
$form['fields']['royalty'] = array (
'#title' => 'Royalty',
'#type' => 'textfield',
'#size' => 4,
'#default_value' => "2,00",
'#required' => true
);
$form['fields']['id'] = array (
'#type' => 'hidden',
'#value' => $id
);
$form['fields']['sumbit'] = array (
'#type' => 'submit',
'#value' => t('Assegna royalty'),
'#submit' => array('dipendenze_royalty_submit'),
'#validate' => array('dipendenze_royalty_validate')
);
return $form;
}
I cant see any imperfection. Form is rendered well, but when i click on submit, php returns me: Fatal error: Cannot use string offset as an array in /var/www/drupal/includes/form.inc on line 973
I wasted 1 hour to understand the problem, but i didn't find anything yet.
Can you help me to understand where i'm making a mistake?
thank you very much
Comments
You need to...
If you are working in Drupal 6 you need to fix your function. It is expecting the $form_state array as a parameter and you are passing it $form and $id. It looks like you are using $id as a parameter in your function so I assume you ment to use $form_state instead of $form. change that and you should be ok.
FYI. $form is passing as a string when it is expecting an array and that is where that message is coming from
Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist
Just curious
I am thinking after reading your post again though that the problem may be in your submit function though. Do you have that? I image that it may be a similar problem as to what I was originally thinking though. But seeing your submit or validate functions if you have them would be helpful as you said it renders but breaks when you submit it.
Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist
ok... i edited the function,
ok...
i edited the function, erasing arguments. Now its signature is: function dipendenze_royalty().
Why arguments make drupal crash?
Check out the Forms Quickstart guide
http://api.drupal.org/api/file/developer/topics/forms_api.html/6
Read that and it will help you get your from working. The reason it isn't working is that you are passing it incorrect arguments
Here is what it should look like
Adam A. Gregory
_____________________________
Web Manger - Marketing Ministries
http://marketingministries.com
Founder - The Open Source Church
http://theopensourcechurch.org
Blogger - AdamAGregory.com
http://adamagregory.com
Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist
Similar issue: #801970: ( ! )
Similar issue: #801970: Fatal error: Cannot use string offset as an array in includes/form.inc on line 986