TOPIC:

validate text fields 1 year 10 months ago #230157

  • Topic Author
  • Mister.Miracle
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 99
  • Karma: 1
  • Thanks: 1
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.

Please Log in or Create an account to join the conversation.

validate text fields 1 year 10 months ago #230166

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
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

Please Log in or Create an account to join the conversation.

validate text fields 1 year 10 months ago #230232

  • Topic Author
  • Mister.Miracle
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 99
  • Karma: 1
  • Thanks: 1
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

Please Log in or Create an account to join the conversation.

validate text fields 1 year 10 months ago #230237

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
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

Please Log in or Create an account to join the conversation.

validate text fields 7 months 1 week ago #238596

  • Topic Author
  • Mister.Miracle
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 99
  • Karma: 1
  • Thanks: 1
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

Please Log in or Create an account to join the conversation.

validate text fields 7 months 1 week ago #238600

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
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

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.052 seconds

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!