Revert drupal settings so the new export in code is used

  db_query('TRUNCATE {ds_field_settings}');
  db_query('TRUNCATE {ds_layout_settings}');
  db_query('TRUNCATE {ds_vd}');
  db_query('TRUNCATE {ds_view_modes}');
  db_query('TRUNCATE {field_group}');
  db_query('TRUNCATE {views_view}');
  db_query('TRUNCATE {views_display}');
  // Add whatever you want, E.g. Panels, ctools objects ... 

  return t('All tables are truncated. Default exports will now be used.');

Small toggler in javascript

function toggleHelp(element) {
  $(element).toggleClass('close');
  toggleNice($(element).parents('.helptekst').find('.helptekst_inner'), $(element).hasClass('close'));
  return false;
}

/**
 * Change this to jQuery.fn
 */
function toggleNice(element, close) {
  if (!close) {
    element.slideUp('normal');
  }
  else {
    element.slideDown('normal');
  } 
}

Easy search form functionality in drupal

  $form['search_to'] = array (
    '#type' => 'textfield',
    '#weight' => 2,
    '#size' => 17,
    '#default_value' => t('Looking for ... ?'),
    '#attributes' => array(
      'class' => 'search-in-field',
      'onclick' => 'javascript: $(this).val(\'\').addClass(\'search-in-field-active\').removeAttr(\'onclick\'); return false;'
    ),
  );

search-in-field has light color, where the search-in-field-active overrides this color

Drupal node devel module does not create nodes correctly

Devel module for Drupal has a generator for nodes, users and taxonomy. I just stared half an hour at a users list that gave not enough results. What is the problem?
Well, generated nodes creates nodes and its revision. Doing so, he assigns authors for the existing users to his node creations. Except, in node revisions table, he always uses uid 1.
So be aware when using this devel feature!

How to trigger tinyMCe on multiple textarea's in a form in Drupal 6

On drupals administer pages, like a system settings form or a custom form, you can add a format on a per field base so tinyMCe editor will be triggered. Usually we can use

$form['form'] = filter_form(2);

But what if you have multiple textarea fields on one page? In this case we need a reference for the format, so that drupal Fapi knows which format needs to be triggered for which field. This is done by adding the parents for the desired field on the filter_form function.

$form['fieldname']['fieldname'] = filter_form(2, NULL, 'fieldname_format');

The tricky part is that you do need to use a parent for your field with the same fieldname as you would normally do. So

$form['fieldname'] = array( ...);// becomes$form['fieldname']['fieldname'] = array( ...);

For a more detailed explanation and a couple of examples, visit http://drupal.org/node/358316.

 

Implement your own form_alter with a custom callback

Sometimes it can be handy to have a generic way to handle types of forms.  Altering fields could be done by hook_form_alter but this could lead to messy code.

/**
 * Implementation of callback_configuration().
*/
function news_configuration() { 
$form_id = 'node_type_form';  module_load_include('inc', 'node', 'content_types');
  $type = node_get_types('type', 'news');
  $alter = array('site_conf_alter' => array(0 => 'news_rating'));
  return drupal_get_form($form_id, $type, $alter);
}



/**
 * Implementation of callback_form_alter().
 */
function news_configuration_form_alter(&$form) {
  foreach (element_children($form) as $key) {
    if ($key != 'form_id' && $key != 'form_token' && $key != 'form_build_id' && $key != 'delete')
    $form[$key]['#access'] = FALSE;
  }
  $form['fivestar']['#access'] = TRUE;
  $form['fivestar']['#collapsible'] = FALSE;
  $form['submit']['#access'] = TRUE;
  $form['#submit'][] = 'news_configuration_submit';
}


How to post disabled fields correctly

In general, disabled fields are not submitted or submitted with an empty value. In drupal, we can use the form attributes or the property disabled. See http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/6 for forms_api reference guide.
Examples :

$form['fieldname']['#disabled'] = TRUE;
$form['fieldname']['attributes'] = array('disabled' => TRUE);

This will leave us with $fieldname = 0 which is incorrect.  The hack here is to use the #value property to set the value that was already known (in form state for instance). The #value property overrules the #default_value property at all times and makes sure you always post the correct values, even when some fields are disabled.