Add / Change arguments in a view programmatically (Drupal 6)


function hook_views_pre_view(&$view, &$display_id, &$args) {
    if ($view->name == 'your_view_name') {
         $view->set_arguments(array(arg1,arg2,arg3));
    }
}
Advertisements

Creating a custom form from a module in Drupal 6


Permissions

This will check if the user has permissions to view the form

function myform_perm() {
  return array('access myform content');
}

Path

What url will lead us to the form, useful to start it with ‘admin’ so non-admin users can’t access it.

function myform_menu() {
  $items = array();
  $items['path/to/my/form'] = array(
    'title' => t('My Form'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('myform_form'),
    'access arguments' => array('access myform content'),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

Form

function myform_form() {
  $form['message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send')
  );
  return $form;
}

 Validation

function myForm_validate($node, &$form) {
  if (isset($node->end) && isset($node->start)) {
    if ($node->start > $node->end) {
      form_set_error('time', t('An event may not end before it starts.'));
    }
  }
}