Jump to content

Juergen

Members
  • Posts

    1,064
  • Joined

  • Last visited

  • Days Won

    7

Everything posted by Juergen

  1. Maybe could it be the same issue as in this topic? Bug report - Get $user->language in hook Pages::saveReady
  2. In PW version 3.0.173, new hooks for urls were introduced (ProcessWire 3.0.173 core updates: New URL hooks). The problem is, I am using translatable strings inside the hook, but the language is always default. I can remember there was also a problem within another hook and Ryan mentioned that this is the usual behaviour, because language is always detected before and after the hook but not within. Maybe someone struggles with the same problem and has found a solution to post it here? I need translatable strings inside this hook.
  3. Hello I have created a module which contains a MarkupAdminDataTable with a lot of entries of statistic data in the module configuration. Inside this table I have added a "View details" button to each table row (entry). By clicking this button I want to show some log file information about this entry inside the panel. This information will come from a php file, not from an admin page. Therefore I cannot load the content via href attribute. Is it possible to load content inside this panel without creating an admin page and how?
  4. Hello, I have a multilang field in my module configuration - it is a text field. // Required hint custom text $requiredText = wire('modules')->get('InputfieldText'); $requiredText->name = 'input_requiredText'; $requiredText->label = $this->_('Hint that all required fields have to be filled out'); $requiredText->value = $this->input_requiredText; // here is the value $reqText = $this->_('This text will be displayed on the form depending on your settings.') . '<br>'; $reqText .= $this->_('If nothing is entered, a default text will be displayed instead.'); $requiredText->description = $reqText; $requiredText->notes = $this->_('Can be overwritten on each form.'); $requiredText->useLanguages = true; // enable multilanguage for this field $requiredText->showIf = "input_requiredHintPosition!=none"; $fieldset1->add($requiredText); The values will be stored as followed inside the db: "input_requiredText":"My custom text","input_requiredText__1012":"Das ist mein Custom Text","input_requiredText__1013":"" I want to output the values depending on the users language on the frontend Question: Is there an easy way to grab this values on the frontend?
  5. Great idea @Anonimas I have integrated both. You can change/customize the text for the required fields with setRequiredText() method. $form->setRequiredText('This is my customized text, that you have to fill out all required fields.') I have also added EOT for better readability. Please download and install the module once more. Thanks for your ideas.
  6. Hi Anonimas Inspired by your question I have added a new method to add the wrapper div over all form fields (including hidden fields too). $form->setFormElementsWrapper()->setAttribute('class', 'mycustomclass'); By default a unique CSS id will be added, but as you can see in the example above, you can also add a class attribute (or other attributes) too. <form> <div id="formelementswrapper" class="mycustomclass"> .... </div> </form> To use this method, please download version 2.0.9 from GitHub. Alternatively replace the Form.php. This file includes all the changes and additions. BTW could you please tell me, what is the intention for you to wrap all form fields in an extra div? Best regards Jürgen
  7. Hi Anonimax Yes it is possible, but instead of adding the divs to the form element itself you have to add the opening div to the first form element and the closing div to the last form element. Please take a look at the example code below: $form = new \FrontendForms\Form('testform'); $surname = new \FrontendForms\InputText('surname'); $surname->setLabel('Surname'); $surname->setRule('required'); $surname->getFieldWrapper()->prepend('<div>'); $form->add($surname); $email = new \FrontendForms\InputText('email'); $email->setLabel('E-Mail'); $email->setRule('required'); $email->setRule('email'); $form->add($email); $button = new \FrontendForms\Button('submit'); $button->setAttribute('value', 'Send'); $button->append('</div>'); $form->add($button); if($form->isValid()){ print_r($form->getValues()); // do what you want } // render the form echo $form->render(); The first input field in the form is the text input "surname". Grab the field wrapper object and prepend the div there: $surname->getFieldWrapper()->prepend('<div>'); The last element in this form is the button element -> so append the closing div there: $button->append('</div>'); It always depends on the structure of your form. Hidden fields are excluded in this case from beeing wrapped with the div, but I guess this should not be a problem. If you have problems, please post your form code here. Best regards
  8. Hello Wishbone, "Sending emails is not part of this module" means not that emails cannot be send by the forms createt by this module. It means that sending emails will be done fe by the WireMail class of ProcessWire and not by this module class. This module creates and validates forms - not less or more. After the validation process is finished you can do whatever you want: storing data in the DB, sending emails,.... its up to you and you have to write the code for the action after the validation by yourself. Yes, there seems to be an issue on a Mac environment for the moment, but I was not able to reproduce the error. I only got 2 messages from users which had troubles. One problem could be solved, the other is still there, but I am working on it. If you want to install the module maybe I could help you. Best regards
  9. Hello Chris Please do the following: Go to the FrontendForms.module file, find the method classLoader (at line 163) and insert the following print command before the include function at line 183 print_r($dir . $file); // add this line include $dir . $file; Load the page on the frontend and make a screenshot of the paths like I did in the image below. Let us see if there are differences in the paths between mine and yours. I am excited! Best regards Jürgen
  10. Hello sp1key, glad to hear that ? Sending emails is not part of this module, so its up to the mailer class of PW. If you set it up correctly, it will work. I have corrected this notice - so please download FrontendForms.module once more and replace it with the new one. Best regards
  11. Hi, I have added a new autoloader function. I have tested it and only the classes which are used in the template will be loaded and nothing more. So there could not be an overhead by loading all classes. You do not need to replace the complete module. Please replace only the code of the FrontendForms.module file and let me know if it works now. Thanks
  12. Hi sp1key! The objects are declared at the top of the file (take a look at line 94 and below of the Form.php). // Classes protected $alert; protected $requiredHint; I do not think so, because the classes will (should) be loaded on demand and not all at once, but you are right: it is strange that it makes differences between classes. I will take a closer look today on the issue especially on the autoloader and the paths. I guess the amount of directories should not cause this issue. Best regards
  13. Maybe there could be a problem with new instances without the namespace. I have only tested this module locally and and never on live servers. Thats why I did not recognize that there could be a problem with namespaces. Anyway: I have added the namespace to every new instance of a FrontendForms class on every file inside the module (I hope I have not overlooked a new instance ?). A lot of files were modified - so please download the module once more. I have not bumped up the version number. BTW: I could not find different spellings on the namespaces inside the files. If you have discovered that I have written it in different ways please let me know where. Best regards
  14. Hello! I have replaced my own class loader with the ProcessWire classLoader, which handles namespaces better and here on my windows system and XAMPP it works. Could you please reinstall the module with the new version 2.0.3 and let me know if the problem is gone now. Best regards.
  15. I have created a fresh install with the beginner theme, but I am not able to reproduce your errors. I have integrated the code inside the basic-page and as you can see the form is still there and it works. Here is the complete code of the basic page (templates/basic-page.php): <?php namespace ProcessWire; /** @var Page $page */ include('./_head.php'); // include header markup ?> <div id='content'><?php // output 'headline' if available, otherwise 'title' echo "<h1>" . $page->get('headline|title') . "</h1>"; $form = new \FrontendForms\Form('contactform'); $gender = new \FrontendForms\Select('gender'); $gender->setLabel('Gender'); $gender->addOption('Mister', 'Mister'); $gender->addOption('Miss', 'Miss'); $form->add($gender); $surname = new \FrontendForms\InputText('surname'); $surname->setLabel('Surname'); $surname->setRule('required'); $form->add($surname); $name = new \FrontendForms\InputText('lastname'); $name->setLabel('Last Name'); $name->setRule('required'); $form->add($name); $email = new \FrontendForms\InputText('email'); $email->setLabel('E-Mail'); $email->setRule('required'); $email->setRule('email'); $form->add($email); $subject = new \FrontendForms\InputText('subject'); $subject->setLabel('Subject'); $subject->setRule('required'); $form->add($subject); $message = new \FrontendForms\Textarea('message'); $message->setLabel('Message'); $message->setRule('required'); $form->add($message); $privacy = new \FrontendForms\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 \FrontendForms\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(); // output bodycopy echo $page->get('body'); // render navigation to child pages renderNav($page->children); // TIP: Notice that this <div id='content'> section is // identical between home.php and basic-page.php. You may // want to move this to a separate file, like _content.php // and then include('./_content.php'); here instead, on both // the home.php and basic-page.php template files. Then when // you make yet more templates that need the same thing, you // can simply include() it from them. ?></div><!-- end content --> <aside id='sidebar'><?php // rootParent is the parent page closest to the homepage // you can think of this as the "section" that the user is in // so we'll assign it to a $section variable for clarity $section = $page->rootParent; // if there's more than 1 page in this section... if ($section->hasChildren > 1) { // output sidebar navigation // see _init.php for the renderNavTree function renderNavTree($section); } // output sidebar text if the page has it echo $page->get('sidebar'); ?></aside><!-- end sidebar --> <?php include('./_foot.php'); // include footer markup ?> You do not need to integrate something inside the init.php to make it work. I have only integrated the following 2 lines inside the init.php. Here is the complete code of my init.php (templates/_init.php) <?php namespace ProcessWire; /** * Initialization file for template files * * This file is automatically included as a result of $config->prependTemplateFile * option specified in your /site/config.php. * * You can initialize anything you want to here. In the case of this beginner profile, * we are using it just to include another file with shared functions. * */ include_once("./_func.php"); // include our shared functions $frontendforms = new FrontendForms(); $frontendforms->setLang('de'); I use these 2 lines only to make the error messages in german for all pages -> nothing more, but the module works also without these 2 lines. Please check my code against yours and let me know. Best regards
  16. Mysterious, on my setup everything works fine. Please be patient, I will take a deeper look within the next days. Today I am to busy to dig in ;-) Best regards
  17. Hello Christian, thanks for informing me about the error during the installation. I have corrected it on github, so please download version 2.0.2 again to get rid of the warning. The other problem is maybe caused by the namespace: you are not using a namespace (fe. Processwire) in your test.php. Therefore you do not need to add the namespace before the class name. // this should be correct $gender = new Select('gender') // do not write $gender = new /FrontendForms/Select('gender') // this in only necessary if you are using a namespace in this template //you have to correct it on each class instantiation. I have not tried it, because I am always using a namespace in my templates, but this should solve your problem. Please let me know. Best regards
  18. Here is the working code for your form by using translatable strings. You have to set your email address in email section. I have removed it to do not publish it here in the public. $form = new \FrontendForms\Form('contactform'); $form->setSuccessMsg(__('Your message was submitted successfully!')); $form->setErrorMsg(__('Sorry, but there are errors!')); $gender = new \FrontendForms\Select('gender'); $gender->setLabel(__('Title:')); $gender->addOption(__('Mister'), 'Mr.'); $gender->addOption(__('Miss'), 'Ms.'); $gender->setAttribute('class', 'w3-select w3-border w3-margin-bottom'); $form->add($gender); $name = new \FrontendForms\InputText('name'); $name->setLabel(__('Full Name:')); $name->setRule('required'); $name->setAttribute('class', 'w3-input w3-border w3-margin-bottom'); $form->add($name); $email = new \FrontendForms\InputText('email'); $email->setLabel(__('E-Mail:')); $email->setRule('required'); $email->setRule('email'); $email->setAttribute('class', 'w3-input w3-border w3-margin-bottom'); $form->add($email); $address = new \FrontendForms\InputText('address'); $address->setLabel(__('Address:')); $address->setRule('required'); $address->setAttribute('class', 'w3-input w3-border w3-margin-bottom'); $form->add($address); $message = new \FrontendForms\Textarea('message'); $message->setLabel(__('Message:')); $message->setRule('required'); $message->setAttribute('class', 'w3-input w3-border w3-margin-bottom'); $form->add($message); $button = new \FrontendForms\Button('submit'); $button->setAttribute('value', __('Send')); $button->setAttribute('class', 'w3-btn w3-round w3-blue'); $button->addWrapper()->setAttribute('class', 'w3-padding-24 w3-center'); $form->add($button); if ($form->isValid()) { // send an email $m = wireMail(); $m->to('enteryouremailhere'); $m->fromName($form->getValue('gender') . ' ' . $form->getValue('name')); $m->from($form->getValue('email')); // the email address of the sender $m->subject(_('New message from the contact form()')); // the subject of the email $m->bodyHTML($form->getValue('message') . ' <br><br> ' . $form->getValue('address')); // the message text of the email $m->send(); } echo $form->render();
  19. Hello sp1ke This module runs in its own namespace called "Frontendforms". I have added this namespace later and have forgotten to adapt the example codes. So if you are using the namespace "Processwire" or any other namespace you have to add the "FrontendForms" namespace before creating a new instance. // running inside a namespace $gender = new \FrontendForms\Select('gender'); // running outside of a namespace $gender = new Select('gender'); You have to do it on every new instance, otherwise you will get an error message!!!! I have adapted your code with the new namespace and it works. $form = new \FrontendForms\Form('contactform'); $gender = new \FrontendForms\Select('gender'); switch ($curLanguage) { case "English": $gender->setLabel('Title: '); $gender->addOption('Mister', 'Mr.'); $gender->addOption('Miss', 'Ms.'); break; case "Ελληνικά": $gender->setLabel('Τίτλος: '); $gender->addOption('Κύριος', 'Κος'); $gender->addOption('Κυρία', 'Κα'); break; default: $gender->setLabel('Title: '); $gender->addOption('Mister', 'Mr.'); $gender->addOption('Miss', 'Ms.'); break; } $gender->setAttribute('class', 'w3-select w3-border w3-margin-bottom'); $form->add($gender); $name = new \FrontendForms\InputText('name'); switch ($curLanguage) { case "English": $name->setLabel('Full Name: '); $name->setRule('required')->setCustomMessage('This field is required'); break; case "Ελληνικά": $name->setLabel('Ονοματεπώνυμο: '); $name->setRule('required')->setCustomMessage('Το πεδίο είναι απαραίτητο'); break; default: $name->setLabel('Full Name: '); $name->setRule('required')->setCustomMessage('This field is required'); break; } $name->setAttribute('class', 'w3-input w3-border w3-margin-bottom'); $form->add($name); $email = new \FrontendForms\InputText('email'); switch ($curLanguage) { case "English": $email->setLabel('E-Mail: '); $email->setRule('required')->setCustomMessage('This field is required'); break; case "Ελληνικά": $email->setLabel('E-Mail: '); $email->setRule('required')->setCustomMessage('Το πεδίο είναι απαραίτητο'); break; default: $email->setLabel('E-Mail: '); $email->setRule('required')->setCustomMessage('This field is required'); break; } $email->setRule('email'); $email->setAttribute('class', 'w3-input w3-border w3-margin-bottom'); $form->add($email); $address = new \FrontendForms\InputText('address'); switch ($curLanguage) { case "English": $address->setLabel('Address: '); $address->setRule('required')->setCustomMessage('This field is required'); break; case "Ελληνικά": $address->setLabel('Διεύθυνση: '); $address->setRule('required')->setCustomMessage('Το πεδίο είναι απαραίτητο'); break; default: $address->setLabel('Address: '); $address->setRule('required')->setCustomMessage('This field is required'); break; } $address->setAttribute('class', 'w3-input w3-border w3-margin-bottom'); $form->add($address); $message = new \FrontendForms\Textarea('message'); switch ($curLanguage) { case "English": $message->setLabel('Message: '); $message->setRule('required')->setCustomMessage('This field is required'); break; case "Ελληνικά": $message->setLabel('Μήνυμα: '); $message->setRule('required')->setCustomMessage('Το πεδίο είναι απαραίτητο'); break; default: $message->setLabel('Message: '); $message->setRule('required')->setCustomMessage('This field is required'); break; } $message->setAttribute('class', 'w3-input w3-border w3-margin-bottom'); $form->add($message); $button = new \FrontendForms\Button('submit'); $button->setAttribute('value', 'Send'); $button->setAttribute('class', 'w3-btn w3-round w3-blue'); $button->prepend('<div class="w3-padding-24 w3-center">'); $button->append('</div>'); $form->add($button); switch ($curLanguage) { case "English": $form->setSuccessMsg('<p>Your message was submitted successfully!</p>'); $form->setErrorMsg('<p>Sorry, but there are errors!</p>'); break; case "Ελληνικά": $form->setSuccessMsg('<p>To μήνυμα σας στάλθηκε με επιτυχία!</p>'); $form->setErrorMsg('</p>Υπάρχουν λάθη στη συμπλήρωση της φόρμας!</p>'); break; default: $form->setSuccessMsg('<p>Congratulations, your message was submitted successfully!</p>'); $form->setErrorMsg('<p>Sorry, but there are errors!</p>'); break; } if ($form->isValid()) { // send an email $m = wireMail(); $m->to('enteryouremailhere'); $m->fromName($form->getValue('gender').' '.$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(); } echo $form->render(); BTW you use the subject value, inside your mail function, but you do not have an inputfield for your subject. This will not work. $m->subject($form->getValue('subject')); // the subject of the email The new error message I have changed the code of the Frontendforms.module file a little bit to check if a template path is provided. I recommend you download the module once more to get the latest version and replace it with the version you have on your system. Another question: Why are you using a switch statement for your languages? You can use translatable strings instead of a switch statement. Best regards
  20. Ryan will make the processCSV method hookable in the next update ? No problem, I will make sure it is hookable in the next dev branch version 3.0.195. If you'd like feel free to add the 3 underscores to your copy and it'll be present on the next update.
  21. I have found a solution, but you have to hack the core file "ProcessLanguage.php"a little bit. The perfect method to save translations to fields created by a module is to hook after the "processCSV" method of the "ProcessLanguage" class file. Only problem: This method is not hookable by default, so I added 3 underscores to the method name to make it hookable. Goal: I want to add the German labels to the 3 fields created by the module after uploading and saving the translation csv file for this module. The label translations are inside the module translation csv file and I need to save it to the 3 fields. This is the main problem, because this field were created by the module but they are not part of the module, so I have to create/save the translations for this fields in an extra step. They will not be saved by adding the translation file to the module by default. To save the labels of the fields in another language I use the method below: // Define the hook function inside the init method public function init() { $this->addHookAfter('ProcessLanguage::processCSV', $this, 'addTranslationsToFields'); } /** * Method to add translation to the labels of fields created by this module * @param HookEvent */ protected function addTranslationsToFields(HookEvent $event){ // get the language object of the uploaded translation csv file $language = $event->arguments(1); $translation = new LanguageTranslator($language); $fields = ['jk_publish_open', 'jk_publish_from', 'jk_publish_until']; // name of the field to translate the labels foreach($fields as $fieldName){ //grab the field object $field = $this->wire('fields')->get($fieldName); $label = $translation->getTranslation($this, $field->label); $field->set("label{$language->id}", $label); $field->save('label'); } } The 3 fields where I want to add the translations to the labels are called 'jk_publish_open', 'jk_publish_from', 'jk_publish_until'. After uploading the translation csv. file for the module, the translations for the labels will be also added to the extra created fields which are not part of the module. This works like a charme (thanks to the PW LanguageTranslator class). I will try to convince Ryan to make the processCSV method hookable by default. Therefore I have submitted a pull request for making this method hookable by default: Best regards
  22. Hello, I am struggeling with the following problem: I have created a module that creates 2 additional text fields during the module installation. As documented ,on version ProcessWire 3.0.181 and above you can ship your modules with additional translation files inside the languages folder. This works great. My problem is that I want to add the translations for the 2 additional fields too. It works great for the module itself, but I dont know how to save the translations to the field too after installing the language file to a certain language. The workflow should be the following: After importing and saving fe the German csv file, the translations should also be added and stored on the 2 additional fields (fe the Label in German). Unfortunately there is no useable hookable function inside the ProcessLanguage class (https://github.com/processwire/processwire/blob/master/wire/modules/LanguageSupport/ProcessLanguage.module). Does anyone has an idea how to accomplish this? Thanks in advance for hints.
  23. Silly mistake!!! Trait is not a class, so using $this was not a good idea ? // use __('myString'); // and not $this->_('myString'); // inside traits
×
×
  • Create New...