Form Attachment
Permalink 3 users found helpful
I understand that when a file is attached via the form block, the message and attachment get saved in the dashboard and the message without the attachment get emailed to the email address specified in the block...
message goes in (reports > form results)
file goes in (file manager >Display files in no sets.)
Is it possible to change the folder in which the attachments upload into while still being able to view them in the file manager?
I need to password protect the folder in which the files get uploaded from the form. Otherwise any files sent via the form are susceptible to being viewed by the world.
If this is too much of a task, is it possible to have the form just email the form data out to an email address instead of using the dashboard? I could set an SSL SMTP address in the dashboard and tell the form block to use that instead of uploading into the dashboard.
Any thoughts on this?
message goes in (reports > form results)
file goes in (file manager >Display files in no sets.)
Is it possible to change the folder in which the attachments upload into while still being able to view them in the file manager?
I need to password protect the folder in which the files get uploaded from the form. Otherwise any files sent via the form are susceptible to being viewed by the world.
If this is too much of a task, is it possible to have the form just email the form data out to an email address instead of using the dashboard? I could set an SSL SMTP address in the dashboard and tell the form block to use that instead of uploading into the dashboard.
Any thoughts on this?
That would be great to be able to automatically define the set an file would be put into. I would be very interested if you figure out how to do this.
Well, a quick and dirty solution until I can really modify the form block is this:
Copy the form block from /concrete/blocks to /blocks
Edit /blocks/form/controller.php
Change this:
to
This assumes that you have a file set created already named 'uploads'
To change the form to allow an admin to pick the fileset would require and additional database field for this block to store the fileset ID.
Copy the form block from /concrete/blocks to /blocks
Edit /blocks/form/controller.php
Change this:
$tmpFileIds[intval($row['msqID'])] = $resp->getFileID();
to
$tmpFileIds[intval($row['msqID'])] = $resp->getFileID(); Loader::model('file_set'); $fs = FileSet::getByName('uploads'); $fsf = $fs->addFileToSet($resp);
This assumes that you have a file set created already named 'uploads'
To change the form to allow an admin to pick the fileset would require and additional database field for this block to store the fileset ID.
do controller changes like these work for templates? So differing templates could have different filesets as long as the template folders have differing controller files? Not necessary for what I need to do, just wondering in general.
By the way this works great, THANK YOU!
OK, I think that I've come up with a better solution without modifying the database.
First, as above, copy the /concrete/blocks/form/controller.php to /blocks/form/controller.php
Modify this line
to
Then, create a new custom attribute of type text called Form File Set with the handle form_fileset
Now on the page with the form, add this new attribute and type a file set name in the field (must be exactly the fileset name - case sensitive) otherwise it will create a new fileset with the attribute name and put the file into that instead.
If the attribute is absent from the page, it will place the file into no sets.
This has been roughly tested so let me know if you have any problems.
EDIT: replaced TYPE_PUBLIC with FileSet::TYPE_PUBLIC
First, as above, copy the /concrete/blocks/form/controller.php to /blocks/form/controller.php
Modify this line
$tmpFileIds[intval($row['msqID'])] = $resp->getFileID();
to
$tmpFileIds[intval($row['msqID'])] = $resp->getFileID(); Loader::model('file_set'); $page = Page::getCurrentPage(); if (!$page->getCollectionAttributeValue('form_fileset')){ $fs = FileSet::getByID(0); }else{ $formset = $page->getCollectionAttributeValue('form_fileset'); if (!FileSet::getByName($formset)){ $fs = FileSet::createAndGetSet($formset, FileSet::TYPE_PUBLIC, $uID = false); }else{ $fs = FileSet::getByName($formset); } } $fsf = $fs->addFileToSet($resp);
Then, create a new custom attribute of type text called Form File Set with the handle form_fileset
Now on the page with the form, add this new attribute and type a file set name in the field (must be exactly the fileset name - case sensitive) otherwise it will create a new fileset with the attribute name and put the file into that instead.
If the attribute is absent from the page, it will place the file into no sets.
This has been roughly tested so let me know if you have any problems.
EDIT: replaced TYPE_PUBLIC with FileSet::TYPE_PUBLIC
nice, wouldn't it be simpler (for the user not necessarily you) to have a dropdown with current files sets? Your first solution was perfect for me, as I am not afraid to dabble in the code, but others would probably benefit from this newer addition.
I did a form block mod to let the user select a file set to add his upload to. First, I created my filesets. I didn't get too fancy - I manually built the select control making sure it contained all the filesets I wanted and that they were all spelled correctly. (This code modification expects that there will only be one drop-down on the form.) I then copied the concrete/block/form to <my root>/block/form and edited the controller.php file.
In the action_submit_form() function:
...and then a little further down in the same function...
It's kind of a heavy-handed approach, and because I overrode the form block then it will affect every form I add to the site. If I wanted to be thorough I'd go through and rename everything to a new version of the form block and call it UploadFileSetForm or something. I'll probably end up doing that eventually but I don't have the energy right now.
Hope this helps someone!
In the action_submit_form() function:
//try importing the file if everything else went ok $tmpFileIds=array(); if(!count($errors)) foreach($rows as $row){ $questionName='Question'.$row['msqID']; // Get the value of the select control to indicate the file set to add the uploaded file to. if( $row['inputType']=='select' ) $fileset=$txt->sanitize($_POST['Question'.$row['msqID']]);
...and then a little further down in the same function...
It's kind of a heavy-handed approach, and because I overrode the form block then it will affect every form I add to the site. If I wanted to be thorough I'd go through and rename everything to a new version of the form block and call it UploadFileSetForm or something. I'll probably end up doing that eventually but I don't have the energy right now.
Hope this helps someone!
Oops. Just realized my code snippets were a little squirrelly.
1) I declared the $fileset variable as a public attribute at the class level. This was while I was dinking around trying to make things work - you could as easily declare it locally in the action_submit_form() function.
2) The $questionName assignment is superfluous. I don't use it for anything. That's in there as a remnant of me trying to identify the select control by name. I will probably keep trying to make that work so I can have multiple selects on the form and pull the value from the correct one, but it's not used in the code I quoted above.
3) The die(_("No file set selected.") is a debugging statement. You should probably take that out.
1) I declared the $fileset variable as a public attribute at the class level. This was while I was dinking around trying to make things work - you could as easily declare it locally in the action_submit_form() function.
2) The $questionName assignment is superfluous. I don't use it for anything. That's in there as a remnant of me trying to identify the select control by name. I will probably keep trying to make that work so I can have multiple selects on the form and pull the value from the correct one, but it's not used in the code I quoted above.
3) The die(_("No file set selected.") is a debugging statement. You should probably take that out.
Thank you so much. Now the only question I have is it possible to make the new folder secure so that nobody would be able to view the individual file attachments after implementing your code? The below link is an example of a picture file uploaded to the dashboard using the regular form block before your recommended code upgrades. I will get to implementing your crafty code very soon.
http://landsmachining.net/files......./112448_nature.jpg...
How do I use the form and make the file hidden from other web viewers? Perhaps SSL is the key on the entire domain or would that just secure the form transmission of data to the email recipient and the dashboard?
regards,
http://landsmachining.net/files......./112448_nature.jpg...
How do I use the form and make the file hidden from other web viewers? Perhaps SSL is the key on the entire domain or would that just secure the form transmission of data to the email recipient and the dashboard?
regards,
I assume someone smarter than I could auto set the permissions of the file just like the file set or default location, right? The file manager allows password protecting the files in it or changing the location.
With advanced permissions turned on, you can assign permissions to sets. Use the image or file block to display the image or file and you should have something to work with.
I am new at this so could you please explain how to do the following?
Now on the page with the form, add this new attribute and type a file set name in the field (must be exactly the fileset name - case sensitive) otherwise it will create a new fileset with the attribute name and put the file into that instead.
I have done everything else but I am not sure how to do this.
Now on the page with the form, add this new attribute and type a file set name in the field (must be exactly the fileset name - case sensitive) otherwise it will create a new fileset with the attribute name and put the file into that instead.
I have done everything else but I am not sure how to do this.
I figured it out. It was the page attribute. This works well. Now all that I need to figure out is how to set up that file set so that it can only be viewed by the admin and not other viewers or non-registered guests.
Add this to your site.php file:
This should give you the ability to set permissions on sets.
define('PERMISSIONS_MODEL', 'advanced');
This should give you the ability to set permissions on sets.
Do I add that code directly in the php file? If yes, do I place it anywhere in the file? I tired adding it on the top and bottom but when I log into the site I see some syntax error on the top of the screen.
I tried using the form after your code (without the new mod for file set attributes) and when I try attaching a zip file that is 8mb in file size I am receiving the following error message. Do you happen to know what I could do to fix this?
Fatal error: Uncaught exception 'Exception' with message 'Oops, something is wrong with the form you posted (it doesn't have a question set id).' in /home2/sosweene/public_html/landsmachining/blocks/form/controller.php:204 Stack trace: #0 /home2/sosweene/public_html/landsmachining/concrete/models/block.php(276): FormBlockController->action_submit_form() #1 /home2/sosweene/public_html/landsmachining/concrete/startup/process.php(214): Block->passThruBlock(Array, Array) #2 /home2/sosweene/public_html/landsmachining/concrete/dispatcher.php(226): require('/home2/sosweene...') #3 /home2/sosweene/public_html/landsmachining/index.php(2): require('/home2/sosweene...') #4 {main} thrown in /home2/sosweene/public_html/landsmachining/blocks/form/controller.php on line 204
Fatal error: Uncaught exception 'Exception' with message 'Oops, something is wrong with the form you posted (it doesn't have a question set id).' in /home2/sosweene/public_html/landsmachining/blocks/form/controller.php:204 Stack trace: #0 /home2/sosweene/public_html/landsmachining/concrete/models/block.php(276): FormBlockController->action_submit_form() #1 /home2/sosweene/public_html/landsmachining/concrete/startup/process.php(214): Block->passThruBlock(Array, Array) #2 /home2/sosweene/public_html/landsmachining/concrete/dispatcher.php(226): require('/home2/sosweene...') #3 /home2/sosweene/public_html/landsmachining/index.php(2): require('/home2/sosweene...') #4 {main} thrown in /home2/sosweene/public_html/landsmachining/blocks/form/controller.php on line 204
The file might be larger than your php settings will allow. Go to the file manager and click the more button next to the upload button. In that window, it should indicate your upload size and max post size. This can usually be overwritten locally in a php.ini file if it is smaller than 8mb.
The advanced permissions code should be put at the end (it really doesn't matter) but before the closing ?>
The advanced permissions code should be put at the end (it really doesn't matter) but before the closing ?>
The code is working with one exception and this may be an easy fix; moreover, I do appreciate all of your help.
Under file manager > sets > uploads > edit
I am checking the new box that appeared which is labeled 'Enable custom permissions for this file set.'
When I click update on the bottom and then go back in to edit mode, the check-box is not checked. Do you happen to know if I did something wrong here?
Under file manager > sets > uploads > edit
I am checking the new box that appeared which is labeled 'Enable custom permissions for this file set.'
When I click update on the bottom and then go back in to edit mode, the check-box is not checked. Do you happen to know if I did something wrong here?
I don't think the box stays checked. As long as the larger menu still appears with all of the group level permissions visible, I think you should be OK.
Thank you. I do see that these file permissions do not restrict other people form being able to view them form outside the dashboard.
There is only two people that have access to the dashboard. I can still see the uploaded file that is in this set after implementing the code and setting the permissions.
http://landsmachining.net/files/2112/8078/7475/112448_nature.jpg...
I do need to see if there is a way to restrict access to these files if possible.
Do you have any suggestions?
There is only two people that have access to the dashboard. I can still see the uploaded file that is in this set after implementing the code and setting the permissions.
http://landsmachining.net/files/2112/8078/7475/112448_nature.jpg...
I do need to see if there is a way to restrict access to these files if possible.
Do you have any suggestions?
True, if you have the absolute path as above, people can get to them. I don't think there is a way around this. It works better for documents since their paths are obscured by the download_file page.
It looks like you are correct. Advanced permissions do not lock images from being viewed. However, now that you have advanced permissions turned on, you can lock the block that the image is in, whether it be a content block or image block. this works fairly well, but does not prevent someone from sharing the absolute link and discovering the image path.
Thanks. Now all I need is to figure out a way to get rid of the syntax error when people try and upload larger files than 8mb. I have a sentence on the site but if someone does not read that and tries to upload a large file they will see syntax error in the page and the form will not be submitted. Are you familiar with how to tell the block to display a 'pretty' message when a file exceeds the set mb size instead of the syntax?
If you do than this would be an all around big help to me and all of the community as you have created a way to resolve these issues.
If you do than this would be an all around big help to me and all of the community as you have created a way to resolve these issues.
Does anyone know how to include descriptions to go with the images, and show who uploaded the images on the image file as a caption?
I am a nob (newbie) when it comes to this question but I am sure that someone with more no how will help answer the question.
This no longer seem to work in 5.4.1 any ideas how to get something like this working again?
I'm using 5.4.1 and code above wasn't working. The issue in 5.4.1 is that FileSet::createAndGetSet(...) isn't saving the fileset. Here's my updated code.
Please note that I'm also creating a file set directly from the forms name without looking for a custom page attribute.
Cheers
Andrew
Please note that I'm also creating a file set directly from the forms name without looking for a custom page attribute.
Loader::model('file_set'); /** @var TextHelper $th */ $th = Loader::helper('text'); $filesetName = $th->camelcase($this->surveyName) . "Uploads"; /** @var FileSet $fileSet */ $fileSet = FileSet::getByName($filesetName); if (!$fileSet) { $fileSet = FileSet::createAndGetSet($filesetName, FileSet::TYPE_PUBLIC); $fileSet->Save(); // FileSet isn't being saved... } $fileSet->addFileToSet($resp);
Cheers
Andrew
I'm completely new to concrete5 and I'm making a site which will have a different image gallery on each page. what I am wanting is to be able to have a multiple image upload form on each page that will link just to the gallery that is on that particular page.
can anyone be able to help me??
as I say I am a complete novice so if anyone could show me where i go to do it too I would be very grateful.
Robert
can anyone be able to help me??
as I say I am a complete novice so if anyone could show me where i go to do it too I would be very grateful.
Robert
like you want the public to be able to send images to the page? or just admins?
best wishes
Franz Maruna
CEO - concrete5.org
http://about.me/frz
best wishes
Franz Maruna
CEO - concrete5.org
http://about.me/frz
I am building a fans review website for my supported team which involves fans posting comments on the match and uploading pictures to a gallery for that particular match.
fans will have to register for my site and then they will get access to see my site...so it will be just for registered users of my site.
what I am wanting is when a fan clicks on a particular fixture it will take them to that fixtures page and on that page will be a file upload form and an image gallery...and when a fan then uploads a picture through the form I want it just to go in the the image gallery that is on that page.
I want to have the same thing for all the other fixtures....so I will need to have a lot of galleries one for each fixture and to have an individual upload form linked to each one.
so I am wondering how I can link the form/multiple upload form to the gallery.
hope that make more sense for you.
Robert
fans will have to register for my site and then they will get access to see my site...so it will be just for registered users of my site.
what I am wanting is when a fan clicks on a particular fixture it will take them to that fixtures page and on that page will be a file upload form and an image gallery...and when a fan then uploads a picture through the form I want it just to go in the the image gallery that is on that page.
I want to have the same thing for all the other fixtures....so I will need to have a lot of galleries one for each fixture and to have an individual upload form linked to each one.
so I am wondering how I can link the form/multiple upload form to the gallery.
hope that make more sense for you.
Robert
p.s. if you possibly have an idiot guide of how to do this and where to go in C5... I would be most grateful.
Robert
Robert
i think someone has a pull request in to extend the form block so when you have a file uploaded you can automatically put it in a set. This little bit of functionality would totally do what you need. We will try to get it in the next version of concrete5.
Until then, I'm afraid the only way I can think of doing this involves some coding.
Until then, I'm afraid the only way I can think of doing this involves some coding.
when is the next version due out?? as this will save me a hell of a lot of messing about!!
Robert
Robert
what version will it be and i will keep an eye out for it.
are you sure that someone has a request to extend the form block?? is there any way of checking?
thanks
Robert
are you sure that someone has a request to extend the form block?? is there any way of checking?
thanks
Robert
-J