Jump to content

Juergen

Members
  • Posts

    1,028
  • Joined

  • Last visited

  • Days Won

    5

Juergen last won the day on August 14 2021

Juergen had the most liked content!

Profile Information

  • Gender
    Male
  • Location
    Linz
  • Interests
    Playing electric guitar (Rock, Heavy), flying model helicopters

Recent Profile Visitors

6,141 profile views

Juergen's Achievements

Hero Member

Hero Member (6/6)

572

Reputation

19

Community Answers

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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.
  6. 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
  7. 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
  8. 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
  9. 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();
  10. 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
  11. 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.
  12. 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
  13. 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.
  14. Silly mistake!!! Trait is not a class, so using $this was not a good idea 😒 // use __('myString'); // and not $this->_('myString'); // inside traits
  15. 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.
×
×
  • Create New...