Support This Site

Run a form in a separate window Print E-mail
Written by Peter Koch   
Thursday, 21 October 2004

When your form exceeds the component space available in your site template, you might want to run your form as a separate browser window. This short tutorial shows how to do it.

Creating The Menu Item

The first thing you need to do is create a menu item that will open the form in a separate window. I assume the form name is popup in this tutorial:

  • Go to the desired mambo menu (for example Menu - Main Menu)

  • Locate the icon labeled New and give it a click

  • In the select component list click on Link - URL and then on the button Next

  • In the Name field enter the desired item name to be displayed in the menu, for example My Popup Form

  • In the Link field enter the url as:
    http://localhost/mambo451/index2.php?option=com_facileforms&ff_name=popup&ff_border=0&ff_frame=0
    Now this might need a little explanation:

    • You need to change http://localhost/mambo451 to your site url of cause
    • Using index2.php instead the usual index.php will make only the component show up instead of the whole page including headers, modules and so.
    • Change popup to the name of your form
    • It is also essential to add the parameter &ff_frame=0 for the scripts that will be added to the form later in this tutorial.

  • At On Click, Open in select New Window Without Browser Naviagation

  • Set the other parameters as you desire

  • Click on the Save icon to save the menu item.

Now you may check out the menu item in frontend. It allready is working, but it probably does not look too good since the window size is not adjusted to the form. You can change that in the form itself:

Changing The Window Size

  • Open your form settings in backend and go to the Scripts pane

  • At Initialization Script check Custom

  • Click on Create code framework and confirm the question whether to really do it.

  • Enter the window sizing commands into the body of the function as:
    function ff_popup_init()
    {
        window.resizeTo(420, 430);
    } // ff_popup_init
    
    The name of the function will of cause be diffrent if your form has another name than popup. You need to set the width about 20 larger than the form width, and the height about 60 larger that the form height because the window size includes the browser frame and title bar.

  • Save the form

The form itself will show up perfectly now, but something is still missing. After submit you would most likly want the window to be closed again:

Closing The Windows

  • Open your form settings in backend and go to the Scripts pane

  • At Submitted Script check Custom

  • Click on Create code framework and confirm the question whether to really do it.

  • Enter the status notification and the window close commands into the body of the function as:
    function ff_popup_submitted(status, message)
    {
        alert(message);
        window.opener = self;
        window.close();
    } // ff_popup_submitted
    
    The name of the function will of cause be diffrent if your form has another name than popup. The command windows.opener = self; will avoid the user getting asked if he really wants to close the window.

  • Save the form

Comments

Guest
2004-12-09 06:53:15
Hi Peter, 
 
first at all I've to say facileforms is greatest piece of software for mambo I've ever seen before. Great work! 
 
I've tried out this tutorial, and all works fine. Except the window doesn't close after the form was submitted, but it is only reloaded and displays the parent page the window was opened from. 
 
I've created a second button for testing purposes to see if the window.close() works. And it works fine. Only in case the button executes a form validation and submit script before window.close() it doesn't work as described above. 
 
Do you have any idea? 
 
Best regards, 
Georg Lorenz
kochp
2004-12-10 09:51:43
I guess the script does not make it to the window.close(). Try adding an alert('before'); and alert('after'); before and after the window.close(). Also check the javascript console if any errors were emitted.
Guest
2004-12-11 12:07:58
I tried it now again, and now it works like a charm. And the alert message is coming up now telling about "The form was successfully submitted", which didn't arise before. 
The only ugly thing is, as I think, on submitting the form the window is being reloaded and displays the main page including all the navigation pane. I think at this point the file index.php is used, even though I used index2.php for the popup. 
 
Best regards, 
Georg Lorenz
kochp
2004-12-11 13:47:02
The issue with index.php after submit can be fixed by doing a redirection in the end submit piece. I'll add this to the tut as soon as I find some time.
Guest
2004-12-14 17:56:04
here: http://www.ahk-uruguay.com/content/view/56/143/ , the link "Bestellformular für Veröffentlichungen". 
 
The only issue, as for everyone as it seems, is the index.php loading in the meantime.  
 
Great job, THANX! 
./sgipan
Guest
2005-02-07 12:02:24
how do I create a survey form in mambo? I have Facile forms installed!
Guest
2005-03-04 11:06:43
I didn't like it the way it first loaded the indexpage and then closed itself. So I tried this: 
 
