I have a webform node inside a modalframe, and i can't manage to have it closed when submitting the it, it just redirects inside the frame.

Here's my set up:
1) I created a webform node

2) in a module, I created a menuitem:

$items['famosos/proponer'] = array(
    'title' => 'Ranking Famosos',
    'page callback' => 'famosos_ranking_proponer_famoso',  
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,  
  );

3) created the function famosos_ranking_proponer_famoso (here i tried two things, loading and embeding the node itself, or directly the form):

function famosos_ranking_proponer_famoso(){	
  modalframe_child_js(); 
  $node = node_load(11446);	 
  return node_view($node, $teaser = FALSE, $page = TRUE, $links = FALSE);;
}

OR

function famosos_ranking_proponer_famoso(){	
  modalframe_child_js(); 
  $node = node_load(11446);	
  $submission = array();
  $enabled = TRUE;
  $preview = FALSE;
  return drupal_get_form('webform_client_form_11446', $node, $submission, $enabled, $preview);
}

4) used the hook_form_alter to add a submit function to the form:

function famosos_ranking_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'webform_client_form_11446') {
  	$form['#submit'][] = 'famosos_ranking_proponer_famoso_submit';
  }
}

5) created the submit function:

function famosos_ranking_proponer_famoso_submit($form, &$form_state) { 
    // Tell the parent window to close the modal frame dialog.
    modalframe_close_dialog(array(
      'message' => t('changos!'),
    ));    
}

6)here i define the link that'll open the modalframe (I created a block with a hook_block and this function renders its content):

function famosos_ranking_propone_famoso(){
modalframe_parent_js();	
  drupal_add_js(drupal_get_path('module', 'famosos_ranking') .'/famosos_ranking.js');	
 return l(t('Proponé un famoso'), 'famosos/proponer', array('attributes'=>array('class'=>'popup')));	
}

7) and finally... here's the content of famosos_ranking.js:

(function ($) {
Drupal.behaviors.famosos_ranking = function() {		
	$('a.popup:not(.modalframe-processed)').addClass('modalframe-processed').click(function() {
		
	   var element = this;  
	   	   
	   // Build modal frame options.
	    var modalOptions = {
	      url: $(element).attr('href'),
	      autoFit: false,
	      width: 500,
	      height: 500
	    };	    
	
	    // Open the modal frame dialog.
	    Drupal.modalFrame.open(modalOptions);	    

	    
	    // Prevent default action of the link click event.
		    return false;    
	});
}

})(jQuery);

Please some advice will be appretiated, I tried this set up with a node edit form and works (it's basically the same as the example form modal_frame_example module) but for some reason it doesn't work with this webform.

regards

Comments

allabouttea’s picture

http://drupal.org/project/modalframe

modalframe_close_dialog($args) - When a form is rendered within a modal frame (what we would call the child window), you can use this function from your form submit handler to close the client-side dialog. You can also give it arguments that will be passed to an optional onSubmit dialog callback that you can provide when opening the modal frame from the parent window.

mikou’s picture

I have the exact same problem. I use modalframe_close_dialog(). It seems to happen before that ! The submit function is not even called (which means that is is not due to ModalFrame issue. So sorry for posting here.)

However, I would like to hear if leanazulyoro found a solution for this.

Scott McCabe’s picture

I ran into this problem for our client's site and am still trying to find a solution.

After the user submits the webform contained in a child window, that window does not close, even though it should based on the documentation for the modalframe module.

I used a form alteration to add my following submit function to the webform:

function mymodule_form_submit($form, &$form_state ) {
  modalframe_close_dialog();
}

That submit function is being triggered (I tested it with a die statement and later using drupal_set_message()), but something is apparently blocking the call to close the child window.

Note that I can use the Firebug console to call Drupal.modalFrame.close(), which successfully closes the child window. I even tried replacing the server-side call in the aforementioned submit handler with the following:

drupal_add_js('Drupal.modalFrame.close();', 'inline');

The execution of that code did nothing to close the child window.

Since the modalframe module works with custom forms, I believe this support request should be changed to a feature request for webform compatibility, noting it could just as well be posted as a feature request for the webform module to be compatible with this nice api (I'll check the webform issue queue, after posting this).

Whatever solution the Drupal community provides, coming up with it should be treated as fairly urgent, considering how likely the use case of having a webform in a child window is, and how advantageous it would be for site builders to be able to do this.

Marko B’s picture

Category: support » bug

Scott, have you found a solution? Is this a bug or what is going on? I also can't close modal frame, using FBSS module to submit but closing the frame doesnt' happen.

dsnopek’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

This sounds like the same problem as described here: #881538: modalframe_close_dialog() does not work on node edit

The solution was putting the submit handler on the actual submit button, rather than the form: $form['buttons']['submit']['#submit'][] = 'MYSUBMIT_CALLBACK';