Hi!

I find the module VERY useful for a website I'm building that allows visitors to contact users for lessons.

The question I have is, is there any way to up the contact form directly into a panel (I'm using Advanced Profile Kit for user profiles)? Any tips on how to do this would be greatly appreciated!

Comments

itserich’s picture

I think I was able to get an anonymous contact form in a View using the Author Contact module (but not sure if that was it).

I am using this module to get anonymous contact into a View.

Good luck!

dasjo’s picture

i just followed http://shellmultimedia.com/articles/creating-content-type-ctools-panels-3 and created a custom ctools content type plugin in order to embed anonymous contact forms for users with panels:

MYMODULE_DIR/MYMODULE.module

/**
* Implementation of hook_ctools_plugin_directory().
*/
function c3mundos_ctools_plugin_directory($module, $plugin) {
  if ($module == 'ctools') {
    return 'plugins/' . $plugin;
  }
}

MYMODULE_DIR/plugins/content_types/anon_contact_pane.inc

/**
* Callback function to supply a list of content types.
*/
function MYMODULE_anon_contact_pane_ctools_content_types() {
  return array(
    'single' => TRUE,
    'title' => t('Anonymous Contact Pane'),
    'icon' => 'icon_user.png',
    'description' => t('Anonymous Contact Pane, required anon_contact module.'),
    'required context' => new ctools_context_required(t('User'), 'user'),
    'category' => t('User'),
    //'defaults' => array('image_path' => '', 'template_file' => 'author-pane'),
  );
}

/**
* Output function for the 'anon contact pane' content type.
*/
// The function name is <code>MODULE_NAME_CT_NAME_content_type_render
function MYMODULE_anon_contact_pane_content_type_render($subtype, $conf, $panel_args, $context) {
  // $context in this case is a user context, so we can get the user object
  // from it and put it into $account.
  $account = isset($context->data) ? drupal_clone($context->data) : NULL;
  
  // Make a new empty "block" which will be a Pane you can add to your Panel.
  $block = new stdClass();
  
  if ($account) {
    // Set the title of the block to the name of the user. It can be overridden
    // through the UI as well.
    $block->title = check_plain($account->name);
    
    $block->content = anonymous_contact_page($account);
  }
  else {
    // If somehow the user context is empty, this is a fallback message but
    // that should never happen.
    $block->content = "User information not available";
  }

  return $block;
}

/**
* Returns an edit form for the custom type.
*/
// The function name is <code>MODULE_NAME_CT_NAME_content_type_edit_form
function MYMODULE_anon_contact_pane_content_type_edit_form(&$form, &$form_state) {
  // The current configuration
  $conf = $form_state['conf'];
}

function MYMODULE_anon_contact_pane_content_type_edit_form_submit(&$form, &$form_state) {
  // For each part of the form defined in the 'defaults' array set when you 
  // defined the content type, copy the value from the form into the array
  // of items to be saved. We don't ever want to use 
  // $form_state['conf'] = $form_state['values'] because values contains 
  // buttons, form id and other items we don't want stored. CTools will handle
  // the actual form submission.
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
    $form_state['conf'][$key] = $form_state['values'][$key];
  }
}

function MYMODULE_anon_contact_pane_content_type_admin_title($subtype, $conf, $context) {
  return t('"@s" anon contact pane', array('@s' => $context->identifier));
}

works :)

maksimova’s picture

You should create in panels new custom content, for example for your profile page (not default):

Contact

full html, check "Use context keywords".

It works great. Thank for modules' author!

maksimova’s picture

sorry. The content is a href="/contact_form/%user:uid"

vcrkid’s picture

The plugin looks really thorough, but I can't even get the module to appear. I'm copy and pasting the content as you've written it and I'm placing the module in the standard module directory. What could I be missing?

Regarding the second option, if I do that, I only get a link to the contact form embedded while I wanted the entire contact form to appear.

vcrkid’s picture

Status: Active » Closed (fixed)

@dasjo - the module you suggested at #2 worked perfectly. This was the first time that I created a module, so after looking at the documentation, I realized I made a noob error of not including a module.info file... whoops!

This code should definitely be added into the main module. This would significantly increase its usability with relatively little work (the code is written... can someone stick it into the module?)

dasjo’s picture

Status: Closed (fixed) » Needs work

vcrkid, you will have to ask the maintainer if s/he wants to include such "third-party module integration code". i am not sure which would be the best way to do this, maybe we would just want to have a separate module for this purpose