Close Lightbox on Custom Form Submit I am using form Api to create a custom form. My form is below. 

function myform_form() {
  $form = array();
  $form['name'] = array(
    '#type'          =&gt; 'textfield',
    '#title'         =&gt; t(''),
    '#required'      =&gt; FALSE,
    '#weight'        =&gt; 2,
  );
   $form['telephone'] = array(
    '#type'          =&gt; 'textfield',
    '#title'         =&gt; t(''),
    '#weight' =&gt; 3,
    );
     $form['submit'] = array(
      '#type' =&gt; 'submit',
      '#value' =&gt; t('submit'),
     );
  return $form;
}

function myform_submit($form, &amp;$form_state) {
  drupal_set_message(t('Your form has been submitted successfully.'));
  $form_state['redirect'] = 'thankyou';
}


I used to show this form in lightbox as this : 

&lt;a href="/myform" rel="lightframe"&gt; Form &lt;/a&gt;


Form is correctly showing in lighbox. But when i submit the form it opens the thankyou page in popup.

I used  

&lt;a href="/myform" rel="lightmodal"&gt; Form &lt;/a&gt;

It closes the popup event if form validation returns false. I don't want to close the popup if there is any validation error. I added this to myform_submit function :

parent.Lightbox.end();


But drupal_add_js is not working in myform_submit function.

Updated : 

I send a parameter to thank you page and added this on the page load.

&lt;?php if($_GET['redirect']) { ?&gt;
  &lt;script&gt; 
      window.parent.location = "quick_request_quote";
  &lt;/script&gt;
&lt;?php } ?&gt;


Its redirecting but it shows content in popup for few seconds and redirect after that. I don't want to display popup for a second also after submitting the form.
Solved this by creating a Menu showing processing message and redirect it using : 

      window.parent.location = "thankyoupage";