Jump to content

da²

Members
  • Posts

    405
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by da²

  1. 😂 https://www.tomshardware.com/tech-industry/artificial-intelligence/claude-code-deletes-developers-production-setup-including-its-database-and-snapshots-2-5-years-of-records-were-nuked-in-an-instant EDIT, the post-mortem by the developer: https://alexeyondata.substack.com/p/how-i-dropped-our-production-database
  2. Hi, thanks for the explanation. I'll try to explain my actual case, it's more complex and would be easier to manage if I could just invalidate a form field manually. The form has a zip field, zip file contains several files. To make the explanation short, I extract the zip and validate its content, but the validation also requires to know values from the other fields in the form. I think this is the first problem: accessing the other fields (only if they are validated by the form) while validating the zip field. So I have a field "A", form should valid it (basic validation, like "required"), then while validating zip content (another field) and extracting its data I check again field "A" against the zip data. If there's an issue I must invalidate field "A" (but I'm processing zip field) and display an error on this "A" field. In one sentence: I know that field "A" is wrong only when processing zip field. Also this validator seems to make things more complex. I don't want to extract/validate the zip 2 times, once in validator, and once again when form is fully validated (isValid() function) to save values in database. So I should refactor code to store the validated data somewhere to reuse them in isValid() function, this is extra complicated work I want to avoid. Also this is not a light process for CPU, zip can be 500 MB and contain a lot of files to parse (some are also zip to extract again), this is a heavy process and I don't like the idea of doing this 2 times. Telling the form "this field is not valid and should display this error message" is way more simple and doesn't necessitate extra code, I just have to return an error code from the high level class that process data and invalidate one or another field. If you have an idea to avoid processing zip 2 times and without adding extra work, it would be welcomed, hope my explanations are clear (I'm not sure 😆). Actually I'm displaying error message on form result page, and in case of error the user has to fill again the whole form. My client is OK with this since this form is mainly used by himself, but I'm not happy because this is also a public form that a user could use, and having the whole form reset in case of error is a bad design. This is the actual code in template php: $form = new UploadSolveForm(); if ($form->isValid()) { $uploadFilePath = $form->getSolveFilePath(); $tagsText = trim($form->getValue('tagsFinalInput')); $tags = $tagsText ? explode(',', $tagsText) : []; $parseCommand = new ParseSolveUploadCommand( $uploadFilePath, trim($form->getValue('groupName')), $tags, RoomType::from($form->getValue('room')), boolval($form->getValue('isSpaceKo')), $form->getValue('subtreeVilainPosition') ? TablePosition::from($form->getValue('subtreeVilainPosition')) : null, $form->getValue('subtreeVilainAction') ? PlayerAction::from($form->getValue('subtreeVilainAction')) : null, $form->getValue('subtreeHeroPosition') ? TablePosition::from($form->getValue('subtreeHeroPosition')) : null ); if (!$parseCommand->execute()) { // I would like to do: // $errorCode = $parseCommand->getErrorCode(); // if ($errorCode == ParseSolveUploadCommand::SOME_ERROR){ // $form->setError('a field name', 'errorMessage'); // } else if($errorCode == ParseSolveUploadCommand::SOME_OTHER_ERROR){ // $form->setError('another field name', 'errorMessage'); // } if ($parseCommand->getUserErrorMessage()) NoticeManager::add($parseCommand->getUserErrorMessage(), NoticeType::ERROR); // Will display an alert box on form result page else NoticeManager::add(__("Une erreur s'est produite, merci de contacter un administrateur.", COMMON_TRANSLATION_DOMAIN), NoticeType::ERROR); } else { $parseCommand->getReport()->noticeUser(); } } Thank you for your interest. 🙂
  3. @Juergen OK I'll try with the custom validation rules. Need to check how it works more deeply. Actually I have a specific case, but I often use this for several scenarios. A very simple example would be a form where user must enter the username he is using in a game (I developed a site to manage competitions in sim-racing games), and we need to verify that it's not already used by another user. If already used, invalidate the form and display an error on the username field.
  4. This is not related with this field, I removed it, and still the method setErrorMessageToField() doesn't work the second time the form is submitted. Looks like it's related with css classes you add to the alert div. It seems you're adding both alert_successClass and alert_dangerClass to this div, that's why it melts red and green (I'm using UiKit).
  5. Hi @Juergen Thank you very much, I updated the module but there are some issues. If I try to valid a form with a required field (InputFile) without filling it (and without calling setErrorMessageToField()): It's not happening with the previous version I was using (2.2.55). I'm trying the method to set an error on a given field, it's working but message text color is still green at top of form: Strange error management when submitting the form several times using setErrorMessageToField() (video to make it clear) : I fill the InputFile required field and an optional one. I submit. setErrorMessageToField() triggers the error. The InputFile required field has been emptied (was already the case in previous version, is it expected?). I submit again. Issues: the form is fully emptied. setErrorMessageToField() has no effect the second time. InputFile required field is empty but no error. (if I had filled it again, the 2 points above are still there) I also have a request, could you make the setErrorMessageToField() first parameter a string, so I can pass a field name? Or supporting both name and field reference if you prefer. Usually the form fields are created in a form class and are not stored as class members, it's why it's more convenient to use field names, like with getValue() method. Thank you. 🙂
  6. I never use AI to generate code, my case was more about understanding an issue and how the framework works. The kind of issue that is hard to find a solution with a Google search. The fun fact is that this issue never existed, that was a misinterpretation by myself, but all chatbot (ChatGPT, Claude and the framework dedicated chatbot) said this was a "very common issue", and gave me very bad solutions, all bullshit. 😂
  7. When a developer says he is more productive with AI, I think about this study from early 2025. 🙂 Maybe this is improving with new chatbot models, but in my experience I already lost a lot of time this year because of AI driving me in the wrong direction when using a framework I had zero knowledge with. I'm very cautious with AI, and use it only in some cases I know it's good enough. https://metr.org/blog/2025-07-10-early-2025-ai-experienced-os-dev-study/
  8. My way to upload local site to production is using basic Linux tools. I'm on Windows but with a WSL console running Debian, you have access to all tools. First I use Ant to synchronize files from my code to a separate local directory (Ant is a set of tools that you use by creating a simple XML describing tasks), I exclude some files or directories (like PW cache and logs...), automatically increment a version number, replace some variables in some files (like site version/build number, debug variables...)... Then an rsync command send the code to the server. Deploying a site update is then only executing this script and waiting a few seconds. 🙂 I exclude site config.php because some values change from production server (database credentials, debug=false|true, Stripe identifiers...). Example of a deploy script (very simple but powerful stuff ^^): #!/bin/bash # Directory where Ant project synchronize files. build_dir=./target/processwire/ echo "=> Executing ANT project..." cmd.exe /c build-processwire.bat buildOk=$? if [ $buildOk -ne 0 ]; then echo "ANT build failed, stopping script." exit fi read -p "Press enter to update PRODUCTION server, ctrl+c to cancel." echo "=> Copying files to web server..." rsync -avh --delete-delay --include-from=deploy-includes.txt --exclude-from=deploy-excludes.txt --chown=linux_user_name:linux_user_group -e ssh $build_dir linux_login@server_ip:/var/www/path_to_productionsite/ If this is the first time I deploy this project, or if this is a staging server (not production) and I want to reset database at every deploy, I add this line, it copies my local PW database to the server: echo "=> Copying database to production" /mnt/e/xampp_php8.2/mysql/bin/mysqldump.exe --add-drop-database -uDB_local_user --databases database_name | ssh linux_login@server_ip "mysql -uDB_user -pDB_password" Since Ant project uses files synchronization (and not copy) and rsync does the same, it deploys to server only files that have changed since last deploy, so it's fast and console logs are clear. If you're interested with Ant XML file, I can show you an example. Same with directories/files I exclude from build, both in Ant and rsync. EDIT: For the first installation on server, I start with a regular PW install directly on server. EDIT 2: Script also set the site in maintenance while deploying, displaying a "Maintenance, please come back later" message, with a bit of Apache configuration. It uploads a file at the site root on server, and when this files exists Apache redirects users to a basic HTML page (except for my IP).
  9. Hello, After form validation, is it possible to force the form to display an error on a given field? This is possible with the processwire core InputfieldForm and I often use it. Generally I use this to do additional and more complex checks after the basic form validation. For example the form contains a file upload field, it's a zip and I have to validate zip content, if it's not valid the form should display values entered by user with an error message on this field. I know I can create a custom validation rule, but within this validation I have to access variables that are outside the form. For example the form is to edit an ItemData instance, and within the validation I need to access this object. Can I pass variables to the validator custom rule? I looked at the documentation, what is the $params parameter, can I use it to pass variables to validator? Valitron\Validator::addRule('alwaysFail', function($field, $value, array $params, array $fields) With the core InputfieldForm I created a wrapper class and I use it this way: $onValidate = function (AccountEditionForm $form): void { // $onValidate is called only if form basic validation succeeded. if (someCondition) { // Triggering an error, $onSuccess won't be called, // form field will be red with error message, // form still filled with user values so user has only to fix the field with error. $form->setError('fieldName', 'errorMessage'); } } $onSuccess = function (AccountEditionForm $form)): void { // Form is valid (basic validation + $onValidate), use its data. }; $form->execute($onSuccess, $onValidate); Is there a way to do this kind of process, or can you recommend me another way? Thank you.
  10. On my Ubuntu (Gnome) laptop, I often get a popup saying an issue happened when waking up computer. I also sometimes had pain accessing an external drive, plug in, plug out, in, out... and finally it worked. Usually it works immediately, but not this time. Recently I was looking to free space, I have old accounts in my /home (from previous installations of Manjaro KDE, Manjaro Gnome...) and found I had 150 GB in the Download folder of one of this accounts. I opened a video just to check its content, and explorer crashed. I restarted explorer, selected everything in folder, deleted and... explorer crashed again. I tried again and this time it crashed when selecting files... I finally succeeded, but what a pain. I rarely turn off computer, just put it in sleep, I suppose this is why sometimes Firefox freezes for a few seconds after days without restarting, so I restart and everything is OK.
  11. I watched a video and Omarchy looks really great, but it's based on Arch Linux, I don't trust enough the stability of this distribution to use it for my daily job. I had a big issue in the past using Arch, only one time but when it happened the system was totally broken, after a simple "pacman -Syyu"... no more internet, no more access to external drives... The end. 😄 I also tried Manjaro, and after the dinner break, instead of a sleeping computer, I saw a black screen with graphic card fans at 100 % and everything else frozen. Ubuntu should be stable, but almost every day I have small issues on my Ubuntu laptop. That's why I didn't use Linux for my job since years, every time I try a distribution I see stability issues that scares me. Hope you'll have a great experience with Omarchy, keep us updated! 🙂
  12. Aurelien Barrau is a french physicist and philosopher, I translate: 😅 The study: https://metr.org/blog/2025-07-10-early-2025-ai-experienced-os-dev-study/
  13. It works only if I set multiple to true, but this is a single file upload: $zipUpload = new InputFile("zipFile"); $zipUpload->setMultiple(false); // Rule 'allowedFileSize' not working with "false" $zipUpload->showClearLink(true); // No link displayed too $zipUpload->setLabel("label"); $zipUpload->setRule('allowedFileSize', '524288000'); // Not taken into account except with multiple files $zipUpload->setRule('allowedFileExt', ['zip']); $zipUpload->setRule('required'); Oh, this works if I fill the english title of french language! Is it expected? Usually in ProcessWire the field first language value is used as default if second one is empty, like here: In my language selector for example, it works like this, all languages are found and usable. But at least I know how to fix this on my side. 😉
  14. Thank you @Juergen for the fixes. Sorry not to reply before but I have few free time. ^^ I found more issues: File upload is limited to 500 MB: $zipUpload->setRule('allowedFileSize', '524288000'); But I can add a file larger, the form is valid and the upload starts, but then the server is not happy: With module FrontendLoginRegister, in Account Settings I add Language field. I have 2 languages, french and english, french is default. The form displays the 2 languages only if user is actually using french, when using english, only english is listed in the Select field. If user selects english and save, it works. If user selects french it is not saved. I try to investigate the code quickly, only to find that in Select::___renderSelect(), when user is using english, $option->render() returns an empty string for french.
  15. And another issue. First time I submit the form, after isValid() I call showForm(true), so the form shows with the last value entered. I see the notice "Thank you for your message", and the URL segment is still there. I hit submit a second time and get a 404 page (from my code) because the URL segment is removed.
  16. Reason is the option in PW admin: I always check to end segments with a slash, if I check "no" the form works.
  17. Hello, On a page with an url segment, the form is never valid. It's a simple form with an InputNumber. If I remove the segment it works, if I add it isValid() is always false. Another minor issue, even if an InputFile has setMultiple(false), I can drag and drop several files on it, I don't know if you can do something for this.
  18. OK, but the random bug is still there. Don't be in the urge to investigate this, I'll go for a classic HTML form because I have to finish this ASAP.
  19. enum TournamentType:string { case MYSTERY = "Mystery"; case PKO = "PKO"; case VANILLA = "Vanilla"; } class FilterSolvesForm extends AbstractFrontendForm { protected function buildForm(): void { $tournamentTypeSelect = new Select("tournamentType"); $tournamentTypeSelect->setLabel(__("Type de tournoi")); foreach (TournamentType::cases() as $tournamentType) { $tournamentTypeSelect->addOption($tournamentType->value, $tournamentType->value); } $this->add($tournamentTypeSelect); } } abstract class AbstractFrontendForm extends Form { public function __construct(string $id) { parent::__construct($id); $this->buildForm(); $this->addSubmit(); } private function addSubmit():void { $button = new Button('submit'); $button->setAttribute('value', __("Valider")); $this->add($button); } abstract protected function buildForm(): void; } // TEMPLATE PHP FILE $command = new SelectSolvesDatabaseCommand(1, 10); $filtersForm = new FilterSolvesForm("solvesFilterForm"); if ($filtersForm->isValid()) { // DevUtils::prettyPrintObject($filtersForm->getValue('tournamentType')); // $command->addFilter('tournamentType', $filtersForm->getValue('tournamentType')); } $filtersForm->showForm(true); $command->execute(); $solves = $command->getPaginatedSolves(); Twig::render('browse-solves', [ 'paginatedSolves' => $solves, 'filtersForm' => $filtersForm, ] );
  20. It's a simple Select: I tried again and find this is a random bug, sometimes it works, sometimes not. I made a video, we don't see the dropdown because I recorded only Firefox window, but I can confirm the list is always rendered in the same order as the top line "Mystery,PKO,Vanilla,", that is the order used to fill the Select element, so this is not a problem caused by a random order when initializing the form.
  21. I found in your code that it is $form->setAttribute('method', 'get'); (documentation needs an update 🙂 ). But now the page is empty after submission, empty head and body. I don't understand what's happening. EDIT: Looks like there is an exit() somewhere, because no code in my template is executed after $form->isValid() when I use GET method. 🧐
  22. Thank you @Juergen I edited my message with more questions while you were answering: Another thing, after form submission I'd like the form to be still displayed for another use, it is used to filter data in a table so it should always be visible. Actually after submission the form is hidden and replaced with the message "Thank you for your message.". I tried to use $form->showForm(true); but there is a bug, the value shown in the form is not always the value I selected before to submit (in a Select element). And another question, following the documentation I added $form->setMethod('get'); but get an error: "::setMethod does not exist or is not callable in this context"
  23. Hello, Is there a way to put some fields into a div, so I can manage form layout more precisely? Is it with the FieldsetOpen/FieldsetClose elements? EDIT: Another thing, after form submission I'd like the form to be still displayed for another use, it is used to filter data in a table so it should always be visible. Actually after submission the form is hidden and replaced with the message "Thank you for your message.". I tried to use $form->showForm(true); but there is a bug, the value shown in the form is not always the value I selected before to submit (in a Select element).
  24. This gives a warning, better like this: if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], $this->wire('config')->urls->admin) === 0) { Will you publish a fix?
×
×
  • Create New...