Drupal alter shape

I am developing a module that changes the display of node add / edit forms. I am starting to develop a module.

I wrote the following code, it does not work correctly. Please tell me what's wrong with that?

function hook_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'node_form') {    
    drupal_set_message(t('some message.'));
  }  
}

This is for drupal 6.

+3
source share
4 answers

In addition, node add / edit forms have identifiers of a certain type of content. therefore, the history nodes will be:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'story_node_form') {    
    drupal_set_message(t('Editing a story node!'));
  }  
}

If you want to catch every node editing form, regardless of type, try the following:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form') {
    drupal_set_message(t('Editing a node!'));
  }  
}
+19
source

"hook_form_alter", "yourmodule_form_alter". yourmodule , , "", "hello_form_alter".

+3

, Drupal, . - Drupal, hook_something. , , hook, "hook" "modelname". Drupal . Drupal , . , .

+1
source
function hook_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'node_form') {    
     drupal_set_message(t('some message.'));
   }  
}

You must first bind the keyword to the module keyword. suggests that your module name is "contact_us", then

function contact_us_form_alter(&$form, $form_state, $form_id) {

Now this function has three variables

  • $ form
  • $ form_id
  • $ form_state

The most important variable when changing the form is $ form_id, which basically notes which form is the load on the page.

function contact_us_form_alter(&$form, $form_state, $form_id) {
   print_r($form_id);exit; // Used to find the form id
}

after you find form_id

function contact_us_form_alter(&$form, $form_state, $form_id) {
   if($form_id=='contact_us_form')
      // Do your stuff
}

Note: make sure that you have created the user module correctly and enabled it. Also clear the cache

0
source

Source: https://habr.com/ru/post/1711645/


All Articles