Hi you all.

I've been searching and searching on the forums trying to find how to determine that the hook_alter_form acts according the node type. One example would be limiting that the menu or path or nodewords alter the editing form with their parameters on each and every node type. I thought it would be easy adding at the very beginning of the function something like:

  if ($node->type == 'required_node_type)  {
      return;
  }

which would be skip the hook funtion if the node matches such requirement, but after two days of trying and trying I haven't got any result...

Any idea?

Comments

DriesK’s picture


function hook_form_alter($form_id, &$form) {
  if (isset($form['type'])) {
    if ($form['type']['#value'] == 'required node type') {

for an example application, see http://drupal.org/node/87595

jorditr’s picture

Wow, DriesK, thanks a lot for your fast answer :-)

I observed similar things on some modules but didn't find the proper parameter. Thanks again.

glennnz’s picture

Dries

I can't get this to work. Here is the code for my module:

<?php
// $Id: course_pre_requirements.module,v 0.1

/*******************************************************************************
 * Hook Functions
 ******************************************************************************/
/**
 * Implementation of hook_form_alter().
 */
function course_pre_requirements_form_alter($form_id, &$form) {
  if (isset($form['type'])) {
    if ($form['type']['#value'] == 'rbtpa_course') {
      $form_nid = $form['nid']['#value'];
      switch ($form_id) {
      case 'uc_product_add_to_cart_form_'.$form_nid:
        $form['requirements'] = array(
          '#weight' => '-2',
          '#type' => 'fieldset',
          '#title' => t('<b>Course Pre-entry Requirements: <span class="form-required" title="This field is required.">*</span></b>'),
        );
        $form['requirements']['description'] = array(
          '#type' => 'markup',
          '#value' => 'You must confirm that you have fulfilled all of the course pre-entry requirements by checking the boxes below before you can register on this course.',
        );
        $form['requirements']['requirement1'] = array(
          '#type' => 'checkbox',
          '#title' => 'I have......',
          '#required' => TRUE,
        );
        $form['requirements']['requirement2'] = array(
          '#type' => 'checkbox',
          '#title' => 'I have......',
          '#required' => TRUE,
        );
        $form['requirements']['requirement3'] = array(
          '#type' => 'checkbox',
          '#title' => 'I have......',
          '#required' => TRUE,
        );
        $form['requirements']['requirement4'] = array(
          '#type' => 'checkbox',
          '#title' => 'I have......',
          '#required' => TRUE,
        );
        break;
      }
    }
  }
}
?>

It's not displaying my added fields to the rbtpa_course node type.

Also, how do I validate this to make sure the required checkboxes are ticked?

Thanks

Glenn

Glenn
THECA Group