pwFoo Posted January 2, 2015 Share Posted January 2, 2015 As described at FormHelper module topic create forms based on template object (with a "fake page") stops working with PW dev Fatal error: Exception: New page '/pw//' must be saved before files can be accessed from it (in /volume1/web/pw/wire/core/PagefilesManager.php line 260) #0 /volume1/web/pw/wire/core/PagefilesManager.php(251): PagefilesManager->___path() #1 /volume1/web/pw/wire/core/PagefilesManager.php(211): PagefilesManager->path() #2 /volume1/web/pw/wire/core/PagefilesManager.php(67): PagefilesManager->createPath() #3 /volume1/web/pw/wire/core/PagefilesManager.php(55): PagefilesManager->init(Object(Page)) #4 /volume1/web/pw/wire/core/Page.php(1752): PagefilesManager->__construct(Object(Page)) #5 /volume1/web/pw/wire/core/Pagefiles.php(74): Page->filesManager() #6 /volume1/web/pw/wire/core/Pagefiles.php(58): Pagefiles->setPage(Object(Page)) #7 /volume1/web/pw/wire/modules/Fieldtype/FieldtypeImage.module(33): Pagefiles->__construct(Object(Page)) #8 /volume1/web/pw/wire/core/Fieldtype.php(390): FieldtypeImage->getBlankValue(Object(Page), Object(Field)) #9 /volume1/web/pw/wire/core/Page.php(817): Fieldtype->getDefaultValue(Object(Page), Ob in /volume1/web/pw/index.php on line 243 Error: Exception: New page '/pw//' must be saved before files can be accessed from it (in /volume1/web/pw/wire/core/PagefilesManager.php line 260) #0 /volume1/web/pw/wire/core/PagefilesManager.php(251): PagefilesManager->___path() #1 /volume1/web/pw/wire/core/PagefilesManager.php(211): PagefilesManager->path() #2 /volume1/web/pw/wire/core/PagefilesManager.php(67): PagefilesManager->createPath() #3 /volume1/web/pw/wire/core/PagefilesManager.php(55): PagefilesManager->init(Object(Page)) #4 /volume1/web/pw/wire/core/Page.php(1752): PagefilesManager->__construct(Object(Page)) #5 /volume1/web/pw/wire/core/Pagefiles.php(74): Page->filesManager() #6 /volume1/web/pw/wire/core/Pagefiles.php(58): Pagefiles->setPage(Object(Page)) #7 /volume1/web/pw/wire/modules/Fieldtype/FieldtypeImage.module(33): Pagefiles->__construct(Object(Page)) #8 /volume1/web/pw/wire/core/Fieldtype.php(390): FieldtypeImage->getBlankValue(Object(Page), Object(Field)) #9 /volume1/web/pw/wire/core/Page.php(817): Fieldtype->getDefaultValue(Object(Page), Ob This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged. I used template based forms to create new pages in the frontend. Is there a way to get image fields working in a form without an still existing page? There was no problem in older / stable PW versions if page is created before the temp uploaded file is added to the page image field (after form process...). In current dev I get the error during form creating before submit. Link to comment Share on other sites More sharing options...
pwFoo Posted January 3, 2015 Author Share Posted January 3, 2015 Is it possible to skip it to get form uploads via template file / image inputfield working? I know I could create and add an image upload field, but it would be great to generate an form based on the template fields without hardcoded parts. It works fine in "older" versions of PW (stable or earlier dev). Link to comment Share on other sites More sharing options...
Soma Posted January 5, 2015 Share Posted January 5, 2015 What is the code you're using here? This was always like this, you first have to create and save a page before you can add files to it. I get that error in all PW versions. I think it also depends a lot how you setup things with the form creation and inputfields, for example $page->getInputfields() PW will try to create get inputfields in context of a page and if there's file fields it requires a saved page with an ID. Link to comment Share on other sites More sharing options...
pwFoo Posted January 5, 2015 Author Share Posted January 5, 2015 With older PW version some month before it works fine with a "fake page" public function fakePage($tpl) { $fakePage = new Page(); $fakePage->template = $tpl; return $fakePage; } and getInputfields() elseif($src instanceof Template) { $fields = $this->fakePage($src)->getInputfields(); } $src is a template object (function param). Tested it with latest dev some days before and now it works no more. I'll check my code and test it again, but it looks like a PW dev change. Is there another / better way to work with "template based forms" (no existing page, because page will be created after form sent / processed). Link to comment Share on other sites More sharing options...
Soma Posted January 5, 2015 Share Posted January 5, 2015 I'm not sure I can follow what you're doing but there was no change I'm aware of. For example this $templ = $templates->get("block-page"); $form = $modules->InputfieldForm; $p = new Page(); $p->template = $templ; foreach($p->getInputfields() as $f) $form->add($f); $content .= $form->render(); ... creates an error ever since in earlier pw2.4 up until latest dev. This for example doesn't give an error for all PW versions: $templ = $templates->get("block-page"); $form = $modules->InputfieldForm; $p = new Page(); $p->template = $templ; foreach($p->fields as $f){ $form->add($f->getInputfield($p)); } $content .= $form->render(); Well not sure I can give a better way since you "just" have to build a form with inputfields and create a page later if there's files (in theory). Well if there's file uploads it makes it a lot harder to figure it all out cause you can't use backend ajax upload etc. but the inputfield file is designed for backend. Link to comment Share on other sites More sharing options...
pwFoo Posted January 5, 2015 Author Share Posted January 5, 2015 Thanks, Soma. I'll try it. With a edit form (existing page) Inputfields ckeditor and image / file works fine. I'll prefered to use those Inputfields also to create a new page So you recommend not to use the (designed for backend) Inputfields? Link to comment Share on other sites More sharing options...
Soma Posted January 5, 2015 Share Posted January 5, 2015 There's no problem with inputfields just creating a from a dummy pages's inputfields , won't work cause its not a existing page. Link to comment Share on other sites More sharing options...
Recommended Posts