A
A
Alexander2017-08-25 11:20:24
MODX
Alexander, 2017-08-25 11:20:24

How to fix hook for FormIt?

There is a task so that when submitting a completed form, a file is downloaded, and then the user is redirected to another page. The file is loaded through the TV-field. I'm trying to do it with the download
hook :

$kp = $_SERVER['DOCUMENT_ROOT'];
  $kp .= $modx->resource->getTVValue('kp');

  if (file_exists($kp)) {
      header('Content-Description: File Transfer');
      header('Content-Type: application/octet-stream');
      header('Content-Disposition: attachment; filename="'.basename($kp).'"');
      header('Expires: 0');
      header('Cache-Control: must-revalidate');
      header('Pragma: public');
      header('Content-Length: ' . filesize($kp));
      readfile($kp);
      exit;
  } else {
    $modx->log(xPDO::LOG_LEVEL_ERROR, 'Нет такого файла');
  }
  return true;

I call FormIt as usual:

The problem is that the file is downloaded, but the redirect does not work. I suppose this is due to the exit function , but if you remove it (or put return true; instead ), then the redirect works, but the file does not download.
Can you tell me how to make both actions work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ulo, 2017-08-28
@Salexer

remove redirect and try to put header with redirect manually before exit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question