pwFoo Posted September 26, 2014 Share Posted September 26, 2014 Hello, is there a recommend way how to add / save new pages via frontend? Could I use/ integrate some core modules to do it (field sanitizing and saving)? With my FormHelper module I can create forms from pages and templates. That works fine for edit a page. To add a new page is tricky... Before I execute my save function I have to do some preSave actions (save the fake page! Set parent and name!). Now also add and save pages works... until there is a file / image field... Error: Exception: Invalid image (in /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module line 273) #0 [internal function]: InputfieldFile->___processInputAddFile('tk_passbild_and...') #1 /volume1/web/pwdev/wire/core/Wire.php(359): call_user_func_array(Array, Array) #2 /volume1/web/pwdev/wire/core/Wire.php(317): Wire->runHooks('processInputAdd...', Array) #3 /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module(360): Wire->__call('processInputAdd...', Array) #4 /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module(360): InputfieldImage->processInputAddFile('tk_passbild_and...') #5 [internal function]: InputfieldFile->___processInput(Object(WireInputData)) #6 /volume1/web/pwdev/wire/core/Wire.php(359): call_user_func_array(Array, Array) #7 /volume1/web/pwdev/wire/core/Wire.php(317): Wire->runHooks('processInput', Array) #8 /volume1/web/pwdev/wire/core/InputfieldWrapper.php(436): Wire->__call('processInput', Array) #9 /volume1/web/pwdev/wir Here the page add method which basically works without file / image fields. public function add($parent, $options = null) { // ignore admin pages and check permissions! if ($this->input->urlSegment1 != 'add' || $page->template == 'admin' || !$parent->addable()) return false; $tpl = ($options['tpl'] ? $options['tpl'] : $parent->template); $fh = $this->modules->get('FormHelper'); $fh->createForm($parent, array('clearValues' => true)); // process form $processedForm = $fh->formProcess(); if ($sanitizedForm = $this->checkFormValues($processedForm)) { // sanitizing is skipped with always true! $title = $sanitizedForm->get('title')->value; $page = new Page(); $page->template = $tpl $page->parent = $parent; $page->name = $this->sanitizer->pageName($title); $page->title = $title; $page->save(); $this->pageSave($page, $processedForm, true); } else { return $fh->render(); } } // Set page values and save it... private function pageSave($page, $processedForm, $changed = false) { foreach ($processedForm->children as $field) { if ($field->value != $page->get($field->name)) { $page->set($field->name, $field->value); $changed = true; } } if ($changed) { // Save and reload to show changed page... $page->of(false); $page->save(); $page->of(true); } } Would like to reuse backend page save function (validate and sanitize form values before save the new page). Link to comment Share on other sites More sharing options...
pwFoo Posted September 26, 2014 Author Share Posted September 26, 2014 After loading jquery and set "jsconfig" WYSIWYG editor works fine, but there are some more modules needed to get a full styled form. For example image field? How can I determine and load needed modules to get a full styled form (like backend forms) with autocomplete page reference for example (JqueryCore, JqueryUI,...)? But first problem to solve should be file / image field handling from post above... Error: Exception: Invalid image (in /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module line 273) #0 [internal function]: InputfieldFile->___processInputAddFile('tk_passbild_and...') #1 /volume1/web/pwdev/wire/core/Wire.php(359): call_user_func_array(Array, Array) #2 /volume1/web/pwdev/wire/core/Wire.php(317): Wire->runHooks('processInputAdd...', Array) #3 /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module(360): Wire->__call('processInputAdd...', Array) #4 /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module(360): InputfieldImage->processInputAddFile('tk_passbild_and...') #5 [internal function]: InputfieldFile->___processInput(Object(WireInputData)) #6 /volume1/web/pwdev/wire/core/Wire.php(359): call_user_func_array(Array, Array) #7 /volume1/web/pwdev/wire/core/Wire.php(317): Wire->runHooks('processInput', Array) #8 /volume1/web/pwdev/wire/core/InputfieldWrapper.php(436): Wire->__call('processInput', Array) #9 /volume1/web/pwdev/wir No problem with images during frontend page edit, only during page add... So I think I have to set some more values or change my page presave / save method... Link to comment Share on other sites More sharing options...
pwFoo Posted October 7, 2014 Author Share Posted October 7, 2014 Solved file / image handling (not commited yet). Added file handling to FormHelper module and get add() (create page) working. Link to comment Share on other sites More sharing options...
diogo Posted October 7, 2014 Share Posted October 7, 2014 sorry that you didn't get any answer by now. Glad you managed to solve some things though. Link to comment Share on other sites More sharing options...
pwFoo Posted October 8, 2014 Author Share Posted October 8, 2014 At the moment FrontendContentManager module (dev, unstable) used to edit and add pages as frontend user. Also add and delete images works. CKeditor doesn't work in regular mode. Inline mode ckeditor is loaded, but text isn't saved (save works fine with simple text field without wysiwyg ?!)jsconfig is set and JqueryCore loaded first. Two questions: How should such a module named? (add, edit and optional delete pages as frontend user)? Any better suggestion than FrontendContentManager (short: FCM)? Form (created via form api with own FormHelper module) is unstyled. Inputfield scripts and styles are loaded, but form / fields still unstyled. Are there some more styles and scripts which be used in the admin section to style forms / edit page? Link to comment Share on other sites More sharing options...
pwFoo Posted October 18, 2014 Author Share Posted October 18, 2014 New topic FrontendContentManager. 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