By ooXei1sh on
I have a form module with two block views. Both use the same form fields and I would like to use the same javascript. So i need all the ids to be the same no matter what.
But, Drupal is changing form element id attributes, adding two dashes and a number like 'myform--2' instead of just 'myform'. Is there a way to ensure that all forms (and elements) will have the same id attributes for any blocks I add to my module?
Below is the block info and block view code.
/**
* Implements hook_block_info().
*/
function myform_block_info() {
$blocks['myform'] = array(
'info' => t('Form side bar'),
'cache' => DRUPAL_CACHE_GLOBAL,
);
$blocks['myform-fullpage'] = array(
'info' => t('Form full page'),
'cache' => DRUPAL_CACHE_GLOBAL,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function myform_block_view($delta='') {
$block = array();
switch ($delta) {
case 'myform':
$block['subject'] = t('Contact Us Today');
$block['content'] = drupal_get_form('myform');
break;
case 'myform-fullpage':
$block['content'] = drupal_get_form('myform');
break;
}
return $block;
}
Comments
If there are two forms with
If there are two forms with same name/id, drupal changes the id of one of the forms. Because, if you have two same id's in the same page, then the definition of id doesn't hold.
you can add some class to the form use it in your script.
Regards
Chakrapani
that makes sense
Thank you for responding. I'll try that out.