pwFoo Posted February 8, 2015 Author Posted February 8, 2015 Hi JoZ3, could You provide your code which uses FormHelper and your PW version?
pwFoo Posted February 8, 2015 Author Posted February 8, 2015 You shouldn't use FrontendContentManager (FCM) because it's unstable and after some changes at PW dev FormHelper amd FCM won't work as expected in future releases. At the moment I remove the FormHelper dependency for FrontendUserLogin and FrontendUserRegister modules because of the native support for form fields as array data. Maybe I'm rewrite / redesign FormHelp to simplify form process and file handling, but have to think about first. After current work is done, I'll start a new try to build a FCM module. If you need a module to frontend edit pages you should try Fredi for example.
pwFoo Posted February 8, 2015 Author Posted February 8, 2015 Do you try to edit or create a page with FCM? I'll take a look. Maybe I'll release a fix to make it useable until I rewrite it...
pwFoo Posted February 12, 2015 Author Posted February 12, 2015 Hello JoZ3, sorry for the delay... I installed both (FormHelper and FrontendContentManager) via PW backend Navigate to Admin -> Modules -> New Fill in FormHelper (second time FrontendContentManager) as ModuleClassName Click Download and Install No errors during install the current module versions. Could You try it again?
pwFoo Posted February 12, 2015 Author Posted February 12, 2015 It's fine if Fredi works for you FormHelper and FrontendContentManager need some work to be compatible with the latest dev, but at the moment I have some other projects. 1
pwFoo Posted February 12, 2015 Author Posted February 12, 2015 Because of needed redesign and rework most of the code will be changed / optimized Test today was with PW 2.5.18 dev and PHP 5.5.21.
BitPoet Posted February 13, 2015 Posted February 13, 2015 Hi, I have this strange error when try to install: Parse Error: syntax error, unexpected '=', expecting ')' (line 276 of /home/myserver/public_html/site/modules/FormHelper/FormHelper/FormHelper.module) This error message was shown because you are logged in as a Superuser. Error has been logged. My php version is 5.4.35 This is because of assignments inside function calls, which should be avoided at all costs, e.g. in line 329 of FormHelper.module (279 is the other one): if (!empty($files = $this->files[$fieldName])) { Strict mode barks on this because assigning to passed variables like this breaks pass-by-reference. Consider these two snippets: $x = 1 byref($x); echo $x . "\n"; function byref(&$val) { $val = 3; } This correctly echoes "3". Now lets do the same and assign $x in the function call: byref($x = 1); echo $x . "\n"; function byref(&$val) { $val = 3; } Now our output is "1", which is of course not what we would have expected after assigning to a variable passed by reference - our assignment has turned the pass-by-reference into a pass-by-value. The original line should be written as: $files = $this->files[$fieldName]; if (!empty($files)) { 1
pwFoo Posted February 19, 2015 Author Posted February 19, 2015 Thank's, will be changed in the next release, but a major redesign is planned.
pwFoo Posted February 24, 2015 Author Posted February 24, 2015 (edited) New testing branch (readme file includes an example usage / template fiel): https://bitbucket.org/pwFoo/formhelper/src/14d3cf18768b?at=testing *UPDATE* Supports forms based on Page Template Fields InputfieldForm (form fields) and should also work with array (PW 2.5.5+). You can define optional field settings callback (additional field processing via dynamic function) set / clear form field value or get unformatted page field value skip a field (not added to form) ignore a field (no additional field processing, skip field after form process in getForm() function) set the CKEditor pwImage plugin page id (plugin image source) set a sanitizer to field and you will get a sanitized value with getValue() function FormHelper prepare file fields and give you a file array to work with (path + filename) Edited February 25, 2015 by pwFoo 1
pwFoo Posted February 28, 2015 Author Posted February 28, 2015 New testing branch commit with a shortcut to combine source() with create() // Set source, optional $fhOptions and $refPage and chain it with form render $fh->form($source, $fhOptions = null, $refPage = null)->render(); Thought about field save / create page feature, but should be done with another module because it would unnecessary overhead if you sending a mail or something else. Current version:https://bitbucket.org/pwFoo/formhelper/src/99d0ea09a8012446fd8fba71e7b34ede319551ad/?at=testing
pwFoo Posted March 1, 2015 Author Posted March 1, 2015 (edited) merged testing to the master branch as version 0.5.1. Added a state() function to get the form submit state. Edited March 1, 2015 by pwFoo
pwFoo Posted March 9, 2015 Author Posted March 9, 2015 Bump version to 0.5.3 Replaced fhOption "callback" with "callbackPrepare" (executed before field added to form) and callbackProcess (executed after form process to do additional processing). Examples callbackProcess // You can use "$field" (current field object) and "wire()") $fhOptions['title']['callbackProcess'] = function ($field) { // Modify a form field (wire('fh') is the FormHelper instance / object which is added to "wire()") wire('fh')->form->get('body')->error('CALLBACK-ERROR to another field...'); // modify current field by callback $field->error("CALLBACK {$field->name} ERROR"); }; callbackPrepare $fhOptions['title']['callbackPrepare'] = function ($field) { // replace field value (executed after clear / value / unformatted feature) $field->value = "TEST PREPARE CALLBACK"; // or skip the field just before it will be added to the form... wire('fh')->fhOptions($field, array('skip' => true)); }; FormHelper creates forms by Page, Template, Fields, Inputfields, InputfieldForm (fields) or an array with field data with 371 lines of code. Maybe it could be separated into a basic form process module and an sub module to handle additional features (Template based form with file upload, CKEditor image plugin, ...) but I don't know if it should be necessary. 1
pwFoo Posted April 1, 2015 Author Posted April 1, 2015 (edited) While look deeper and deeper inside Processwire and hooks I'll have a new reduced FormHelper testing branch... FormHelper TESTING branch extends InputfieldForm. So you can use the pw form api with some extensions. How FormHelper could be used. // Load FormHelper module and also set wire('fh') variable $fh = $modules->get('FormHelper'); // Create a (first) form $form = $fh->create(); // Add some fields to the PW form object // Add default sanitizer $field->fhSanitizer = 'text'; // Add preprocess and processed callbacks $field->addHook('fhCallbackPreprocess', function($event) { // called before form processing }); $field->addHook('fhCallbackProcessed', function($event) { // called after form processing }); // Your callbacks need more arguments than $event or $this (class inside the callback is written)? Set additional arguments as array $field->fhCallbackArgs = array($arg1, $arg2); // access arguments via $event->arguments // process form // adds submit button, callback execution, CSRF check + reset and processInput() // error handling, also WireUpload errors if ($form->fhProcessForm()) { // true = submitted without errors // false = submitted with errors // null = not submitted // Get value sanitized (fhSanitizer) echo $form->fhValue($fieldname); // Get value sanitized with given sanitizer echo $form->fhValue($fieldname, 'pageName'); // Get raw value and ignore fhSanitizer setting echo $form->fhValue($fieldname, false); } Submit button is added in the beginning of the fhProcessForm() method. Get the submit button to modify it previously... // Get submit button $submitBtn = $form->fhSubmitBtn; Missing features will be moved to FormHelperExtra (if needed) pwImage plugin InputfieldCKEditor stuff (hidden page id field...) form by template / type "Field" fields with a hidden storage page to get file uploads working without saved page ... FormHelper testing branch https://bitbucket.org/pwFoo/formhelper/src/2a7e7261cf347622a82612d381cabdc63bed4c08?at=testing *UPDATED* Edited April 2, 2015 by pwFoo 1
pwFoo Posted April 2, 2015 Author Posted April 2, 2015 Updated post above. Also updated the Bitbucket repo link callbacks moved to PW hooks additional callback arguments supported
pwFoo Posted April 7, 2015 Author Posted April 7, 2015 New version 0.7.1 and added the FormHelperExtra (proof of concept!) module to handle removed features. 1
naldrocks98 Posted May 20, 2015 Posted May 20, 2015 hi pwFoo this error i shown in my module? here's the part in the module when it becomes error public function ___install() { $fg = new Fieldgroup(); $fg->name = self::$tempUploadPage; $fg->add('title'); $fg->save(); $this->message('FormHelperExtra temp file storage Fieldgroup "' . self::$tempUploadPage . '" created.'); $t = new Template(); $t->name = self::$tempUploadPage; $t->flags = Template::flagSystem; $t->noParents = 1; $t->fieldgroup = $fg; $t->save(); $this->message('FormHelperExtra temp file storage Template "' . self::$tempUploadPage . '" created.'); $storage = new Page(); $storage->template = $this->templates->get($t); $storage->name = self::$tempUploadPage; $storage->parent = $this->pages->get('/admin/'); $storage->title = self::getModuleInfo()['title'] . 'StoragePage'; // <--- here's the error part $storage->addStatus(Page::statusHidden); $storage->save(); $this->message('FormHelperExtra temp file storage Page "' . self::$tempUploadPage . '" created.'); } Parse Error: syntax error, unexpected '[' (line 170 of D:\home\www\tfdold\public_html\animalbitecenter\site\modules\FormHelper\FormHelper\FormHelperExtra.module) This error message was shown because you are logged in as a Superuser. Error has been logged.
adrian Posted May 20, 2015 Posted May 20, 2015 That's a limitation of PHP before 5.4 http://php.net/manual/en/language.types.array.php "As of PHP 5.4 it is possible to array dereference the result of a function or method call directly. Before it was only possible using a temporary variable." It's an easy fix to support PHP 5.3 though: $moduleInfo = self::getModuleInfo(); $storage->title = $moduleInfo['title'] . 'StoragePage';
pwFoo Posted May 20, 2015 Author Posted May 20, 2015 Thanks! I'll update this soon. I haven't a php 5.3 test env. So I'll post here after an updated version is available for testing.
pwFoo Posted May 20, 2015 Author Posted May 20, 2015 Released 0.7.2 removed FormHelper php 5.4 dependency (historical, have its seeds in an old version based on anonymous functions instead of PW hooks) FormHelper (0.1.1) php 5.3 compatibility update (thanks to Adrian and naldrocks98 for testing / help / feedback) But I have to install an php 5.3 test vm for compatibility testing soon...
pwFoo Posted May 31, 2015 Author Posted May 31, 2015 Updated to version 0.8.1 Changed FormHelperExtra usage Added documentation at bitbucket repo wiki
pwFoo Posted June 1, 2015 Author Posted June 1, 2015 Version 0.8.2 Moved methods from FormHelperExtra to Formhelper because could be used without FormHelperExtra. jsConfig() and fhCkeditorImagePlugin() needed by InputfiedCKEditor load admin (backend) form styles
heldercervantes Posted June 2, 2015 Posted June 2, 2015 I'm trying this out and having some trouble. In my usecase, I want to generate a form based on a template. Here's my code: $fh = $modules->get('FormHelper'); $form = $fh->create($templates->get('basic-page')); echo $form->render(); This is outputting a form without fields except for a hidden token. Can't figure out what I'm doing wrong.
pwFoo Posted June 2, 2015 Author Posted June 2, 2015 Your code should work. Tested it here and I get a form. Could you please activate debugging and check the apache log for errors? PW and PHP version?
heldercervantes Posted June 2, 2015 Posted June 2, 2015 Can't find any errors either on the Apache log or PW's. I'm using PHP 5.6.3 and PW 2.5.29 dev. Here's the output I'm getting: <form id="fhForm1" class="InputfieldForm" name="fhForm1" method="post" action="./" data-colspacing="1"><input type="hidden" name="TOKEN1463213210X1433263864" value="fXJQW/rrJn/a1VrW5nGRJXbxA3MrczWb" class="_post_token"> </form>
pwFoo Posted June 2, 2015 Author Posted June 2, 2015 I get an empty form (with submit button and hidden token field) if the template not exists... There was a commit problem yesterday in the evening... Maybe it's not the latest version. Could you uninstall, remove and install it again to be sure it's the latest version / master commit?
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