would there be much involved in making it work with something such as the forward module?

http://drupal.org/project/forward

Comments

iLLin’s picture

What type of integration?

jglynn’s picture

Getting forward module to open it's forward page dialogue in colorbox would be ideal

jglynn’s picture

A simple hack for the forward module (7.x-1.3) is change lines 1538 +1539 to

            'attributes' => array('title' => t('Forward this page to a friend'), 'class' => array('forward-page colorbox-node')),
            'query'      => array('path' => $path,'width'=>'400','height'=>'600'),
chriz001’s picture

Your simple hack works with the latest dev version but not 2.2... (I think)

But how about after submitting the form? I was sent to a page of Ajax data.

iLLin’s picture

Use 2.3, 2.2 was built wrong somehow.

As far as making it ajax, you can do a form alter to do that.

jglynn’s picture

Sorry, I hadn't tried the form submission when I posted that code. It does send the email, but it needs something to redirect it back to the original page, or just close the colorbox and post a "email sent" message. I'm not sure how to do that.

chriz001’s picture

Ive managed to get it working using 2.3 thanks to iLLin's suggestion. :)

I pretty much copied some of the webform specific code and adapted it into a custom module.

i didn't end up changing the forward module, i just used a custom link.

anyway, here is the code:

/*
 * Implements hook_form_alter().
 */
function custom_form_alter(&$form, &$form_state, $form_id) {  
    if ($form_id == 'forward_form') {
      $form['#prefix'] = '<div id="forwardWrapper">';
      $form['#suffix'] = '</div>';
      $form['actions']['submit']['#ajax'] = array(
        'callback' => 'custom_forward_js_submit',
        'wrapper' => 'forwardWrapper',
        'method' => 'replace',
        'effect' => 'fade',
      );
    }
}

/*
 * Javascript submit handler for the forward module
 */
function custom_forward_js_submit($form, &$form_state) {
  // Resize the modal box
  $javascript = '
  <script type="text/javascript">
    (function ($) {
      $(document).ready(function() {
        setTimeout(function() {
          var h = $("#cboxNode").height() + 100;
          var w = $("#forwardWrapper").width();
          $.fn.colorbox.resize({width:w, height:h});
        }, 0);
      });
    })(jQuery);
  </script>';

  // Lets display our confirmation message.
  if (!form_get_errors()) {
    // Return our markup.
    $message = check_plain(t(variable_get('forward_thankyou', 'Thank you for your help in spreading the word about !site.  We appreciate your help.'), array('!site' => variable_get('site_name', 'Drupal'))));
    $markup = array(
      '#type' => 'markup',
      '#markup' => $message . $javascript
    );
    return $markup;
  }
  else {
    // We just pass through our $form
    return $form;
  }
}
iLLin’s picture

Status: Active » Fixed

Good Job! Marking this as fixed.

jglynn’s picture

Nice work, thanks for posting your code.

chriz001’s picture

your welcome :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

carn1x’s picture

Just in case anybody wants something a little more lightweight and doesn't want to hack the forward.module, here's the code that works for me:

(function($) {
  $(document).ready(function(){
    $forward_link_container = $('li.forward_link');
    $forward_link = $('li.forward_link').find('a.forward-page');
    href = $forward_link.attr('href');
    $forward_link.addClass('colorbox-node').attr('href', href + '&width=600&height=600');
    Drupal.attachBehaviors($forward_link_container);
  });
})(jQuery);
carn1x’s picture

In addition, I made a small modification to #7 which uses drupal messages rather than duplicating the thank you message. It has the benefit of automatic styling, as well as showing any send errors that occur even though the form validates.

/**
 * Javascript submit handler for the forward module
 */
function custom_forward_js_submit($form, &$form_state) {
  // Resize the modal box.
  $javascript = '
  <script type="text/javascript">
    (function ($) {
      $(document).ready(function() {
        setTimeout(function() {
          var h = $("#cboxNode").height() + 100;
          var w = $("#forwardWrapper").width();
          $.fn.colorbox.resize({width:w, height:h});
        }, 0);
      });
    })(jQuery);
  </script>';

  // Lets display our confirmation message.
  if (!form_get_errors()) {
    // Return our markup.
    $markup = array(
      '#type' => 'markup',
      '#markup' => theme('status_messages') . $javascript,
    );
    return $markup;
  }
  else {
    // We just pass through our $form
    return $form;
  }
}