Closed (fixed)
Project:
Modal Frame API
Version:
6.x-1.6
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
11 May 2010 at 19:47 UTC
Updated:
26 May 2010 at 00:10 UTC
Hey,
I have a modal frame module implementation, and on my submit handler I have two options - one to reload the page, the other to redirect to an arbitrary page. Everything works well, however, I'd like the arbitrary page to redirect to the submitted node, and I'm trying to pass that into the javascript file.
Here is my javascript code:
$('a.automodal:not(.modal-processed)', context).addClass('modal-processed').click(function() {
function onSubmitCallback(args, statusMessages) {
if(args && args.reload){
setTimeout(function() { window.location.reload(01); }, 01);
}
if(args && args.redirect){
window.location = "URL of Submitted Node"
}
}
// Build modal frame options.
var modalOptions = {
url: $(this).attr('href'),
autoResize: true,
autoFit: true,
width: 600,
height: 400,
onSubmit: onSubmitCallback
};
// Open the modal frame dialog.
Drupal.modalFrame.open(modalOptions);
return false;
});
I use either one of two submit handlers, one reloads the page, the other redirects the page.
My question is this:
How do I get the node id to pass into JS where it says "URL of Submitted Node"?
Here is my submit handler:
function modalframeTool_form_submit_redirect($form, &$form_state){
// Ignore preview requests. Close dialog only when user clicks "Save" button.
if ($form_state['values']['op'] == t('Save')) {
modalframe_close_dialog(array('redirect' => TRUE));
}
}
I just need to be able to pass the url to the JS so it properly redirects. Any ideas?
Thanks!
Comments
Comment #1
rc2020 commentedI made a bit of progress by being able to pass variables form the submit handler directly to the js, but I still can't get the nid set. Here's what I got:
JS:
Submit handler:
I'm so close. I just need the NID of the submitted node to pass and I'm golden. Please chime in with ideas if you have them!
Thanks!
?>
Comment #2
markus_petrux commentedIf this is a node edit/create form, try looking at
$form_state['nid'].See an example in Node Relationships module, file
noderelationships.pages.inc, function_noderelationships_child_node_form_submit().Comment #3
rc2020 commentedHey Markus,
Thanks for getting back to me. I commented out modalframe_close_dialog() and using devel's dsm function I passed
dsm($form_state);There is no $form_state['nid']. However, there is a $form_state['values']['nid'] but it's a NULL value - although all CCK values have the info in them. I guess the CCK value is processed before the node is saved to the DB.
Any thoughts?
I'll try out node relationships but that I think that requires me to use a node reference field in order for it to work.
Comment #4
markus_petrux commentedYour submit handler is attached to ... ?
Have you tried like this?
Comment #5
rc2020 commentedHey Markus,
My submit handler is attached to the node via form_alter()
My submit handler is as such:
As explained in commented line above I am under the impression that hook_nodeapi can help me here, but I need to implement it in a way that gives me access to the created node object on insert so I can extract the NID and pass it into the string for $path for the modalframe_close_dailog arguments. This doesen't seem to be happening at all - and I don't know why.
Any thoughts?
Comment #6
markus_petrux commentedHave you tried attaching your submit handler as in second question in #4?
Comment #7
rc2020 commentedIt works! Ha!
Thanks so much dude! I had no idea putting it within buttons would make it work like that but it does!!!!
THANK YOU SO MUCH!
Comment #8
markus_petrux commentedYeah, the node edit form is quite particular. :)