Close Lightbox when form is submitted

When you have a form inside a Lightbox...

Question:
How can I close the Lightbox on form submit?

Answer:


When you have a form displayed in a Lightbox you can simply set the target of your form tag to "_top". That is if the form must be submitted to the parent page of the Lightbox.

If your form is submitted elsewhere( i.e. in the same page where the form is placed or on a page that defers for the parent one) and you are using built-in server behaviors in Dreamweaver for inserting, updating or deleting records in database and a redirection, you can do as follows:

For ASP as well as PHP:

1. Make a RedirectChildWindow.htm file containing:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8"" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function controlDMXzoneLightbox(cmd, args, context) {//v1.0
        context = context || window, args = args || [];
        if (context.DMX && context.DMX.Lightbox) {
            args.unshift(cmd);
            context.DMX.Lightbox.runCommand.apply(context.DMX.Lightbox, args);
        }
  }
//-->
</script>
</head>

<body onload="controlDMXzoneLightbox('close', [], parent.parent)"></body>
</html>

 2. Put this file in the popup window as a redirect at your Insert/Update record SB

If  you have custom server behavior you can use a method that set a check for form submit as follows::

For PHP:

if(count($_POST) > 0){
            echo "<script> top.location = top.location; </script>";
            exit;
    }

 For ASP:

If (Request.Form.Count > 0) Then
      Response.Write("<script> top.location = top.location; </script>")
      Response.End
    End If

that will refresh the parent page of the Lightbox, which will close the box and your form will be submitted.

If any questions appear, don't hesitate to sent them on my e-mail: miro@dynamiczone.com