function ff_popup_submitted(status, message) 

window.close(); 
} // ff_popup_submitted 
 
it works fine; closes rightaway  
but first you get an alertbox with nothing in it. 
How can I get rid of thsi thing? 
 
Tx, 
 
papa_kievit 
wonderwoman
2005-12-22 06:39:20
"The issue with index.php after submit can be fixed by doing a redirection in the end submit piece. I'll add this to the tut as soon as I find some time." 
 
Did this get done? not finding reference to it anywhere, and going absolutely nuts trying to get the submit and thankyou pages working in a popup window. 
james_uk
2006-03-10 22:23:15
This popup method also has the advantage that there is no history in the new browser window so the browser back and forward buttons comamands cannot be used (either by keyboard or mouse input). Using the back and forward buttons on a form can have a potentially distressing side effect of the user loosing the form contents. 
 
This popup method is great for larger forms where you really do not want the user to lose the form contents.
normdouglas
2006-03-29 17:07:29
Great code, works a treat!
walidn
2006-06-17 04:53:43
it is working great, to popup window with the needed form. 
but want to let it open a page number 2 in the form. 
how to accomplish that? 
thanks in advance.
walidn
2006-06-17 04:59:30
http://localhost/mambo451/index2.php?option=com_facileforms&ff_name=popup&ff_border=0&ff_frame=0&ff_page=2 
 
this will open your form popup, and directed to page 2  
ff_page=2
walidn
2006-07-09 03:23:29
The issue with index.php after submit can be fixed by doing a redirection in the end submit piece. I'll add this to the tut as soon as I find some time."  
 
Did this get done? not finding reference to it anywhere, and going absolutely nuts trying to get the submit and thankyou pages working in a popup window.  
 
Put this in end submit pieces 
$url = '{mossite}/index2.php?option=com_'. 
'facileforms&ff_name=myadmin_projectprofile&ff_border=1&ff_frame=0'; 
ff_redirectParent($url); 
luijt99
2006-08-08 11:00:55
Put this in end submit pieces  
$url = '{mossite}/index2.php?option=com_'.  
'facileforms&ff_name=myadmin_projectprofile&ff_border=1&ff_frame=0';  
ff_redirectParent($url);
 
 
When I try this, I get the following error. Can somebody help me? 
 
Fatal error: Call to undefined function ff_redirectParent() in /home/mailastu/public_html/components/com_facileforms/facileforms.process.php(1002) : eval()'d code on line 3
Captain Paralytic
2006-08-23 05:25:13
Try including  
$this->execPieceByName('ff_InitLib'); 
before calling ff_redirectParent
rio517
2006-10-03 05:16:42
I found captain Paralytic's code worked for me: 
 
$url = '{mossite}/index2.php?option=com_'.  
'facileforms&ff_name=[FORM NAME]&ff_border=1&ff_frame=0&ff_page=2';  
$this->execPieceByName('ff_InitLib'); 
ff_redirectParent($url);
scarygary
2006-10-23 08:21:09
I've managed to get the thing opening in a new window, give me a confirmation popup when i click on save and even close the window after that. The only thing i can't figure out, is how to make it NOT go back to the home page with all the menus and stuff.  
I tried the code mentioned here, but all that does is go back to an empty form along with removing my confirmation alert. Li'l' help please?!
RVP
2008-02-01 16:00:08
Hi there, 
I got my form to open nicely in a separate window. 
however the following code is not working anymore : 
ff_getElementByName('obf_amount').value = Math.round(amount*100)/100; 
where obf_amount is a read-only text field I wish to update with this value to show to the user. 
any pointers here ? 
 
thanks.
Masters Housing
2008-09-15 06:11:40
How to do it: 
First create a new menu Item "Component" Under "Parameters", subheading "Form Name" type the exact name of the form you created form. Then create the menu item. Next create a new menu item "Link - Component" Then choose the prevoisly created menu item. Name this new items whatever you want it to appear as in the menu. Then choose "Open in new window without navigation" and create the second menu item. Then go to your menu manager and unpublish the first menu item you created. The second menu item which is the remaining published one will open the popup window just like you want, while the first one hides in the background taking care of all of your formatting worries without you having to paste in any code except for the code to close the window upon submitting the form which you will still have to do as described above.

Only registered users can write comments.
Please login or register.

 
< Prev   Next >