-
Posts
1,489 -
Joined
-
Last visited
-
Days Won
43
Everything posted by gebeer
-
Multiple problems with your code. in the last code sample you used InputfieldSelect. Now you are using InputfieldText. The latter will give you a text input and has no method setOptions() you set the options before you define $location $fields->location->$label needs to read $fields->location->label Here is working sample code for a form with location select as only field: // define form /** @var InputfieldForm $form */ $form = $modules->get('InputfieldForm'); // define location first before you can use setOptions() /** @var InputfieldSelect $location */ // you need to use InputfieldSelect here, InputfieldText has no setOptions() method $location = $modules->get('InputfieldSelect'); $location->attr('id+name', 'location'); $location->label = $this->_($fields->location->label); $location->required = 1; $location->attr('required', 'required'); // build options array $optionsArray = $pages->findRaw('template=location', 'title'); // set options to the select field $location->setOptions($optionsArray); // add field to your form $form->add($location); echo $form->render(); // will print out the markup for the whole form I left out the whole fhSanitzer stuff and the hook. Let's go step by step and first make the inputfield work. You need to adjust this to the rest of your code. If you want to have a standalone field, not inside a form you would do something like this: $location = $modules->get('InputfieldSelect'); $location->attr('id+name', 'location'); $location->label = $this->_($fields->location->label); $location->required = 1; $location->attr('required', 'required'); // build options array $optionsArray = $pages->findRaw('template=location', 'title'); // set options to the select field $location->setOptions($optionsArray); // print markup echo $location->render(); This will give you markup like: <select id="location" class="required" name="location" required="required"> <option value=""> </option> <option value="1001">Location 1</option> <option value="1002">Location 2</option> <option value="1004">Location 3</option> </select>
-
FieldTypeOptions gives you different UI and stores data in a different way. If you just need a checkbox, I'd go with InputfieldCheckbox. Less overhead.
-
You would use $county->setOptions($optionsArray) to populate the select options. Example: /** @var array $optionsArray */ $optionsArray = $pages->findRaw('template=basic-page', 'title'); // returns an array with page ids as keys and page titles as value $county->setOptions($optionsArray); // each option will have value="{pageID}" and label page title You need to adjust the selector to your needs.
-
Yes it can, but not via the field settings in the GUI. You can put this hook code in site/templates/admin.php above the require($config->paths->core . "admin.php"); line: // sets field checkbox to checked on new pages with template basic-page $wire->addHookAfter('Pages::saveReady', function (HookEvent $event) { /** @var Page $page */ $page = $event->arguments(0); if ($page->isNew() && $page->template->name == 'basic-page') { $page->checkbox = 1; } }); You just need to adjust template and field name. Everytime a new page with that template is created the checkbox will be checked by default. If you have TracyDebugger installed, you can do this with a one-liner in the Tracy console in the backend: $pages->find('template=basic-page, include=all')->each(function($p) { $p->setAndSave('checkbox', 1); });
-
@Heinzregarding communication via http-requests with the PW backend for retrieving, storing, patching etc with a Rest-ful approach you could use this module: https://processwire.com/modules/app-api/ For building custom frontend forms there is an excellent thread: It is a long thread but a nice read for bored people ?
-
I personally can live with this behaviour but still would consider it a bug since it is unexpected. Inputfields should open/close independently whether they are in the same row or not.
-
Your textformatter seems like a valid solution. Although I am not sure whether the regex for getting the file URL is 100% reliable. I'm not a regex prof. But in general it is not a good idea to rely on regex for parsing HTML. You could use PHP's SimpleXML to parse and replace the href attributes. Adapt something like this: https://stackoverflow.com/questions/27326066/simplexml-php-change-value-from-any-node But I think you don't even need a textformatter for the task. A simple hook will intercept all URLs to PDF files and return the desired URL under /downloads/. Place this in site/init.php <?php namespace ProcessWire; // intercepts all file URLs and rturns URLs in desired format. wire()->addHookAfter('Pagefile::url', function(HookEvent $event) { /** @var PageFile $pageFile */ $pageFile = $event->object; if(strtolower($pageFile->ext) === 'pdf') { $pageId = $event->page->id; $event->return = '/download/' . $pageId . '/' . $pageFile->basename; } }); Now all URLs to PDF files will have the desired format. Even when you add a link to a file inside CKE editor, the desired URL will inserted.
-
Hello and welcome to the forum! Please try to post in English if possible. Thank you. Is your code inside a function? If not, you need to echo json_encode($res) return json_encode ($res); // inside function echo json_encode ($res); // not inside function Do you see the output from var_dump() in the response in browser dev console?
- 1 reply
-
- 3
-
-
You are writing that you want to sort results by artist. But in your sort selector you try to sort by help_roles. Is it help_roles, you want to sort by? Or is it that you want to filter results by help_role "artist"? Please clarify.
-
If I understand correctly, you want to publish all draft versions of pages with a single click? For drafts you are using ProDrafts module? You might want to ask Pro module related questions in the dedicated VIP support forum.
- 1 reply
-
- 1
-
-
Use of AdminThemeUikit doesn't find the directory
gebeer replied to Nahuel Tori's topic in General Support
Hello and welcome to the forum! In PW you can override core modules by copying them from wire/modules to site/modules. If you have multiple copies of a module installed, you can go to Modules->Configure->AdminThemeUikit and choose there which copy to use. If you don't have this choice in the Module Edit Screen, follow these instructions: Copy wire/modules/AdminTheme/AdminThemeUikit to site/modules/AdminThemeUikit and then in the backend main menu do a Modules->Refresh, you will get a notification that AdminThemeUikit has multiple files installed in different locations and it lets you choose which file location to load the module from. You can do this and choose the files in wire/modules/AdminTheme/AdminThemeUikit. After that you can delete the site/modules/AdminThemeUikit folder and the warning should be gone. -
Using config data for the module elsewhere
gebeer replied to gornycreative's topic in Module/Plugin Development
just to make sure, did you copy/paste this from your code? There is a typo "Imput", note the "m". It should read "getModuleConfigInputfields" To retrieve module config data from anywhere you can also use https://processwire.com/api/ref/modules/get-config/ -
Here you are referring to ProcessModules. These provide custom pages in the admin. For an example see https://processwire.com/modules/process-hello/ and I also can strongly recommend the excellent blog post about ProcessModules linked by @BillH This is correct. You can read all about module configuration at https://processwire.com/blog/posts/new-module-configuration-options/ with examples both for the "old" and "new" way to implement your custom configuration fields. There is no settings button on the module's detail page. Once you have implemented input fields for module configuration, they will appear underneat the module information. All configurable modules are also listed in the admin menu under Modules->Configure When you are new to module development, the available classes can be quite confusing. But once you try and build a module yourself everything will get clearer. If you want to build custom pages in the admin, use a process module (https://processwire.com/modules/process-hello/). If you want to add general functionality, use a "normal" module (https://processwire.com/modules/helloworld/). This is because the API docs are auto-generated from the PW code. Since ConfigurableModule is an interface and not a class, the documentation for it is not being picked up by the script that generates the docs. But you have the path to the file in the core that defines the interface and there you have extensive documentation https://github.com/processwire/processwire/blob/master/wire/core/ConfigurableModule.php
-
Great that this is working for you. Please share your additions to make it work with pageFileSecure. I never used that but would be interested in seeing how you implemented it.
-
DOn't think this will make a big difference. Browsers will still handle it inconsistently.
-
Support for config-localhost.php file (or similar)
gebeer replied to Lance O.'s topic in Wishlist & Roadmap
There is no built-in way ATM. But you can find some nice implementations here: -
To get more control over what happens in the user's browser, you can output your PDFs through a specific template file. Example implementation: Create a new template "pdf", in the URLs tab allow URL Segments Create a hidden page named "pdf" under home with that template. URL for that page will be: "/pdf/" Change text links for the PDFs to a format like "/pdf/{$pageId}/name-of-pdf-file.pdf" Sample code to create text links: /** @var Page $page page that the PDF file lives on */ /** @var Page $pdfPage page that ouputs the PDF file */ $pdfPage = $pages->get('template=pdf'); /** @var PageFile $pageFile object that holds the PDF */ $link = $pdfPage . $page->id . '/' . $pageFile->basename; // example result: /pdf/1234/name-of-pdf-file.pdf Now in site/templates/pdf.php you can use URL segments logic to retrieve and output the pdf if ($input->urlSegment1 && $input->urlSegment2) { $pageId = $sanitizer->int($input->urlSegment1); $baseName = $sanitizer->filename($input->urlSegment2); /** @var PageFile $pageFile object that holds the PDF */ $pageFile = $pages->get($pageId)->file_field->getFile($baseName); if ($pageFile) { $filePath = $pageFile->filename; // see https://processwire.com/api/ref/wire-file-tools/send/ for more options /** @var Files $files PW Files API */ if($filePath) $files->send($filePath, array('forceDownload' => false)); } } Instead of sending the file directly to the browser, in pdf.php you could implement https://pdfobject.com/ to embed it for every browser
-
What code are you using to display the PDF / send the PDF to the browser, are you using $files->send()? With that method you have control over the headers. Firefox uses Mozilla's PDF.js for PDF display. If you want to have a consistent display of PDFs across browsers you might want to consider implementing it on your site. This might of interest: And this: https://pdfobject.com/
-
You can use the User::changed hook to do what you want (see https://processwire.com/api/ref/wire/changed/). Put this in site/ready.php: $wire->addHookAfter('User::changed', function ($event) { if($event->arguments(0) === 'pass') { $user = $event->object; $this->wire->log->save('password-changes', "User $user->name has changed their password"); } }); Now everytime a user changes their password, it will be logged to Setup->logs->password-changes. You can do similar thing with roles if($event->arguments(0) === 'roles') { $user = $event->object; $oldRoles = $event->arguments(1); $newRoles = $event->arguments(2); // code to compare $oldRoles/$newRoles // write to log } If you want to have that information in the session log, just do $this->wire->log->save('session',...)
- 1 reply
-
- 7
-
-
I don't know where your input comes from. I would take care at the source that there is no broken HTML in the first place. I already provided some sample code how you can do this above
-
If you are building the formData object like you do it, you have to take care about url encoding yourself. Only if you pass in the form when building formData, encoding is taken care of. Have a look at https://processwire.com/api/ref/sanitizer/ and try different methods. But I'm afraid that the sanitizer methods that handle HTML tags will always run into problems when there is broken HTML. So you should take care in the first place that HTML is not broken if possible.
-
@fruid can you confirm that your data is urlencoded? You might want to have a read over at MDN https://developer.mozilla.org/en-US/docs/Learn/Forms/Sending_forms_through_JavaScript . Especially the part where they are using encodeURIComponent() to encode the data. What do you mean by broken HTML. Do you have an example? Passing an email, do you mean the HTML or text content of an email or an email address? In your code you are taking all form fields, putting them into an object, then converting that object into a JSON string and assign that string to a property 'content' of a formData object and send that object via XHR. To me it looks like what you actually want to do is send JSON data to the server. If this is the case, you could omit the step of assigning your JSON string to a formData object and use request header content-type 'application/json' instead. No need for url encoding the data then. Simplified example: // create an object const content = { formfield1: 'value', formfield2: 'value' } // open request xhr.open('POST', 'yourURL') // set Content-Type header xhr.setRequestHeader('Content-Type', 'application/json') // send rquest with JSON payload xhr.send(JSON.stringify(content)) On the PHP side where you receive the request, you can get the JSON data like this: // Takes raw data from the request $json = file_get_contents('php://input'); // Converts it into a PHP object $data = json_decode($json);
-
Module Concept for Error Reporting via Email
gebeer replied to gebeer's topic in Module/Plugin Development
Good find, thank you. By default PW only logs errors, exceptions, not warnings or notices. So the available types would be "error" and "exceptions". Is there a way of telling PW to also log warnings and notices? -
@kongondo I have a MM field "icons", allowed media types images. When adding an image via "Add Image", the MM modal pops up and shows all files of type image. I'd like to automatically apply a filter (profile) so that only images with tag 'icon' and extension svg are being listed. Otherwise editors have to manually choose a filter each time. "Add Image" issues a request which contains a property "filters". But in the field settings I don't see how I could configure which filters to apply. Is this scenario possible at all?
-
Hello all, I'm working on a concept for a module that sends error reports via email to different recipients based on different error levels (notice, warning, error) and I don't know yet how to best tackle this. It would be preferable if I could use PW internal classes, functions. I had a read through https://processwire.com/blog/posts/debugging-tools-built-in/ and especially the logging section. But looking at related classes like FileLog and WireException, it doen't seem like one can hook into them. I'm quite tempted to use NetteTracy, like TracyDebugger does. It seems like it can do what I want https://tracy.nette.org/en/guide#toc-production-mode-and-error-logging. PW is writing errors/exceptions to the log, I just wouldn't know how to tap into this, especially for different log levels. If anyone can point me in the right direction it would be much appreciated.