Pete Posted October 10, 2015 Share Posted October 10, 2015 Hi guys and gals I've created a backend module that essentially just loads in a template and its fields and this saves fine with file fields. My issue is on that page I've created a modal window that also does the same with some other file fields and these get created in the DB with a creation date of 1st Jan 1970, +10 seconds (so basically the Pagefile::createdTemp constant). Next time I go to view this modal window with the files in, the files are deleted: Pagefiles: Removed 'field_name' temp file(s) for page /admin/cases/43/file_name.pdf So it seems that files saved by the modal have no date set, which is confusing as the modal page is saved, whereas the parent page - using near-identical code - saves the files with a created date. The code used is this (more or less): if($this->config->ajax && (isset($_SERVER['HTTP_X_FIELDNAME']) || count($_POST))) { $subfiles= $this->input->get('subfiles') ? true : false; // If we're dealing with a file submitted through the SubFiles modal if ($subfiles) { $this->pageContext = $this->pages->get('id=' . (int)$this->input->get('subfiles') . ', include=hidden'); // else it's the parent page the modal was opened on } else { $this->pageContext = $this->pages->get($this->input->urlSegment2)->child('template=attachments, include=hidden'); } $this->pageContext->setTrackChanges(true); $this->input->get->id = $this->pageContext->id; // ProcessPageEdit expects a GET or POST called 'id' $this->pageEdit = $this->modules->getModule("ProcessPageEdit", array('noPermissionCheck' => true)); $this->pageEdit->setTrackChanges(true); $this->pageContext->trackChange($_SERVER['HTTP_X_FIELDNAME']); return $this->pageEdit->ajaxSave($this->pageContext); } Any ideas? It's really difficult to explain, so hopefully someone knows what I'm talking about Link to comment Share on other sites More sharing options...
Pete Posted October 10, 2015 Author Share Posted October 10, 2015 Setting the field to overwrite seems to skip the draft status on file fields introduced here: https://processwire.com/blog/posts/processwire-2.5.7-core-updates/ which works around my issue. What I still don't understand is why when saving the page with the file field it's no changing them from draft file status to published (putting a created date in the "created" column for the file in the DB). Link to comment Share on other sites More sharing options...
Pete Posted October 10, 2015 Author Share Posted October 10, 2015 Duh, turn debug on - it helps! Because my custom form render function was skipping some fields in certain scenarios, one of them isn't there when another one is trying to use it as a dependency. Whoops! Should have this wrapped up in 5 mins - should have realised about 3 hours ago Link to comment Share on other sites More sharing options...
Pete Posted October 10, 2015 Author Share Posted October 10, 2015 Hmm... now when I save the debug error is gone, but instead of putting in a created date in the table for that file, it just deletes it! Link to comment Share on other sites More sharing options...
kongondo Posted October 10, 2015 Share Posted October 10, 2015 Things in a modal window or being processed via ajax are many times notorious to debug. I haven't looked at your code much but have you tried debugging every step in your modal window's code using the console, to confirm values are actually being set correctly? Something like.... $subfiles = $this->input->get('subfiles') ? true : false; $data['message'] = $subfiles; echo json_encode($data); exit; Link to comment Share on other sites More sharing options...
Pete Posted October 11, 2015 Author Share Posted October 11, 2015 I ended up ripping apart my code and starting again The original version was based on an older version of Fredi, so I went back and found that Apeisa was doing something totally different there now. Sure enough, adapting the newer Fredi code for my purposes worked well. It also gave me some good ideas for quick custom admin forms too but I don't think there are enough hours in the day to work on all these ideas unfortunately 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now