Drupal : Three simple steps to adding ajax to your drupal forms/pages

If you need a simple content refresh system, let me show you an example of a simple (yet powerful) implementation.

Step 1
Download a the lightweight ajax library from ImpliedByDesign, and copy it to a directory called “ajax” in your module directory.

Step 2
Add the following two functions to your drupal module

function printAjaxJs() {
   drupal_add_js(drupal_get_path('module', 'myModule').'/ajax/ajax.js');
}
function printAjaxFunction($function,$page) {
  $output.='function '.$function.'(div_id,content_id) {';
  $output.='subject_id = div_id;';
  $output.='content = document.getElementById(content_id).value;';
  $output.='http.open("GET", "'.$page.'" + content, true);';
  $output.='http.onreadystatechange = handleHttpResponse;';
  $output.='http.send(null);';  $output.='}';
  drupal_add_js($output,'inline');
}   

Step 3
Ajaxfy your forms/pages

  printAjaxJs();
  $function="showContent";
  printAjaxFunction($function,"/show/content/");
  $script=$function."('updated-field','edit-myselect')";
  $form['myForm']['mySelect'] = array(
  '#type' => 'select',
  '#title' => t('Formation Select'),
  '#default_value' => $fdefault,
  '#options' => $foptions,
  '#prefix' => '
', '#suffix' => '
The output of /show/content/*value* will be updated here.
', );

Setting up “auto-update” on your system thru command line

Below you can find a ‘howto’ on setting up an automated update system for your ubuntu system. In essence we’ll be setting up the whole aptitude mechanism thru cron.

WARNING : This may cause unexpected results due to unknown updates.

Open up the crontab as root

kvaes@ubuntu:~$ sudo crontab -e

Add the following line to your crontab

0 0 * * * aptitude -y update && aptitude -y upgrade && aptitude -y dist-upgrade && aptitude -y autoclean

Sidenote: If you prefer the gui, check the following article. It won’t do exactly the same, but it might give you a better feeling… 😉

Resetting permissions for drupal

For some odd reason, after testing out some modules I was given an access denied on all content for non-admin users. If you would get such a thing, and are at the end of the road with your options, try the following commands:

INSERT INTO users (uid, name, mail) VALUES (‘0’, ”, ”);
INSERT INTO users_roles (uid, rid) VALUES (0, 1);
INSERT INTO node_access VALUES (0, 0, ‘all’, 1, 0, 0);

It will either return ‘duplicate entry’ warning (ignore this) or -maybe- fix your problem…

OWA Most Popular – version 0.5

This version contains a bugfix and the new “PostOnly”-feature. By selecting this feature, you won’t be pestered by non-posts in your listing. Examples here are the “Flavicon” & the “Homepage”.

Have fun with the release. Suggestions are always welcome!

IT Departments, dare to innovate!

Scenery
Wich companies come to mind if you would be presented with the following question:

What’s the difference between the new companies that stand out, and those who just populate the economic landscape as scenery?

Let’s take the “almighty google”. It started out as an idea of two Stanford University students. Its corporate philosophy includes statements such as “Don’t be evil”, and “Work should be challenging and the challenge should be fun”. I guess that isn’t something you see in every company. The competition for competence is fiercely high in Silicon Valley, and yet they win a lot of brainpower due to their company mentality. Note that I don’t want to sell google as heaven on earth, but I just want to sketch a certain starting point.

The human factor Continue reading “IT Departments, dare to innovate!”