I have an Entity on Symfony that has also a file "attached" to it.
I want to save the file with the id of the created Entity.
The problem is, that I will know the Entity's ID only after doing "dosave()" on that
Entity form.
Is there any way to save the file after doing the "dosave()" but still write the code
as an override for the Entity's form code?
Assuming you are using symfony's bundled file widget, then you can't do this, because of the way the form save process works. In short, the file is saved by the validator, but by the nature of it being a validator, the data hasn't been saved yet!
I've worked around this before by using a temporary filename for the file if the object is new, and then after save has completed (but still within an overload in the form class), move it to the real location now that you know the id.
Related
I use input form in admin dashboard for changing values in custom config file that is loaded in codeigniter over autoloading. I have issue that after submiting(saving), form values are saved in config file but they are not updated in $this->config->item.
After sending form data to controller and successful saving in config file page is reloaded. Right(updated) values appear in input fields only after one more reload. If config file is loaded only in current controller (not over autoloading) it works ok, but it is needed in many controllers and models. How do I resolve this issue?
As far as i know the data loaded in autoloader is loaded before controller execution. So if you change the data in a called controller it will always differ until reload.
I would recommend handling the data either in a database table or manage it manually in a file (outsource file operation in a library).
Im using Symfony 3.3 and configured a file upload like in the handbook.
https://symfony.com/doc/current/controller/upload_file.html
When editing my entity in a form, after the submission of the form, the image property (like in example "Brochure") is "null", even if set it before submit.
$entity->setBrochure(new File($this->getParameter('brochures_directory').'/'.$entity->getBrochure()));
So it is not possible to decide if the user really want to remove the image or if he wants to keep it.
Did I forgot something or how is it possible to correctly handle the image?
Thank you for your answers!
Best!
It's due to HTML specifications: a file input can't be pre-filled.
A solution is to put another input submit with a different name (different than the default one). Only the button/input "clicked" by the user will be sent.
Detect it in the request; if exist, delete your file data.
And, in your view, display the original name (and/or size, type... whatever your want) near the input file.
Has anyone faced this feature request and were able to resolve it? We have a webapps that is capable of creating a form as a template. That template will basically be called and user will need to fill out the form before it got push into the db. So the form is created directly inside the application and the fields, labels and variables are all defined when the form is created by user using the apps. Since the form is always going to be changing, I can't hardcode the activity in android and have to create it manually and recompile every time a new form is created. Is there a way for us to read the label, variables setting that's stored in db either in XML format or called as JSON and build the form dynamically everytime the form is called via android? Am I making any sense? Please advise?
Yes. Everything you do in XML (view creation, positioning etc) can be done dynamically via code as well.
A simple way would to be to put a single ScrollView with a single LinearLayout inside it. Then in your activities onCreate(), you can read your JSON or XML file just like any other file (you can store this is assets folder or maybe query it from your backend). Then depending on your variables you can initialize and add TextViews and EditText's to the LinearLayout. The ScrollView will expand infinitely to accommodate all your form elements.
Just make sure you don't do any long-running operation such as querying from your backend or reading from your file in the main UI thread. Another caveat is that if ScrollView does not recycle views and putting too many views in it (say more than 20) can make your application run out of memory and slow down/crash.
You can create a form in relative layout having all the fields/view you require in XML, then on Runtime in code According to your label name in db or whatever you are using, you can hide/show the fields/view which are needed dynamically. This way you can preserve the position and setting of each field as when 1 view is hidden other views are going to take its position.
Not really sure where to start on this one and a day of google searches hasn't helped much.
I am working on a submission form where my logged in users can submit data in form fields and attach a number of files. These files should be available to the users across many submissions so as not to clog up my database with duplicate files and for user convenience not having to reupload files many times. The files will be mostly PDFs and word docs.
My question is, what is the most elegant solution to letting my user select a previously submitted file for their current submission and to "attach" or associate that file with multiple submissions? Some drop down box that shows previous uploads seems best and if you agree any code snippets would be super helpful.
I've decided to store the document files as blobs in their own table. I'm running php and MySQL on Linux with godaddy.
Thanks for advice on where to look for code samples in advance. Just haven't been able to find what I'm looking for. Is JavaScript necessary here?
A better way to handle file uploads is to simply store the file-name (which should be generated as unique) in the database and store the actual file in a directory. That way, you won't have this issue of storing it in a BLOB. Is there any reason you are doing that over this method?
Now, if you output a SELECT form element with a list of filenames stored in the database, a user can simply select one and all you need to do is store that filename in the new row. Then, all rows that point to that file name will point to the same file, with no need to upload it.
If you want to allow multiple file uploads or "attachments" in this case, then you are going to need to create a one-to-many relationship in the database. Each submission row will have many rows in another table that point to it, all referencing the corresponding files uploaded. Such that any submission can have zero, 1, 2, or more files attached. If they select files that already exist, great, just copy the username as stated above. IF its a new file, then you should upload that file and add its name to the database.
Javascript isn't required but it would be nice - to add interactivity to your form. If you want to allow for a user to click say, "Add New File", and have a new file upload form element appear.
Start with a a form. Add a select with the list of files associated with that user. Add another form element that allows for file upload. Have all of your other stuff as normal.
On page view, populate the select with the filenames and put the row IDs for that file in the <option value="file_id_xxx">....
In your server script, detect if a file was uploaded; if so, complete the process of storing the file and set the file reference as the associated file for the submission; if not, check that a file was selected from the dropdown and if so, save the reference from the select with previous uploaded files with the submission instead.
Javascript may help in disabling the select or file upload input, depending. But it's not necessary.
I, have successfully implemented uploadify script into my app, files are being uploaded to /web/uploads folder.
I have entity Order witch can have multiple attachments OneToMany-unidirectional relation to File entity, uploadify is a part of Order form.
Now, I would like to transform ulpoaded files into File entity presisted to DB, and set it as related to Order that was created with form.
I suppose I have to add some kind of form ID to Order entity and persist it to DB, so uploadify can send this ID and I'll know witch files are related to witch form instance (Maybe use of CSRF token?)
In general, I have no clear idea of how to implement this feature, my english isn't very good, hope everyone will understand my intentions, I'll be thankful of any help or hints on implementation.
I have done this like that:
Each Order entity on construct gives an unique ID base64_encode(microtime()) witch is persisted into DB, then on files form I get this ID from DB and pass it with uploadify postData, them I have clear link witch file was uploaded to witch Order