How can I get an edit form to appear as a popup when a user clicks on a link created by views?

Comments

gabrielo’s picture

Same question

Leoo’s picture

Hello, managed to do it adding a nid attribute and tweaking (for the time being) _popup_form function in popup.api.inc:

function _popup_form($attributes, $return = FALSE){
  module_load_include('inc', 'node', 'node.pages');
  $title = $attributes['title'] ?  $attributes['title'] : 'form';
  if ($return == 'title'){
    return $title;
  }
  $node=node_load($attributes['nid']);
  $form=drupal_get_form($attributes['form'],$node);
  $body = drupal_render($form);

  if ($attributes['ajax']){
    $body = '<div class="ajax-form-wrapper">' . $body . '</div>';
  }

  if ($return == 'body'){
    return $body;
  }

  return
    popup_element(
      $title,
      $body,
      $attributes
    );

}

The problem then is how to override the submit button on the node edit form, to work with AJAX. I tried the below to stop the redirect, unfortunately it still redirects the page on which the popup is open to the node edit page..
L

function popup_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'tags_node_form':
        $form['#submit'][]='_popup_change_submit';
        //debug($form, $form_id, TRUE);
      break;
  }
  return;
}

function _popup_change_submit($form, &$form_state) {
  $form_state['no_redirect']=true;
}
Scheepers de Bruin’s picture

That is a cool idea for a feature... I'll look into it, thanks!

Leoo’s picture

For the popup link integration in Views see http://drupal.org/node/1760306
L

Leoo’s picture

Got it to work locally, even if I dont know how to save the node changes using AJAX (For the time being, when I save, the page refreshes).
To get the save button to work in production, I had to comment the action attribute override in popup.js
l 68: // thisForm.attr('action', '');

Leoo’s picture

Still on this issue. For the time being, there are two things i cannot manage to do: after opening an edit form under popup AJAX format:
* I cannot find a way when I press 'submit' to close the popup using AJAX: right now I close my popup window and reload the entire page.
* Moreover, I have problems using AJAX-based options on my form opened by AJAXified Popup. As an example, i want to use the nice Autocomplete Deluxe module (http://drupal.org/project/autocomplete_deluxe) to fill Select/Autocomplete lists. This works on a node edit, but if I open the node edit form using Popup, I can not see anymore the Select/Autocomplete options for my field edited.
Any tip on how to manage to integrate AJAX-based options on forms loaded using AJAXified popup?
Thanks,
L

Leoo’s picture

Priority: Normal » Major
vb_swapnil’s picture

I create a View and I want to show webform block as a popup after clicking on email which i display in table
Please check this url http://shunyatec.com/demo/excitor/resellers

ishwar’s picture

Issue summary: View changes
Scheepers de Bruin’s picture

Ok SO it's best to do a form like this:

  module_load_include('inc', 'popup', 'includes/popup.api');
  module_load_include('inc', 'node', 'node.pages');

  print popup_element(
    'My Title',
    drupal_render(node_add('feedback')),
    array() // Attributes
  );
Scheepers de Bruin’s picture

This works better:

  module_load_include('inc', 'popup', 'includes/popup.api');
  module_load_include('inc', 'node', 'node.pages');

  global $user;
  $node = (object) array(
    'uid' => $user->uid,
    'name' => (isset($user->name) ? $user->name : ''),
    'type' => 'feedback',
    'language' => LANGUAGE_NONE,
  );
  $form = drupal_get_form('feedback_node_form', $node);

  return popup_element(
    'Feedback',
    drupal_render($form),
    array(
      'activate' => 'click',
    )
  );
flyingyoda51’s picture

I am trying to display a link to add, edit and delete a node each in a popup. I can't figure out what to do.

Scheepers de Bruin’s picture

You could try:

  print popup_element(
    'Links',
    '<ul><li>' . imlode('</li><li>', 
      array(
        l('node/' . $node->nid . '/edit', 'edit'),
        // more links
      )
    ) . '</li></ul>',
    array(
      'activate' => 'click',
    )
  );
srikanth.g’s picture

View with edit link and Lightbox module is working for me in Frontend theme.