0

I have made a custom module where I load the create node form for an "announcement" content type.

What i want

Besides the text and select fields, I require an image field which supports multiple image upload (up to 4 ). The images should be uploaded to a temporary directory and load in the form a thumbnail for preview , and on form submit the images should be permanently saved . In case I refresh the form page , if I already selected the images they should still display on the form as thumbnails. After form submit I want to use the first image ( of the max of 4 uploaded ) as a preview image for the announcement and the rest to be shown when the node is viewed (using views module).

What I have

I made an image field with multiple values set to 4, I tried to hide the button for upload so the image is saved only on form submit, but I can't upload but one image on submit. If i leave the upload button , the user can click it , upload the image and do that for each image. But if i refresh the form page the thumbnails are not loaded at all, even though the files are saved on the server. After form submit I get all the images in the box for previewing instead of 1 .

My questions

Right now I am lost on how to approach these issues. I am not afraid to do this programmatically, but I don't know which functions should I look for, if i should keep the field and edit it or add the field programmatically and set its functionality as well. Or can this be solved by a few settings that I missed? Or is there a module out there that already did this so I don't have to reinvent the wheel?

Any help is most apreciated,if required I can attach the code for the module as well.

  • 1
    When the user clicks the upload button it should only be saved as temporary. When the submit button for entire form is created then it should move them to permanent. – FatGuyLaughing Aug 14 '14 at 14:38
  • unless you refresh the form via ajax and have a function to reload the data, if you refresh the form by refreshing the page, I don't think you can get around the fact that the data will be reset. As for Views, in the field settings, you can choose how many to show when multiple are preset, presumably you only want to show 1, the first one. – Geoff Aug 14 '14 at 14:45
  • @FatGuyLaughing how can I check that? from what I saw it saves on my server in the files directory. – Cristi Aug 14 '14 at 19:45
  • @Geoff - what do you mean refresh the form via ajax?? – Cristi Aug 14 '14 at 19:46
  • 1
    @Cristi - Temporary files will eventually be deleted by the cron run when. I believe it has some degree of grace period. That way if you have cron running on your server every 5 mins and the last time cron ran was 4 mins 59 secs ago. It would have a chance of being removed before being set to permanent. – FatGuyLaughing Aug 18 '14 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.