I've been trying to embed the private message block and may it more user friendly by having the submission take place in ajax form.

1. Its been possible to embed the private message section into the template pages.
2. Not yet been possible to make it ajax based. Any help/support to get this functionality in place as soon as possible.

<?php
  module_load_include('pages.inc','privatemsg');
  $recipients = array(user_load(arg(1)));
  $subject = 'Again, this is just a default that can be changed';
  print drupal_render(drupal_get_form('privatemsg_new', $recipients, $subject));
?>

My issue is trying to hook the form to make it ajax based.

http://drupal.org/node/624528#comment-6039804

I tried to hook into the form to build it and adjust the submit button as ajax. Its just not working.

function new_note_form($form, &$form_state, $nodeid = NULL) {
          $form_state['build_info']['args'] = array('note');
          $form = drupal_build_form('privatemsg_new', $form_state);

          $form['submit'] = array(
            '#type' => 'button',
            '#value' => 'Submit',
            '#limit_validation_errors' => array(),
            '#ajax' => array(
                'callback' => 'advanced_form_callback',
                'wrapper' => 'status',
            ),
          );

          return $form;
        }

Comments

Berdir’s picture

Category: feature » support
Priority: Critical » Normal
plessas’s picture

This is my approach on making the form ajax-based, so that the page doesn't reload.

I have created a custom module. This module makes use of hook_form_FORM_ID_alter in order to add the ajax property to the form and define the callback function.

function mymodule_form_privatemsg_new_alter(&$form, &$form_state, $form_id) {
	$form['actions']['submit']['#ajax'] = array(
      'callback' => 'mymodule_ajax_callback',
      'wrapper' => 'privatemsg-new',
	  );
}

function mymodule_ajax_callback($form, $form_state) {
  $form['subject']['#value'] = '';
  $form['body']['value']['#value'] = '';
  $form['recipient']['#value'] = '';
  return $form;
}

The same approach can be followed for the reply form. However i am not sure how I could load the new message in the thread list after replying without reloading the page.

Coyote6GraphX’s picture

Issue summary: View changes

Thanks plessas for your answer. Helped me 6 years later. Just an FYI for someone trying to ajax the form in on a separate page, and you are getting an undefined function privatemsg_check_format_accesss() you need to be sure to include the privatemsg.pages.inc on all pages, not just before getting the form. I placed it in the custom module's init function.


function mymodule_init () {
  module_load_include('pages.inc','privatemsg');
}
ivnish’s picture

Status: Active » Closed (outdated)