1

Consider I have 3 content type. The problem is that if I use form alter in a module , when I use:

drupal_set_message(t($form_id), 'status', FALSE);

in the mentioned hook, it shows me different set of form-IDs as message on showing each node add/edit form.

For example if I go to node type A add/edit form, drupal_set_message shows:

A_node_form

if I go to node type B add/edit form, drupal_set_message shows:

A_node_form
B_node_form

if I go to node type C add/edit form, drupal_set_message shows:

A_node_form
B_node_form
C_node_form

Showing them means that I can not really make an specific effect for each content type add/edit form by form_alter.

Note: I use OG module and B and C are the content types and A is the group type.

How should I solve it?

2

In the case you need, so you can easily use control flow in your hook_form_alter

You know that the hook runs everytime a form is willing to be rendered, so you can easily do something like

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

if($form_id == 'A_node_form'){...}//alter form A

if($form_id == 'B_node_form'){...}//alter form B

if($form_id == 'C_node_form'){...}//alter form C

}
| improve this answer | |
  • I edited the title of my question. As I told previously, my system checks almost all forms in each node add/edit form. and I really do not know where is causing this problem! – Ehsan Nov 17 '14 at 15:05
  • Your answer works for normal situations where system only checks a form related to the shown form. – Ehsan Nov 17 '14 at 15:06
  • Ok I understand check the answer again – svelandiag Nov 17 '14 at 15:16
  • Actually, it's a bug belonging to Pages and Panels, whenever I customize the node edit form it happens! – Ehsan Nov 17 '14 at 15:53
  • So in your code, whole conditions will be true for almost all forms, that's my problem! – Ehsan Nov 17 '14 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.