4

I am using form Api to create a custom form. My form is below.

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

function myform_submit($form, &$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 :

<a href="/myform" rel="lightframe"> Form </a>

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

I used

<a href="/myform" rel="lightmodal"> Form </a>

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.

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

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.

2 Answers 2

0

Solved this by creating a Menu showing processing message and redirect it using :

      window.parent.location = "thankyoupage";
-2

Hope this will help you,

For forms validation on modal dialog you can user Chaos tool suite module.

Steps

  • Download and enable Chaos tools and Chaos Tools (CTools) AJAX Example
  • Go to the URL your_site/ctools_ajax_sample
  • You can refer ctools dialog form examples using sites/all/modules/contrib/ctools/ctools_ajax_sample
    • Where contrib is the folder where I keep all my contributed modules.
3
  • 5
    Could you please explain how to use ctools for that effect? It's a big and complicated set of tools, just pointing at it will be useless for at least some readers.
    – Mołot
    Commented Jun 24, 2013 at 6:55
  • updated my question check. Commented Jun 24, 2013 at 7:59
  • Better now. I did not downvoted you so I cannot un-downvote, and it's still hardly anything but pointing at examples, so I'm not so sure if it deserves upvote. Let's leave it to downvoters and question's author.
    – Mołot
    Commented Jun 24, 2013 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.