skip to Main Content

Question:
What do I have to do to hide a download link as soon as the download starts?

Problem:
The difficulty or problem for me here is that a password is sent with the user request. If the password is correct, the download starts. If the password is incorrect, the download is redirected to the same page.

Blade / Frontend

<form action="/download/{{ $data->uuid }}" method="POST" class="download-with-pw">
  @csrf
  <label for="password">Password:</label>
  <input type="password" name="password" value="">
  <input type="submit" value="Download">
</form>

Controller / Backend

...
if ($request->input('password') === $file->password) {
  return IlluminateSupportFacadesStorage::download($path);
}

2

Answers


  1. To hide the download link once the download has started you can use javascipt to detect form submission and immediately hide the link

    Login or Signup to reply.
  2. I expect you should just hide it by handling the "submit" event of the form using JS. It should run before the submission occurs.

    Rather than a "success" message, just put a "your download will start shortly" message, or something like that – that’s pretty common on download sites.

    Then if it turns out there’s an error, the server will redirect the browser back to a suitable point, which presumably will show the form again anyway.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search