-
Posts
1,423 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Juergen
-
Good morning @da² I have wrapped my head around your problem and I have found a possibility to check file uploads against the value of an input field by using a custom validation. In the following example you have 2 form fields: Field 1 is a text input where you have to enter the name of a file (for example "myfile") without the extension Field 2 is the file upload field where you upload a ZIP folder with different files. Validation check In this simple example it will be checked if there is a file with the filename entered in field1 present inside the files uploaded in field 2. In other words: Check if the uploaded ZIP folder contains a file with the filename for example "myfile" in this case. If yes, then the form submission is successful, otherwise an error will be shown at field 1. This is only a simple scenario to demonstrate how a custom validation could be done. You have to write your own validation rules. Now lets write some code for this example: The first one is the custom validation rule. Please add this code to your site/init.php. If this file does not exist, please create it first. <?php namespace ProcessWire; \Valitron\Validator::addRule('checkFilenameInZip', function ($field, $value, array $params) { $fieldName = $params[0]; // fieldname of the upload field $form = $params[1]; // grab the form object // get all the files from the given ZIP folder as an array $zipfiles = $form->getUploadedZipFilesForValidation($fieldName); // now start a validation rule with the value of this input field ($value) and the files inside the ZIP folder if (!is_null($zipfiles)) { $fileNames = []; foreach ($zipfiles as $zipfile) { $fileNames[] = pathinfo($zipfile, PATHINFO_FILENAME); } return in_array($value, $fileNames); } return true; }, 'must be a wrong filename. The ZIP folder does not contain a file with the given name.'); I have named the validation rule "checkFilenameInZip" in this case. The important thing is that you have to add 2 values to the $params variable: The name of the file upload field The form object itself To get all the files that were uploaded via the upload field, you can use one of these methods of the form object. getUploadedZipFilesForValidation (outputs only files of a ZIP file) getUploadedFilesForValidation (outputs all files of a file upload field) Important: To use these 2 new methods you have to update to the latest version of FrontendForms (2.3.14)! All ZIP files will be extracted automatically. Nested ZIP files are supported too. Now lets create the form $form = new \FrontendForms\Form('testform'); $form->setMaxAttempts(0); // set 0 for DEV $form->setMaxTime(0); // set 0 for DEV $form->setMinTime(0); // set 0 for DEV $form->useAjax(false); // set false for DEV // input field containing a filename $filename = new \FrontendForms\InputText('filename'); $filename->setLabel('Name of file'); $filename->setNotes('Please enter the name of the file without extension.'); $filename->setRule('required'); $filename->setRule('checkFilenameInZip', 'fileupload1', $form);// here is the new custom validation rule: Enter the name of the file upload field as the first parameter and the form object as the second parameter $form->add($filename); // the file upload field $file1 = new \FrontendForms\InputFile('fileupload1'); $file1->setRule('required'); $file1->setLabel('Multiple files upload'); $form->add($file1); $button = new \FrontendForms\Button('submit'); $button->setAttribute('value', 'Send'); $form->add($button); if ($form->isValid()) { // do what you want // $extractedFiles = $form->getUploadedFiles(true); // returns all uploaded files including extracted ZIP folder files // $nonExtractedFiles = $form->getUploadedFiles(); // returns all uploaded files but Zip files are not extracted // $values = $form->getValues(); // returns all submitted form values } echo $form->render(); Copy this code and paste it inside a template for testing purposes. Upload a ZIP folder and add the name of a file inside the "filename" input field. If the file exists in your ZIP folder you will succeed. Please note: The extraction of the ZIP files is done only once during the validation process. You can get the extracted files afterwards inside the isValid() method via the getUploadedFiles() method from the temporary upload folder. Use the return of this method to do some more work with the uploaded files. Take this example as a starting point for your own validation rules and let me know if it works for you. I think this is the only possibility to get what you need. Another hint: User browser validation in FrontendForms to make client side validation first by enabling it in the backend.
-
Hello @da² Thank you for your detailed explanation! Now I know what your goal is. The first problem by doing additional validations inside the "isValid()" method after all form values are valid is that the form has "status valid" and therefore the form values will be emptied to prevent double form submission. That is the reason why the form is empty. This can be prevented by adding the useDoubleFormSubmissionCheck() method with value false to the form object. The second problem is that the validation of max attempts (if enabled) will be reseted if the form is valid, but it would take further attempts if you are doing additional validations inside the isValid() method. So the max attempts validation in this case does not work. But this can be disabled by using the setMaxAttempts() method and setting the value to 0. So adding additional validations inside the isValid() method is a very dirty solution and the module is not developed to support such a scenario. So the goal you want to achive is very difficult to achive. I am afraid that the module will not be able to solve your problem, but I will wrap my head around it and maybe I have an idea.🤔
-
Hello @da² I have added a new validation rule that could be interesting for your usecase: uniquestringvalueofpwfield It checks for the uniqueness of a value inside of a specific ProcessWire field. Lets assume you have stored your gaming usernames inside the PW field with the name "gamer_name" which you have added to the user template. Then you could validate the gaming username with the new validator like this: $gamername = new \FrontendForms\InputText('gamername'); $gamername->setLabel('Gamer name'); $gamername->setRule('required')->setCustomFieldName('This gamer name'); $gamername->setRule('uniqueStringValueOfPWField', 'gamer_name', ['user']); $form->add($gamername); As you can see, you have to add the name of the PW-field (= gamer_name) as the first parameter. The second parameter (= the name of the template") is not mandatory, but it makes sense in this case to restrict the search only for entries in the user template. Add this as an array, because it also possible to search in multiple templates). Otherwise the search will be globally on all templates where this ProcessWire field is added. To use the new validator please update to 2.2.13 Best regards Jürgen
-
Hello @da² looks like it is not so difficult 🙂. First of all I would take a look at the following Inputfield: https://processwire.com/modules/fieldtype-text-unique/ This looks interesting and if it fits to your needs, than add it to the user template in the backend as the field containing the gamer name. Second, take a look at the uniqueEmail or uniqueUsername validators, which are already included in FrontendForms. These validators could be used as a starting point for your own validation rule. Take them as an example to create your own custom rule for gaming names.
-
After taking a look at the code, I guess the best approach would be to go with a custom validation rule, because there is so much going on inside the isValid() function that must be checked in the setErrorMessageToField() method too. Can you explain which kind of validation you need in this case. Maybe I can help you to create the custom rule. You can also send me a PM with the code you have so far.
-
This is caused by the TracyDebugger - I have forgotten to remove this call after Debugging. Please go to the Form.php and find the following line and remove it: bd($this->formErrors); Then this error will be gone. I have removed the TracyCall on Github too. This is strange, because it has nothing to do with the PHP code. Please take a look at your CSS classes. On my site the color is white. Yes, this is a browser security behavior and independent which browser you will use - file upload fields will always be empty after submission (whether successfully or not). I will test it with file upload fields and see if I can reproduce the issues. For now, please remove the bd() call first.
-
Yes, that is the purpose of this variable: To add additional values to the validator. You can add several values as an array to the validator. To get a specific value from this array, you only have call it by its key (fe $params[2] will return the array value on the position with the key 2). You will find a lot of examples on how to write custom rules inside the CustomRules.php file. There you can study how to use the $params variable to test conditions with it.
-
Hello @da² I have added a new method to trigger an error message to a field manually: setErrorMessageToField() Here is a small example on how to use it: $form = new \FrontendForms\Form('testform'); $form->setMaxAttempts(0); $form->setMaxTime(0); $form->setMinTime(0); $firstname = new \FrontendForms\InputText('firstname'); $firstname->setLabel('Firstname'); $firstname->setRule('required')->setCustomFieldName('The first name'); $form->add($firstname); $button = new \FrontendForms\Button('submit'); $button->setAttribute('value', 'Send'); $form->add($button); if ($form->isValid()) { $form->setErrorMessageToField($firstname, 'This is my custom message'); } echo $form->render(); If the "default validation" was successful, then the error message will be displayed under the "firstname" field in this case. You can use it to make another validations inside the isValid() function to check the submitted form values against other conditions. If the conditions fail then you can output this manually triggered error message like written above. To use the new method, you have to replace the file site\modules\FrontendForms\Formelements\Form.php with the one from Github or you simply add the new function to your Form.php. Please let me know if this helps.
-
Hello @grewr11 Thanks for pointing out this issue. I have removed the sanitizer for names on the "Name" field, because usernames are allowed to have numbers in it. This was a thinking mistake. Now it should work as expected. Please replace the following file to get it working: https://github.com/juergenweb/FrontendComments/blob/main/FrontendCommentForm.php I have discovered another issue, with WireMail and localhost, so please replace the following file too: https://github.com/juergenweb/FrontendComments/blob/main/Notifications.php You will find all information about the changes in the changelog.md. I haven't worked on this module in a long time, so there could be more problems. Please report any problems, I will try to solve them as soon as possible. Jürgen
-
Hello @ttbb I have tried to reproduce the issue you had described, but in my case everything works as expected. I have used Bootstrap 5 and 2 contact forms side by side using the "row" and "col" classes. This works as expected as long as the errors are form errors (wrong or missing input data). But I have discovered an issue by showing the alert box if the form has been submitted too fast. In this case it did not jump to the top of the form properly to show the alert box that informs the user that the form has been submitted too fast. Therefore I have made some changes to make this work properly. Take a look here at the changelog file. So please update to the latest version 2.3.11 and let me know if there are some problems left. Best regards Jürgen
-
Hello @ttbb This should work by default 😐, so there is no need to add it to the JS manually. To be more specific: If a form submission is successful or has errors, than the page jumps to the start of the form (not to the top as you have written), so the user can see the success or the error message (independent of the length of the form). This should work with or without AJAX. If it does not work in your case, please post your form code here or send it to me via PM and I will test it. Best regards Jürgen
-
This module is nothing special. It adds a small JavaScript and CSS file to your page to create a nice snowfall. To adapt the snowfall to your needs you have some configuration options like snowfall density, min and max size of the snowflakes, duration time of the snowflakes and more. You have the option to start and stop the snowfall manually or depending on the date. At the moment you will find a live example here: https://www.schulfreund.at/ This example is only active in the winter season - not the whole year 😉 You can find the full docs and description and the download possibility of the module here. Have fun and enjoy the winter!!
- 3 replies
-
- 11
-
-
Hello @ all The new version 2.3.0 comes with a brand new feature: the possibility to turn a form into a multi-step form. Many thanks to @Jan S. for the idea and the support in testing during the development of the new feature. In a nutshell: A multi-step form is a long form divided into multiple steps. At the end of each step, the user clicks on a "Next" button to go to the next section. In the final step a summary of the data entered will be displayed to the user. The user now has the option to change some of the data if necessary before finally submitting the form. Typical use cases are very long forms, surveys or quizzes. I have written an extra chapter in the docs with a lot more information, which you can find here. There are only 2 restrictions for multi-step forms to work properly: The send button must be after the last step (by the way, it wouldn't make sense to put it anywhere in between ;-)) File upload fields must be placed in the last step (otherwise they won't work) To turn a form into a multi-step form, you only need one new method: addStep() You need to add this method to the form object in the places where you want to make the cut: $form = new \FrontendForms\Form('simpleform'); $firstname = new \FrontendForms\InputText('firstname'); $firstname->setLabel('Firstname'); $firstname->setRule('required'); $form->add($firstname); $lastname = new \FrontendForms\InputText('lastname'); $lastname->setLabel('Lastname'); $lastname->setRule('required'); $form->add($lastname); $form->addStep(); // first step $email = new \FrontendForms\InputEmail('email'); $email->setLabel('Input Email'); $email->setRule('required'); $form->add($email); $form->addStep(); // second step $birthday = new \FrontendForms\InputDate('date'); $birthday ->setLabel('Birthday'); $form->add($birthday ); $form->addStep(); // third step $message = new \FrontendForms\Textarea('message'); $message->setLabel('My message'); $form->add($message); $form->addStep(); // fourth step $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(); That is all! You can find more examples here. To be informed of all the changes in this release, please read the changelog. As always, please keep an eye on whether everything is working as expected and report any issues you discover here or directly on GitHub. Jürgen
-
I have fixed the JS bug for displaying the badges on single upload fields: Please replace the JS code with this one: https://github.com/juergenweb/FrontendForms/blob/main/frontendforms.js You can remove this line too, because it is true by default, you only have to use this method if you want to prevent the badges from being displayed. In this case you have to set the parameter to false. You can also try to set the max filesize to 50MB and see what happens. Let me know.
-
Good morning @da² Remove this line to show the badge, but anyway: it works properly on my side on single and multi file upload fields. You are right, I will check this!! BTW: You do not have to write the filesize like "524288000" -> you can write "500 MB" instead and it will be converted to "524288000" automatically. I have never tried it with such a high upload max size - please try it with a lower size (fe. set it to 50 MB) and take a look what happens). Another aspect could be that there are 2 different max size config settings: Max upload file size (the max size for an individual file) Max post size (the max size for all uploaded data via a POST request The validator only checks for the max file size, not the max post size. So for testing purposes please set the max file size to 50 MB, remove the showClearLink() and take a look what happens.
-
Hello @da² I have tried to test the file size restriction with various files, but in my case I could not find any issues. It has worked every time. Do you see the red badge warning under the file input field too as in my screen shot below before you submit the form (if you have selected a file larger than allowed)? If you see this red badge, the form could not be valid after the form submission. Please also check the file size in the badge (in this case it is 12.81 MB). Maybe you could provide a screen shot before the form submission? Please check if you have the latest version too! Best regards
-
Hello Jan, I did not find any infos about the possibility of creating multi-step forms inside the form builder docs, but maybe I have overlooked it too.😉 I will take your request as an idea about a new feature for the future and maybe I will integrate the possibility of creating a multi-step form out of the box in an easy way. I have some ideas but I guess this will take a lot of time, so it cannot be realized in the next days.
-
Good morning Jan! I guess you have installed the language support module first?? If not, here is a little screen cast how to do it. You will need it to translate strings. Languaga install.MP4 You are German speaking too , so you could install the language files for German translations from the module itself as shown in the clip. Now every English phrase should be translated into German, but if you are not satisfied with the translation text, you can overwrite it with your own text (but be aware that every time you install the translation files again, every changes will be overwritten). You will find the file containing the text for the privacy checkbox here: By clicking the "Edit" link you will be redirected to the editable page: There you can make your changes if you want. Not out of the box. Maybe you can use URL segments and put each form on a segment page. Example if form 1 is valid, then you will be redirected to the URL segment 2 which contains form 2 and so on. You will need to store the form values inside a session variable. At the end (last URL segment) you can take all the values stored in the session variable and output it to the user (as a kind of list of entered values) Every value output to the user should have an edit link next to it and if the user clicks on the link, he will be redirected to the appropriate form, where he can change the value. I would add a query string at the end of the link to determine that the user wants to change something. If the user have changed the value, everything is valid and the query string is present in the URL then the user will be redirected directly to the last page again, where he can check his entered data once more. If there is a need for changing another value, then he clicks on the next edit link and so on. That was my idea, but you could also write a question in the general forum about this issue. I guess there are some people who have written a multi-page form and can give you a hint how to solve it. FrontendForms only creates single forms, but it is not impossible to combine the values of multiple single forms by using sessions. Good luck!
-
Good morning @Jan S. Thanks for reporting these issues. I have fixed them and updated the module version to 2.2.55. Alternatively you can replace the following files, which contain the changes: https://github.com/juergenweb/FrontendForms/blob/main/Formelements/Form.php https://github.com/juergenweb/FrontendForms/blob/main/Formelements/Inputelements/Inputfields.php PHP 8.4. is more strict than the previous version and in addition I use declare(strict_types=1); on all PHP files in FrontendForms. As a result, any warning will be treated as an error. So please test if it works now and let me know if you discover some issues again. Thanks!!