Adress field / IBAN validation
-
Hi there,
I hope you are doing well.
Is it possible to validate Adress fields and IBAN-numbers in Forminator, so that no incorrect data is submitted?
Thanks a lot and kind regards
-
I hope you’re well today and thank you for your question!
This will require additional custom code but, fortunately, we already have it ready.
You’ll find the code here:
https://gist.github.com/wpmudev-sls/8ca771c9cde2f583b20280b23291e9cc
To use it on site you’d want to add it as Must Use plugin:
1. create an empty file with a .php extension (e.g. “forminator-validate-iban.php”)
2. copy and paste code into it
3. in this part of the code$forms = array( 92 => array( 'text-2' ), );
you will need to replace
– number 92 with your form ID (form ID is the number you see in form’s shortcode)
– text-2 with ID of your text field used for IBAN4. save the file and upload it to the “/wp-content/mu-plugins” folder of your site’s WordPress installation.
If there’s no “mu-plugins” folder directly in “wp-content”, just create an empty one first.
Best regards,
AdamHi Adam @wpmudev-support8,
thanks a lot – it works great!
Is it also possible to validate:
- Germany adress fields (street name + house number in one field, postal code in another field)?
- (mobile) phone number?
Thank you very much for great support and kind regards
Technically speaking, it would be possible to validate the address I believe, but we’d need to know exactly how to validate it – in terms of “validation rules”, so to say.
So if you can provide some sort of a (relatively) simple rules that could be used for that, we can look into it and see if it could be done.
As for phone numbers, there’s a built-in validation option. Once you add a “phone” type filed to the form, there’s an option to select “National” validation type in field settings – then you can select a country for which the number should be valid.
Best regards,
AdamHi Adam @wpmudev-support8,
thank you very much for the quick reply.
With the phone number I got it now, thanks! But is there any way to use css to edit/delete the flag in the field?
Regarding the address fields I have the following scheme:
- First there is the street and the house number in an address field, e.g. “Musterstra?e 8”.
- In the next address field is the postal code, e.g. “12345”.
- In the third and last address field is the city, e.g. “Berlin”.
The postal codes in Germany always have 5 digits. There is no specific rule for the street and the house number. Does it make sense here to include all street names (and postal codes) available in Germany in the php snippet or would this be way too much and would overload the system or cause delays?
Thanks a lot an kind regards
Hi @thankssforhelp,
But is there any way to use css to edit/delete the flag in the field?
The following CSS can help with hiding the flag on the Phone number field, please give it a try.
.iti__flag-container { display: none; }
Does it make sense here to include all street names (and postal codes) available in Germany in the php snippet or would this be way too much and would overload the system or cause delays?
It should be possible to check if the provided value is present in a database table or CSV file using a custom code, but it might cause a small delay while filling up the form. Can you please provide the data with which the fields should be validated so that we could check this with our developers?
Kind Regards,
Nebu JohnHi Nebu John @wpmudevsupport14,
thank you for your response!
.iti__flag-container { display: none; }
This one works, thanks a lot!
?Can you please provide the data with which the fields should be validated so that we could check this with our developers?
Is it possible to implement this with Forminator as described here: https://da-software.net/2018/03/stadt-und-ort-in-formular-mit-plz-autovervollstaendigen/
As soon as the 5-digit German postal code is entered, the city is autocompleted via the geonames database. Then I would only have to validate that a 5-digit postal code is entered.
Thank you very much and kind regards
Hello @thankssforhelp ,
As soon as the 5-digit German postal code is entered, the city is autocompleted via the geonames database. Then I would only have to validate that a 5-digit postal code is entered.
At the moment this is not possible, but Forminator’s team is already working on that feature.
kind regards,
KasiaHi Kasia @wpmudev-support2,
thanks for your response.
But would it be possible to use this code via mu-plugin?:
<script> $('#PLZ').bind('keyup change', function (e) { if ($(this).val().length > 4) { var ort = $('#Ort'); $.getJSON('https://secure.geonames.org/postalCodeLookupJSON?&country=DE&callback=?', { postalcode: this.value }, function (response) { if (response && response.postalcodes.length && response.postalcodes[0].placeName) { ort.val(response.postalcodes[0].placeName); } }) } else { $('#Ort').val(''); } }); </script>
I think I can handle the rest then.
Thanks a lot and kind regards
Thanks for response!
I gave it a go and… actually yes, it can be integrated via MU plugin, with some slight changes. Here are the steps.
1. first, you need to have an account registered and active with the geonames.org service and you must enable it for use of webservices:
– login to geonames.org
– go to “https://geonames.org/manageaccount (while logged-in)
– you should see “the account is not yet enabled to use free web services, click here to enable” message – so click to enable
– you should get a confirmation message on screen that it’s enabled.If you have already done that, you’re good to go.
2. Now edit your form and for the field where you put zip code go to “styling” settings and put this in the Additional classes
PLZ
note – there’s no # or . characters in front, only letters, like this
https://app.screencast.com/K1NchSQM2Hwcz
3. and for the field which you want to be auto-completed, put this in “styling” settings
Ort
(again, no # or dot)
https://app.screencast.com/Iff7dW0P9Fh3M
3. Now add this code as MU plugin
<?php add_action( 'wp_footer', 'forminator_geo_zip_autocomplete', 99 ); function forminator_geo_zip_autocomplete() { ?> <script> jQuery(document).ready(function($) { $('.PLZ input').bind('keyup change', function (e) { if ($(this).val().length > 4) { var ort = $('.Ort input'); $.getJSON('https://secure.geonames.org/postalCodeLookupJSON?&username=YOUR_USER_NAME&country=DE&callback=?', { postalcode: this.value }, function (response) { if (response && response.postalcodes.length && response.postalcodes[0].placeName) { ort.val(response.postalcodes[0].placeName); } }) } else { $('.Ort input').val(''); } }); }); </script> <? }
– create an empty file with a .php extension (e.g. “forminator-autocomplete-zip-location.php”)
– copy and paste code into it
– in the code make sure to replace theYOUR_USER_NAME
string with your geonames.org username (same username that you use to login to the services)
– save the file and upload it to the “/wp-content/mu-plugins” folder of your site’s WordPress installation.
It worked for me just fine this way, with both fields being just a regular “input” fields (if they are of different types, it may require adjustments but such adjustments would go out of scope of this support and we won’t be able to assist).
Important note: form cannot have “load form using AJAX” option enabled – code will not work this way.
Best regards,
AdamHi Adam @wpmudev-support8,
thank you so much for your support, it just works great and super smooth! (:
Kind regards
Good afternoon,
I’m not a programmer and I was wondering what the code is like if you have multiple forms?Something like below?
I’d love to hear it. Nice day!$forms = array( 92 => array( 'text-2' ), 92 => array( 'text-2' ), 92 => array( 'text-2' ), 92 => array( 'text-2' ), );
HI @domein747
I think you are referring to the solution shared earlier in this post, right?
https://www.ads-software.com/support/topic/adress-field-iban-validation/#post-16725465
If yes, then you are right, this will be the way. Let’s say you have three forms with IDs 92, 121, 123 and text fields (for IBAN) respectively being “text-2”, “text-1” and “text-3”. So the part of code would be
$forms = array( 92 => array( 'text-2' ), 121 => array( 'text-1' ), 123 => array( 'text-3' ), );
I hope this helps.
Please note: if you have any additional/other questions related to this, please start a separate ticket of your own, as per this forum guidelines.
Best regards,
AdamHi Adam,
I mean that indeed. Thank you!
I have put the php file in the directory (/wp-content/mu-plugins) and also made the correct changes and the permissions are also correct.
Unfortunately it doesn’t work for me. I am currently still using the free version of the plugin. I do see the plugin in wordpress when I’m logged in. (must-used)A beautiful day to you!
Regards, Gert
Hi @domein747,
I tested the code on my site and it works fine with the mentioned suggestion. It isn’t clear what exact issue you are facing after making the changes, however, it looks more specific to your side.
Please do note that it would be better to open a new ticket in such instances rather than replying in an existing users ticket to avoid any miscommunication.
Could you please open a new ticket with us and also mention what exact issue you notice on your side along with a screenshot if possible and also refer to this ticket, so that we could assist you better.
URL to open a new ticket:
https://www.ads-software.com/support/plugin/forminator/#new-topic-0Regards,
Nithin
- The topic ‘Adress field / IBAN validation’ is closed to new replies.