Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/19/2025 in all areas

  1. Assuming that the field would be changed in Page Edit rather than as result of some other API code, you can validate the user input in a hook to InputfieldText::processInput. Example: $wire->addHookBefore('InputfieldText::processInput', function(HookEvent $event) { $inputfield = $event->object; $input = $event->arguments(0); $field = $inputfield->hasField; $page = $inputfield->hasPage; // For a particular field name and template name if($field && $field->name === 'text_1' && $page && $page->template == 'events') { $old_value = $page->getUnformatted('text_1'); // Return early if the old value is empty if(!$old_value) return; $new_value = $input[$inputfield->name]; // If the first three characters have changed if(substr($new_value, 0, 3) !== substr($old_value, 0, 3)) { // Show an error message $inputfield->error('You are not allowed to change the first three characters of the "Text 1" field.'); // Replace the hooked method so the new value won't be saved to the field $event->replace = true; } } });
    2 points
  2. I think the changed hook is not meant to revert any changes but only to listen to changes and trigger actions. But you can do this (not sure this is the best solution) - example using the title field in /site/ready.php: wire()->addHookAfter('Page::changed(title)', function (HookEvent $event) { $old = $event->arguments(1); $new = $event->arguments(2); $oldStart = substr($old, 0, 3); $newStart = substr($new, 0, 3); if ($oldStart === $newStart) return; // save old value to a temporary property that will be used // in the saveReady hook to revert to the old value $page = $event->object; $page->revertTitle = $old; }); wire()->addHookAfter('Pages::saveReady', function (HookEvent $event) { $page = $event->arguments(0); if ($page->revertTitle) $page->title = $page->revertTitle; });
    2 points
  3. Thanks for all the feedback on the new admin design last week. Based on the amount of feedback and requests we’ve received, it sounds like there’s a lot of interest and enthusiasm in the new design, which is fantastic. I’ve been making note of all the suggestions and will talk through them with Diogo and Jan at KONKAT Studio next week. There have been several good ideas mentioned. I was able to implement a couple of them already, including separately configurable light/dark mode main colors, and inline embedding of custom SVG logos (so the color can be styled). Personally I’m loving the new dark mode and have been spending most of my time in it. But I’m really digging the new light mode too, so I suspect I’ll settle into the “auto”, getting the best of both worlds according to the time and/or daylight. If you’ve not yet upgraded to ProcessWire 3.0.248 you are in for a treat when you do. Like anything new and on the dev branch, there may be some things yet to add and fix, but even in this initial release, I think you’ll find the new admin design to already be a beautiful and refreshing upgrade. At least that has been my experience. Thanks again to @diogo and @jploch for their great work with this. Have a great weekend!
    2 points
  4. @bernhard @Robin S: Thank you very much for your code suggestions. Looks very promising. Will try both tomorrow and then report back. Giving an additional hint/warning directly to the corresponding inputfield like robin suggested seems a good idea in terms of usability. The idea of a temporary field is also a need trick. Tried with saveReady before, which seems to work, but felt a bit hacky to me, as I needed to fetch the uncached old value to check for potential changes in the text field. Always good to learn something new. Your answers are highly appreciated. Made my day.
    1 point
  5. Hi. Thanks..I thought that it is in this condition.... Sorry for posting here. I will create thread if I will need more help, but now I know more...
    1 point
  6. Hello @dynweb Thanks for pointing out this issue. To be honest, I have never thought of such a possibility, because I always wanted to output a feedback message after the form submission. Your contribution leads me to update the setSuccessMsg() and setErrorMsg() methods to accept boolean values too. So if you want to disable the output of one of them please add false inside the parenthesis. These prevents the output of a message after form submission. $form->setSuccessMsg(false); This is more elegant than adding an empty string, but you need to replace the following file from Github with yours: https://github.com/juergenweb/FrontendForms/blob/main/Formelements/Form.php This addition will be automatically included in the next update, but I do not want to update the module today. You will find more infos about the new additions inside the changelog.md. Best regards Jürgen
    1 point
  7. Hi Juergen, I'm trying to get me head around FrontendForms, but some questions/problems remain... Hope you don't mind. How can I prevent outputting the success message after successfully submitting the form? $form->setSuccessMsg(' '); is working (setting the message to a space), but not very elegant... Thank you
    1 point
  8. @robert No probs! It was a good exercise to test the quality of my code and make sure the API acted as expected 🙂
    1 point
  9. Yes, this seems to be the problem. ProcessTranslatePage works with the latest Processwire version, but not with Fluency V2 (yet). @FireWiresorry for the long wait, I did not have time to merge your PR yet, but thanks a lot for your effort!
    1 point
×
×
  • Create New...