Hi all. I try to build a form for applications. Users should upload one or more files as an attachment. These files should be stored in the file directory separated by the uploader’s names.
Formit works great with AjaxUpload with a static path to the upload directory. If the directory doesn’t exist, it will be created.
Now I want to create an upload path with the name of the uploader like
&ajaxuploadTarget=`uploads/[[+name]]`
This doesn’t work.
Any ideas to realize this? Many thanks in advance.
For all forum users: happy holidays!
What exactly is the placeholder [[+name]] and where is it set?
I guess that if you want to use a placeholder value for a property in the [[!FormIt? ...]] snippet tag, you have to make sure that the placeholder is set, before FormIt is called.
For example by first executing a custom snippet that sets the placeholder:
[[!setNamePlaceholder]] <!-- custom snippet that sets the 'name' placeholder -->
[[!FormIt?
...
&ajaxuploadTarget=`uploads/[[!+name]]`
...
]]
If you have pdoTools (or fastField) installed, then maybe you could also use [[!#post.name]] instead of the placeholder.
Alternatively you could write a custom hook, that runs after the “AjaxUpload2Formit” hook and moves the files to a different directory.
And I want to get the sub directory for uploads created by the name of the sender after submitting the form. So I can handle all applications separately.
I think, I need a custom hook … but how??
I tried the placeholder [[+name]] like described above but this creates endless sub directories named [[+name]] and not a single directory with the real name of the name fields content.
The MODX parser parses nested tags first. In this case it means that [[+name]] is processed before the snippet FormIt is called.
So you have to make sure that this placeholder is set beforehand. Either by calling a custom snippet above the FormIt tag (that reads the value from $_POST and sets the placeholder → $modx->setPlaceholder(...)) or by using &ajaxuploadTarget=`uploads/[[!#post.name]]/` instead (if pdoTools is installed).
If the MODX parser can’t find the “name” placeholder, then FormIt is called with the unparsed property value. And AjaxUpload doesn’t parse this property value, before it is used to create the folder.
This is somehow insecure, since name can contain slashes and dots which allows changing the folder. Better add an own hook, that restricts the name and sets the folder by $hook->formit->config for the AjaxUpload hook.
YES! That works. And now I can try to “clean” the input in the name field to avoid security issues.
At this time it’s all a test. The goal is an application form for a gallery. Artists should apply for an exhibition and submit examples of their work in PDF format. Staff at the gallery will then have access to the applications and examples via protected access.
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.