Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by Juergen

  1. Silly mistake!!! Trait is not a class, so using $this was not a good idea 😒 // use __('myString'); // and not $this->_('myString'); // inside traits
  2. Hello community, I am struggeling with a problem that translatable strings inside a trait will not display the correct language translation. I use the trait inside a class and include it inside the class like this <?php namespace MyNameSpace; use function ProcessWire\_; class myClass { use activation; public function myMethod() { return $this->function test(); } ] Only to mention : I use a custom namespace. The trait looks like this <?php namespace MyNameSpace; trait activation { public function test() { return $this->_('My text'); } } The problem is that "My text" will not be translated to the other languages independent of the which $user->language is set. Maybe someone has a solution for this problem and could post it here.
  3. Thanks @Zeka I have tried this, but it does not work. It seems the problem is that this method is inside a trait without any reference to a page language. The trait (called activation in my case) will be included inside a class via use activation; and it works - without the exception of the translations. I have some other classes for rendering frontend forms and texts and in this case the translationable strings work. But thank you for your answere.
  4. Hello, I have created a module which sends out emails to users triggered by LazyCron - works well. The emails contain translateable strings and the problem is that the emails will be always sent in the default language and not in the stored user language. Here is my method that sends out the emails: /** * Create WireMail object and send the email with the activation link * @param User $user - the user object * @return bool - returns true on success and false on failure */ protected function sendActivationLinkEmail(User $user): bool { // send an email with the activation link to the user // but check first if activation code (fl_activation) exists inside the database if($user->fl_activation){ $m = wireMail(); $m->to($user->email); $m->from($this->input_email); $m->subject($this->_('Action required to activate your account')); $m->body($this->createActivationLinkEmail($user)); $m->mailTemplate($this->input_emailTemplate); return $m->send(); } return false; } The method is part of a trait that I use. As you can see the subject contains a translateable string. The body text will be created by another method (createActivationLinkEmail) and contains also translateable strings, but you cannot see it here. The emails will be sent, but the text is always in English (default), independant if the user language is English, German or another language. I have tried to add $this->wire('languages')->set($user->language->id); but it does not work. Can someone help me out how to set the language inside this method to send the emails in the user language? Thanks in advance
  5. Hello at all, I am struggeling about a fast method to get all language translation CSV files of fe a module and merge all these files into 1 CSV file. I do not want fe 10 CSV translation files for a module. So I want to merge them all into one. All translation files for a site module are stored in site/assets/idoftheModule/... as json files. These translation files can be downloaded, but they are in json and not CSV format. I know I can do it one by one in the backend, but this is not my goal. Does anyone has done this before and could give me a hint, what ist the best and fastest way to 1) dowload all CSV files of a module at once and 2) merge them all into 1 CSV file. Thanks in advance
  6. Hello @Flashmaster82, There are different ways - the most simple one is to use PWs built in Mail class: Here is a working example (not tested but it should work ;-)) $form = new Form('contactform'); $gender = new Select('gender'); $gender->setLabel('Gender'); $gender->addOption('Mister', '0'); $gender->addOption('Miss', '1'); $form->add($gender); $surname = new InputText('surname'); $surname->setLabel('Surname'); $surname->setRule('required'); $form->add($surname); $name = new InputText('name'); $name->setLabel('Name'); $name->setRule('required'); $form->add($name); $email = new InputText('email'); $email->setLabel('E-Mail'); $email->setRule('required'); $form->add($email); $subject = new InputText('subject'); $subject->setLabel('Subject'); $subject->setRule('required'); $form->add($subject); $message = new Textarea('message'); $message->setLabel('Message'); $message->setRule('required'); $form->add($message); $privacy = new InputCheckbox('privacy'); $privacy->setLabel('I accept the privacy policy'); $privacy->setRule('required')->setCustomMessage('You have to accept our privacy policy'); $form->add($privacy); $button = new Button('submit'); $button->setAttribute('value', 'Send'); $form->add($button); if($form->isValid()){ // send an email $m = wireMail(); $m->to('myEmail@test.com); // enter here the email address where the mail should be sent to - usually it is your email address $m->fromName($form->getValue('gender').' '.$form->getValue('surname').' '.$form->getValue('name')); $m->from($form->getValue('email')); // the email address of the sender $m->subject($form->getValue('subject')); // the subject of the email $m->bodyHTML($form->getValue('message')); // the message text of the email $mailSent = $m->send(); // optional check if there was an error sending the mail // true on success, false on failure if(!$mailSent){ $form->getAlert()->setText('There was an error sending the mail.'); $form->getAlert()->setCSSClass('alert_dangerClass'); } // save the email as page $p = new Page(); // create new page object $p->template = 'email'; // set template -> you have to create the template first by yourself $p->parent = wire('pages')->get('template=contact'); // set the parent page $p->title = $form->getValue('subject'); $p->body = $form->getValue('subject'); $p->save(); } // render the form echo $form->render(); To send an email please check the docs at https://processwire.com/api/ref/wire-mail/ By creating a new page to save the email as a page under the contact form page please take a look at "save the email as page" section in the code above. You have to create the template and the fields for the email template first by yourself. 1) Create a template with fe the name 'email' first 2) Add the fields to the template where you want to store the data of the email (fe surname, name, subject, email address, message,....) 3) You have to set the parent page finding the parent by its template name (in the above example the contact form page uses the template 'contact') 4) Add the mail values to the email template fields and save the page. Best regards
  7. Hello @sp1ke That would be great and could really be a time saver for other Greek people. I would say you send me only the Greek csv file and I will add it on GitHub as el.csv (I guess el is the language code for Greek, am I right?). Thanks and have a nice weekend
  8. Hello @sp1ke An inputfield is a single line input and textarea is a multiline input. ProcessWire provides an extra sanitizer for textareas. Take a look at https://processwire.com/api/ref/sanitizer/textarea/ . Using "sanitizer text" for normal inputfields and "sanitizer textarea" for textareas was my personal choice. These 2 sanitizers will be applied by default - no need for you to do it manually. This is only for security reasons. If you are not satisfied with it, you can disable the sanitizer on each field by using the removeSanitizers() method. Take a look at this example: $surname = new InputText('surname'); $surname->setLabel('Surname'); $surname->setRule('required'); $surename->removeSanitizers();// this line removes the text sanitizer from this inputfield $form->add($surname); In this case the value will not beeing sanitized, but this is not recommended (especially if you are storing values in the database). If you want to add a special sanitizer for an input, you can use all sanitizers that will be shipped with ProcessWire. See a list of all available sanitizers at https://processwire.com/api/ref/sanitizer/ Example: You want to use the following sanitizers from ProcessWire: $sanitizer->alpha(string $value) //Sanitize to ASCII alpha (a-z A-Z) $sanitizer->camelCase(string $value) //Convert string to be all camelCase All you need to do is to use the setSanitizer(name of the sanitizer in ProcessWire) method. $surname = new InputText('surname'); $surname->setLabel('Surname'); $surname->setRule('required'); $surename->removeSanitizers();// this line removes the text sanitizer from this inputfield $surename->setSanitizer('alpha'); // this adds the alpha sanitizer $surename->setSanitizer('camelCase');// this adds the camelCase sanitizer $form->add($surname); Using camelCase sanitizer for the surename makes no sense in real life, so it is only applied as an example 😉 Hope it will be a little bit clearer.
  9. Hello @sp1ke glad to hear that, but I would recommend you to update your PHP version to at least 7.2+, because object type hinting is only possible with higher PHP versions. Otherwise you will get this error message everytime someone uses object type hinting (like me ;-). Best regards
  10. Hello This is very strange, because I have no problems and the error message will also make no sense. I have installed it on a new install of PW without problems. The problem is the type hinting in this case: The method add() expects an object and the variable $gender in your case is an object - it is an object of the class Select. So there should not be a problem, but you can try the following: // Replace this code in FrontendForms/FormeElements/Form.php line 203 public function add(object $field) // with this code public function add($field) But before removing the type hinting from this method, please try the following: For testing purposes remove the add() method by the select field and take a look if the problem persists with other fields (fe. the name input field). Which version of PHP do you use? Please let me know!
  11. Hello, as introduced in PW 3.0.181 modules can be shipped with translation files. I am trying to hook after the save method of this new functionality, but I could not get it to work. This hook is inside a module: // initialize the hooks public function init() { $this->addHookAfter('ProcessLanguage::save', $this, 'testHook'); } protected function testHook(HookEvent $event) { wire('session')->message('test'); } Nothing happens! Does anyone has an idea how to hook this new functionality. I have also tried it with fe ProcessLanguage::executeDownload but without success. Here is the Github page of the new feature: https://github.com/processwire/processwire/blob/master/wire/modules/LanguageSupport/ProcessLanguage.module
  12. Hello @sp1ke thank you for your issue report. This error was produced by my editor during find and replace process. It is not possible to use $this inside the module info method. I have replaced all translateable strings from __('My string') to $this->_('My string') because using $this is the prefered method inside the class of a module. During these replacements I have overlooked the replacement inside the module info method. I have replaced it on GitHub to: 'summary' => __('Create forms and validate them using the Valitron library.'), So in this case the string is also translateable. Thanks
  13. Problem is solved! I installed a new installation on XAMPP and now it works without problems - I guess there was going something wrong during the developement of the module inside the database. Best regards
  14. I found out that it happens if I use save() method without a parameter that was not set before. If I use for example save('title') and I set the title first, it works. // Works $p->title = 'My title'; $p->save('title'); // Does not work if title was not set before $p->save('title'); // Unfortunately this does not work $p->addStautus(Page::statusUnpublished); $p->save('status'); // and this does no work too $p->addStautus(Page::statusUnpublished); $p->save(); Any hints how to save the status?
  15. Hello @ all I am struggeling with a saving problem of pages and could not find the reason. Description: I am using the following Hook inside a module: public function ready() { $this->addHookAfter('Modules::saveConfig', $this, 'setPageStatus'); } This Hook runs after the module was saved and triggers the the following setPageStatus method : /** * Sets the status of pages using the fl_register or fl_activation template to unpublished or published depending on the value of the * input_selectloginregister inputfield * @param HookEvent $e */ protected function setPageStatus(HookEvent $e) { $pages = wire('pages')->find('template=fl_register|fl_activation', ['findAll' => true]); foreach($pages as $p){ $p->setOutputFormatting(false); if($e->arguments(1)['input_selectloginregister'] == 'login'){ $p->addStatus('unpublished'); } else { $p->removeStatus('unpublished'); } $p->save(); $p->setOutputFormatting(true); } } I have found out that $p->save() method is responsible for the hight execution time and the error, but I do not know why. Everytime I remove this method the problem is gone. but of course the status will not be saved. Just to mention: There are always only 2 pages that will be saved - not more!!! Does anyone has an idea why the saving of the pages can exceed the execution time or a way to find out where the problem could be. Thanks in advance
  16. Thank you @OrganizedFellow This module is on a very early stage, so it has to be tested carefully. I have done a lot of tests and it has been working well, but I hope a lot of people will try it out to test it further to find possible weak points and errors.
  17. Hello @ all I want to share a new module with you, which makes the creation and validation of forms easy. Take a look at the following example of a simple contact form: // A very simple example of a contactform for demonstration purposes $form = new Form('contactform'); $gender = new Select('gender'); $gender->setLabel('Gender'); $gender->addOption('Mister', '0'); $gender->addOption('Miss', '1'); $form->add($gender); $surname = new InputText('surname'); $surname->setLabel('Surname'); $surname->setRule('required'); $form->add($surname); $name = new InputText('name'); $name->setLabel('Name'); $name->setRule('required'); $form->add($name); $email = new InputText('email'); $email->setLabel('E-Mail'); $email->setRule('required'); $form->add($email); $subject = new InputText('subject'); $subject->setLabel('Subject'); $subject->setRule('required'); $form->add($subject); $message = new Textarea('message'); $message->setLabel('Message'); $message->setRule('required'); $form->add($message); $privacy = new InputCheckbox('privacy'); $privacy->setLabel('I accept the privacy policy'); $privacy->setRule('required')->setCustomMessage('You have to accept our privacy policy'); $form->add($privacy); $button = new Button('submit'); $button->setAttribute('value', 'Send'); $form->add($button); if($form->isValid()){ print_r($form->getValues()); // do what you want } // render the form echo $form->render(); This piece of code creates a simple contact form and validates it according to the validation rules set. Inside the isValid() method you can run your code (fe sending an email) Highlights: 30+ validation types Support for UiKit 3 and Bootstrap 5 CSS framework SPAM protection Highly customizable Hookable methods for further customization Multi-language You can download and find really extensive information on how to use at https://github.com/juergenweb/FrontendForms. Please report errors or suggestions directly in GitHub. Best regards and happy testing 🙂
  18. Hello @all I want to know if someone stumbled over the same problem: You have created a modul and during the installation process one or more fields will be created via the API. You have decided to use translateable strings for the field label, description etc. so it could be overwritten by translateable files. $field = new Field(); $field->type = $this->modules->get("FieldtypeDatetime"); $field->name = 'mydate'; $field->label = __('My Date'); So far so good. You install the module and everthing works fine. The label of the via API created FieldtypeDatetime is "My date". Now you want to overwrite this and therefore you create the translation file and overwrite it with fe "Your date". But then: Taking a look at the label of this inputfield on the edit form shows that the label has not changed. The reason for this behavior is, that the field was created before the translation file and therefore the overwritten label will not be used. So you have to go to the field configuration itself and change the label there or you uninstall the module and install it once more. In this case the translation file exists if it was created before and can be used during the creation process of the inputfields. It would be better if the overwritten value will be taken into account. It is not really a problem, but does anybody also struggle with this and found a way to solve this behavior. If not it does not matter. Best regards
  19. Yes, that works!! Hook inside hook -> nice combination. That was exactly what I was looking for!! Problem solved!! 😃 Thanks!!!!!!
  20. Thanks @netcarver This works, but only if the module cache will be deleted. So I have to include a cache delete and save new method too. I will try to figure out how this could be realized.
  21. Ok, doesn't work! I used this code inside my checking method to set and save config data: $data = wire('modules')->getConfig('MyModuleName'); if(Condition){ $data['permanent'] = true; } else { $data['permanent'] = false; } wire('modules')->saveConfig('MyModuleName', $data); The permanent value will be changed and saved inside the data table, but it seems that there is a module cache problem which prevents the uninstall checkbox from beeing updated (disabled or not).
  22. Thanks @horst Interesting thought, but the condition depends on a setting in a configuration field of the module, so I guess this will not work, but I will try it!
  23. Hello @all I am struggeling to find a way to set the checkbox status of the uninstall checkbox at the bottom of the module configuration page to disabled. I have created a module and I want that the checkbox should be disabled under certain conditions. I have tried to use this hook in my module file init method: $this->addHookBefore('ProcessModule::executeEdit', $this, 'showHideUninstallCheckbox'); and the method itself: protected function showHideUninstallCheckbox(HookEvent $event) { if(condition) .... run code to disable the checkbox } Maybe this hook is not suitable for this purpose. Can someone help me out to show me a way to achive this. Thanks in advance!!
  24. Ok, I got it: Updating my Fieldtype file with this method solved my problem. I found this method inside the FieltypeText.module file. /** * Update a query to match the text with a fulltext index * * @param PageFinderDatabaseQuerySelect $query * @param string $table * @param string $subfield * @param string $operator * @param int|string $value * @return DatabaseQuerySelect * */ public function getMatchQuery($query, $table, $subfield, $operator, $value) { $ft = new DatabaseQuerySelectFulltext($query); $ft->match($table, $subfield, $operator, $value); return $query; }
  25. Hello at all, I have created a new fieldtype with multiple fields (database columns) in it. More precisely it holds various company data (fe. company name, street, phone,...) - each in 1 database column. I want to make these values searchable in the site search, but it always shows me that the selector '~=' is not implement. It accepts '=' as a selector but not '~='. How can I implement this specific selector inside a fieldtype, so it does not throw me an error all the times, if I run a query with this selector. Thank you PS: My fieldtype class extends from Fieldtype
  • Create New...