function news_article_node_submit($node, $form, &$form_state)
// Make a URI link from title of pdf being uploaded
if (isset($form_state['values']['field_upload_import_pdf'])) {
    $file = file_load($node->field_upload_import_pdf['und'][0]['fid']);
    $filePath = file_create_url($file->uri);

    // Redirect to pdf
    if (isset($filePath)) {

        // Return all field behaviors to redirect to default
    } else {
        $form_state['redirect'] = 'to page preview';

I was experimenting with drupal_goto() and $form_state['redirect'], but neither of them seems to work. Using drupal_goto() hijacks the whole module and the $form_state['redirect'] doesn't do anything. Also I am getting PHP errors when else function encounters the first two lines of code above:

Notice: Undefined offset: 0 in news_article_node_submit()

Notice: Trying to get property of non-object in news_article_node_submit()

Is there a way to create a URI from the filename, and redirect users to domainname://NAME_OF_FILE.pdf when choosing a conditional field while, at the same time, when users use any other conditional field, the behavior is the default Drupal one?

  • I know! Is there another way to approach this?
    – emb03
    Commented Aug 31, 2018 at 22:12

1 Answer 1


You can use the trick from the module File Force Download. You can check it in the their code repository https://cgit.drupalcode.org/file_force/tree/file_force.module?h=7.x-1.x

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.