Drupal API

Solution to: Call to undefined function node_form_validate on ajax form submit

If you're running into the JavaScript alert error message on creating an AJAXified node form:

Call to undefined function node_form_validate() ...

... the reason might be that the $form_states array contains wrong information which files to load on form build.

Drupal 7 API: Display Drupal Messages in/after an AJAX call

Sometimes you need a snippet to display the drupal messages (drupal_set_message) created messages after an ajax call as result (for example if a node was created via ajax).

The following snippet removes old messages from the site and appends new messages in the AJAX callback:

  1. function ..._ajax_callback(){
  2.   $commands = array();
  3.   $commands[] = ajax_command_remove('div.messages');

Drupal 7 API: Trigger views AJAX refresh via JavaScript or from PHP using ajax_command_invoke

Drupal 7 views.module allows to refresh ajaxified views
dynamically via a javascript call.

Implementation in JavaScript

The JavaScript call is simple:

  1.   jQuery('.view-id-XXX').trigger('RefreshView');

Implementation in PHP