0

This is the code I used on the node template and block, I just tried it both

module_load_include('pages.inc','privatemsg');

$recipients = array(user_load(arg(1)));

$subject = 'This is just a default that can be changed';

$body = 'Again, this is just a default that can be changed';

print drupal_render(drupal_get_form('privatemsg_new', $recipients, $subject, $body));

The Bold ones are the codes I added from the orginal code I got from here: https://www.drupal.org/node/624528

But I'm getting this message when I added the $body:

You can not reply to this conversation because all recipients are blocked.

I've looked into the parameter of privatemsg and it says that the $body is the body text of the new message.

I would like to put some default body message on the embedded privatemsg.

I tried to edit the body via custom module, still no luck for me. I'm not sure where I went wrong.. here's the code on the custom module

function sassy_hook_form_privatemsg_new_alter(&$form, &$form_state, $form_id) {
   $form['privatemsg_new']['body'] = array(             
    '#type' => 'textarea',      
    '#title' => t('Message'),       
    '#rows' => 6,       
    '#weight' => 0,         
    '#default_value' =>  t('Message'),      
    '#resizable' => TRUE,   );   
} 

I also tried $form_state['values']['body'] = 'Hello World';

Is there any way to do this?

What am I missing?

0

Have a look at the descriptor of the privatemsg_new function in privatemsg.pages.inc:

privatemsg_new($form, &$form_state, $recipients = '', $subject = '')

It doesn't take a $body argument so you will need to alter the form once it has been created.

  1. Make a custom module
  2. Use hook_form_FORM_ID_alter
  3. Set $form_state['values']['body'] to your desired value
  • Hi, thanks for your answer. Is it possible to use that code on a block or node.tpl.php only? I'm trying to avoid creating a module because I'm still basic at drupal. – Danz Dec 16 '14 at 9:42
  • No it is not possible, because the function you are trying to use won't let you add a $body to it. Sorry. – Darvanen Dec 16 '14 at 22:18
  • Okay, thank you. I'll try to make it work with a custom module. :) – Danz Dec 17 '14 at 2:44
  • Hi @Darvanen, I tried to edit the body, still no luck for me. I'm not sure where I went wrong.. here's the code on the custom module function sassy_hook_form_privatemsg_new_alter(&$form, &$form_state, $form_id) { $form['privatemsg_new']['body'] = array( '#type' => 'textarea', '#title' => t('Message'), '#rows' => 6, '#weight' => 0, '#default_value' => t('Message'), '#resizable' => TRUE, ); } I also tried $form_state['values']['body'] = 'Hello World'; – Danz Dec 17 '14 at 9:15
  • Best to adjust your question, a bit hard to read here. – Darvanen Dec 17 '14 at 13:33
0

Nice attempt with the module, but you have a bit more to learn about hooks.

  1. Your module name should replace the word 'hook' in the function name (case sensitive).
  2. Make sure you turn on the module and clear caches before testing so that Drupal knows the hook is there.

You might find that $form['privatemsg_new']['body'] is the wrong place to be putting your new item, but once the hook registers you'll be able to play around with it until you get it right.

  • Awesome! thanks for guiding me! I'll try it again. :) – Danz Dec 18 '14 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.