1

How can I use a request variable used in an upload form like this?

<form method="post" accept-charset="UTF-8" enctype="multipart/form-data">
<input type="hidden" name="action" value="entries/saveEntry">
<input type="hidden" name="sectionId" value="29">
<input type="hidden" name="enabled" value="1">
<input type="file" name="fields[useruploads]">
<input type="text" name="challenge_id">
...

The idea is to use the field "challenge_id" as dynamic upload location.

enter image description here

Is there a way to get this?

2
  • 1
    Try something like challenges/{{ craft.request.getPost('challenge_id') }}/? I'd also be wary of accepting untrusted front-end input like this that ends up on the file system.
    – Brad Bell
    Commented Apr 13, 2017 at 18:37
  • @Brad Bell: it works - the hint hearby the field "... like {slug] or ..." is misleading, because I have done all my tries with one curly brace.
    – Marco
    Commented Apr 15, 2017 at 14:30

1 Answer 1

1

That field accepts any valid Twig code, so something like this should work:

challenges/{{ craft.request.getPost('challenge_id') }}/

Fair warning, though... I'd also be wary of accepting untrusted front-end input like this that ends up on the file system.

2
  • This seems pretty dangerous, unless Craft automatically prevents users from writing to directories outside the install (i.e. a user in the front-end passing in ../../../usr/bin/ or something malicious)… Commented Apr 17, 2017 at 15:32
  • 2
    Craft does some bounds checking for situations like this, but I added the warning in my initial comment to the answer, too.
    – Brad Bell
    Commented Apr 17, 2017 at 20:24

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.