-
Posts
1,392 -
Joined
-
Last visited
-
Days Won
17
Everything posted by Juergen
-
Problem using PHP script as image src in ProcessWire
Juergen replied to Juergen's topic in Module/Plugin Development
Thanks @teppo I have thought that this will be the problem. I think I will create an extra folder with the required permissions for this reason. -
Hello @ all I want to create a captcha image for a form, which can be reloaded on demand, if the user cannot read the captcha. The form will be created by a module, that is why this question is inside this category. For this reason I want to create the captcha image on the fly by using a PHP file as image source instead of an image file. // in a template file $path = $config->urls->assets.'files/captchaimage.php'; echo '<img src="'.$path.'" />'; As you can see: the image source is not an image file (fe. captcha.png), it is a PHP file which creates the image on the fly. I have added this file to site/assets/files because this folder can be reached from outside. The captchaimage.php consists of the following code (only for testing purposes): <?php header("Content-Type: image/png");//change the php file to an image $im = @imagecreate(110, 20) or die("Cannot Initialize new GD image stream");//creates an image with the resolution x:110 y:20 $background_color = imagecolorallocate($im, 0, 0, 0);//create a color with RGB $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);//draws text to the image with the font:1 xpos:5 ypos:5 imagepng($im);//sends the image data to the user imagedestroy($im);//destroys the image from the server ?> This is not the real code for producing the captcha - it is only a simple code to create an image. My problem is, that I cannot output the image on the template. I always get the message, that the image could not be loaded. Can someone point me in the right direction, why this does not work? Thanks in advance
-
New URL hooks do not consider user language
Juergen replied to Juergen's topic in Module/Plugin Development
I found a workaround: Put the user language inside a session variable and call this session variable inside the hook. public function init() { //set language id inside a session variable for later usage in url hook $this->wire('session')->set('userlang', $this->wire('user')->language->id); // Show details about the blocked IP address inside a panel $this->wire->addHook('/detail-view/{ip}', function ($event) { $userLang = $this->wire('session')->get('userlang'); // grab current user lang from session $this->wire('user')->language = $userLang; // here comes the code }); } Not really elegant, but it works. Now translatable strings work as expected. -
New URL hooks do not consider user language
Juergen replied to Juergen's topic in Module/Plugin Development
Maybe could it be the same issue as in this topic? Bug report - Get $user->language in hook Pages::saveReady -
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.
-
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?
-
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?
-
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.
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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();
-
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