I've a form that I open in a modal window quite successfully. The form has a Submit button that submits the form OK; but what I'd like to do is to close the modal window as well as submit the form when the user clicks the submit button.

I've tried adding

onClick="this.submit(); window.close();"

to the button. The submit works but the window doesn't close.

I've also tried just onClick="window.close();"

and I've also tried window.hide();

Nothing I've tried will actually close the modal window when I click the Submit button.

Many thanks for your reply. The reload works grand; but there's one problem. The modal window submits a form with data to appear on the main window. Unfortunately it seems the main window refreshes before the changes hit the database because the main page doesn't reflect the changes. Hitting F5 in the main page once the modal has closed refreshes the main page again and displays the changes.

I guess it's because the onSubmit function, which executes the parent window reload, runs _before_ the actual submit executes.

That seems nice, but there are a couple of things to be noticed.First of all, this would eliminate the possibility of displaying a confirmation message inside the modal window before reloading the main window.Also, if some kind of error happens after submitting the form, the whole window will have to be loaded again, instead of just a simple message and/or the form.

That seems nice, but there are a couple of things to be noticed.First of all, this would eliminate the possibility of displaying a confirmation message inside the modal window before reloading the main window.Also, if some kind of error happens after submitting the form, the whole window will have to be loaded again, instead of just a simple message and/or the form.

As far as I know, there is no confirmation message for successfully logged in user i Joomla (using JError), only an error message that will show up after iFrame form is submitted. Please correct me if there is one, I searched in user component and language files. Option JS Confirmation message doesn't work for me, in fact I can't find any reference to this option.

For all forms that are not called 'login' action loads in iFrame, so you may add tmpl=component to links href/ form action and target="_self".

I think you're missing the point here. Although modal windows can open any page, the way to make it really useful is using it to add some new functionality to the site, instead of just showing some that already exist.

You could show some special info, display forms, and so on. If a user submit a form, you could show him a status message telling about the result. If the submission process went fine, show something like "The data was succesfully saved." and then close the modal window after a few seconds. And if the data was not saved by any reason, you could show a message saying the reason so the user can fix it and submit the form again. If an error occurs in a form submitted to the parent window, even thought you could show a message, it would take longer to reload the whole window and if the user want to try again, he would have to find the modal window link again...

Also, if an important action is about to happen, like deleting some important database records or something, you could show a confirmation message telling about the consequences and asking if the user wants to proceed or not... If he then chooses to cancel the action, you can just close the window and the user wouldn't have to reload the main page!

In short, what I'm saying is that there are many reasons why you may want to submit the form in the modal window itself and then close it afterwards.

nailson_imgn > thanks for explanation, I agree with you. At the moment I'm using modal box only for the user component (login, remind, etc.).

Unfortunately in Joomla there's no 'login successful' message so there's no point to not close the modal box for me as it would load a blank page If you are aware of any way how to squeeze it out of the system, please let me know.

If the login is unsuccessful, in the main window system message appears. I modded it to jump in the corner of screen frame so it's visible enough.

Unfortunately, Joomla still has a lot of things that has to be fixed. The great thing is: Joomla allows you to fix all you need.Usually I avoid using the Joomla default components. Instead of logging in using com_user, I use the framework to code better user pages/features. When things are wrong only in the layout, I use a layout override... There are always ways to make Joomla even better than it already is.

And just to remind you: your script tip can be useful in some situations. And since it is related with this topic, it is nice to have it here. However, if there are things to be explained that are outside of this topic context the correct thing will be to write a new topic instead of keep posting in this one.

Who is online

Users browsing this forum: No registered users and 7 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum