validate text fields

  • Mister.Miracle
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 94
  • Karma: 1
  • Thank you received: 1

Mister.Miracle created the topic: validate text fields

hello,

i want to validate my text field in this way, that there has an error-message, if there is a text xy given in the textfield.
so i use the code
function ff_FIELDNAME_validation(element, message)
 {
  if(element.value='xy'){
   return 'errormessage i want to be shown \n';
  }
  return '';
 }

now... there are the problem: if the errormessage is thrown, all entered values are lost and i have to enter everything again. i think, this is not usable for the user... or not nice :-( How can i throw the errormessage and show the user the entered values again, so he has only to correct the values.

2.) how can i validate more than one text-string... i want to check xy, yz, xyz and so an. Should i use switch?

3.) Validating german date. i want, that entered date-fields must have the form dd/mm/yyyy. How can i be to check this in a custom field... and i have to validate also, that the date is not older than today (not yesterday and before). Should i validate it in this feature or can i choose a way, no older date are shown in the date-display. But... the user could enter it also by hand. so i have to validate the value.
#230157
  • Posts: 2823
  • Karma: 95
  • Thank you received: 379

mihaela replied the topic: validate text fields

Hello,

1. To validate a textfield in a way that error message is shown if "xy" is entered use the following validation script:
function ff_FIELDNAME_validation(element, message)
{
    if (element.value == "xy") {
        if (message=='') message = element.name+" faild in my test.\n"
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';
} // ff_FIELDNAME_validation
That way no entered data will be erased after the error message is shown. User will be able to edit his entry.

2. To validate the textfield for few strings you can simply add more OR statements in the if clause like this:
function ff_FIELDNAME_validation(element, message)
{
    if (element.value == "xy" || element.value == "yz" || element.value == "xyz") {
        if (message=='') message = element.name+" faild in my test.\n"
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';
} // ff_FIELDNAME_validation

3. To validate the date field and also to check whether the selected date is in the future use the calendar element and in the Validation code area put the following validation code:
function ff_CALENDARITEMNAME_validation(element, message)
{
    if(element.value.split("/").length != 3){return message == '' ? "Date must be in format dd/mm/yyyy.n" : message}
 
     var vDate = new Date(Number( element.value.split("/")[2]),Number(element.value.split("/")[1]-1),Number(element.value.split("/")[0]),0,0,0).getTime();
 
     var today = new Date();
 
     today.setHours(0);
     today.setMinutes(0);
     today.setSeconds(0);
     today.setMilliseconds(0);
     today = today.getTime();
 
     if(vDate < today)
     {
          if (message=='') message = "Selected date mustn't be in the past.n";
          return message;
     }
     return '';
} // ff_CALENDARITEMNAME_validation

Let me know whether this works as you wanted.
If you have more questions, feel free to ask.

Regards,

Mihaela
#230166
  • Mister.Miracle
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 94
  • Karma: 1
  • Thank you received: 1

Mister.Miracle replied the topic: validate text fields

the code of validation of text dont work.
No error-message, nothing.

How can i check, whether the code works on my website right?

Thanks
#230232
  • Posts: 2823
  • Karma: 95
  • Thank you received: 379

mihaela replied the topic: validate text fields

Hello,

I will explain a bit more how it is supposed to work so you can check whether you have set everything accordingly.

You should go to Properties of the textfield that you want to validate. Then in the Validation section you should check the Required checkbox.
Furthermore, set Validation to Custom. Then in the code area below put the following code:
function ff_FIELDNAME_validation(element, message)
{
    if (element.value == "xy") {
        if (message=='') message = element.name+" faild in my test.\n"
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';
} // ff_FIELDNAME_validation
You should replace the FIELDNAME with the Name of that textfield (not the Title).
Save the changes and Preview your form.
In that textfield enter xy, literally, and when you try to submit the form, error message should appear.

Let me know whether you have set everything as explained and did it work.
If you have more questions, feel free to ask.

Regards,

Mihaela
#230237
  • Mister.Miracle
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 94
  • Karma: 1
  • Thank you received: 1

Mister.Miracle replied the topic: validate text fields

Hello,
i want to validate a select-list with the coding:
function ff_Kollege_validation(element, message)
{
    if (element.value =="keine Auswahl getroffen ") {
        if (message=='') message = "Eintrag Unterstützender Kollege wurde nicht ausgewählt. Bitte entsprechend korrigieren!.\n"
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';
} // ff_Kollege_validation
but it dont work.

the select list is created by a script:
(...)$temp_result .= "0;keine Auswahl getroffen;keineAuswahl \n";(...)

what should i check: keine Auswahl getroffen or keineAuswahl?

Thank you for helping
#238596
  • Posts: 2823
  • Karma: 95
  • Thank you received: 379

mihaela replied the topic: validate text fields

Hello,

You should check for keineAuswahl because what is saved to record is what is after the second semicolon.

The list is defined like:
0;Title1;value1

Let me know whether you have managed to make it work.

Regards,

Mihaela
#238600
Moderators: ForumSupporttomeperica
Time to create page: 0.070 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here