I have a webform node. I need the users to fill it and on submit, the user will be redirected to some link.

if ($form_id == 'webform_client_form_970') {
    $form['#submit'][] = 'dl_pdf';

function dl_pdf(){
        drupal_goto("http://dev.site.com/ar/printpdf/9", $options); 

When the form is submitted, drupal_goto works ( it actually just downloads a PDF file automatically ) but the form does not get refreshed.

What i have been doing wrong. Any clue?


if ($form_id == 'webform_client_form_970') {
        //$form['#submit'][] = 'dl_pdf';
            'jQuery(document).ready(function () { 
                jQuery(".webform-submit").on("click", function(){
                    var win = window.open("'.dl_pdf().'", "_blank");
            'type' => 'inline', 
            'scope' => 'footer', 
            'weight' => 5

function dl_pdf(){
        return "http://dev.site.com/ar/printpdf/9?name=".$userinfo->title."&date=".$course_date."&course_type=off-non-reg&course_name_ar=".$courseinfo->title.""; 

If you redirect to a URL that does not return a page but instead returns some other type of resource (such as a PDF in this case), then the current page will not be refreshed, as you have observed, because the response to the form request is returning the PDF, not HTML.

If you want the page to be refreshed as well then a common technique is to return the HTML for the new page from the form, and then redirect again to return the PDF. Because you need the new page to load fully (so the browser renders it), you'll need to use JavaScript to provide the redirect to the PDF. You can have a link in the page as well, to say something like "If the file does not download automatically, click here".

  • doing it with javascript worked. – brainHax Jun 2 '16 at 14:15

For redirect form after submit you have to implement

$form_state['redirect'] = "Your URL"

For more information visit here

  • Yes, this is the correct technique but the drupal_goto the OP has coded will have exactly the same effect (form processing calls drupal_goto for you instead of you having to call it directly). – Alfred Armstrong Jun 2 '16 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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