开发者

wrong form_later() hook behaviour?

i'm using Drupal 6.19 , in order to do some changes to the forms i followed some tutorials on the web using the form_alter hook . well identifying the form consist of testing $form_id (that work开发者_JAVA技巧ed fine) ,but adding new fields is done by manipulating the $form variable . when i tried this on my code it didn't work ,so i tried to manipulate the $form_id variable instead and it worked ! i know that my problem is solved but i want to know what the difference between $form_id and $form ? isn't $form_id suppose to store only the form identifier ? and the form content goes into $form ?


Since you're using Drupal 6 , you are using the wrong syntax for the hook_form_alter. What you have is the Drupal 5 syntax for the hook. This is what it should be...

hook_form_alter(&$form, &$form_state, $form_id)

Because you're using it the way you are, the $form_id variable IS actually the $form variable. Try swapping out to the correct one, and that'll help you out.

Here's a link to the documentation: Drupal API: hook_form_alter


ok, here is my code for the form_alter hook : btw, i use dBug to view the content of variables (that's how i figured out that $form does'nt contain the form structure)

function testymodule_form_alter($form_id, &$form)  {
include_once("dBug.php");

if ($form_id['#id']=='node-form') {
  $form_id['testymodule_checkbox'] = array(
'#type' => 'checkbox',
'#title' => t('Newly testy Checkbox'),
);
  new dBug($form_id); 
}

this will add a new checkbox to the mentioned form (although it maniuplate $form_id not $form)

what i found on the net was manipulating $form :

function testymodule_form_alter($form_id, &$form)  {
include_once("dBug.php");

if ($form_id['#id']=='node-form') {
  $form['testymodule_checkbox'] = array( //here is the clue
'#type' => 'checkbox',
'#title' => t('Newly testy Checkbox'),
);
  new dBug($form_id); 
}

it's weird nan ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