element validation with strlen?

AlfredJK

Member
Hi, i try to validate a element to check if the element filled out with 5 characters. In the element validation i added this php-code.

$ww = $formModel->getElementData('table___element');
if (strlen($ww) == 5) {
return true;
}
else {
return false;
}

but no error message is shown when i filled the element with 2 characters. What's wrong?
 
Isn't this just enough in the condition field?

PHP:
return strlen( $data ) < 5;
 
Unfortunately, this is what I had already tried. Also without succes. The same syntax in the php field is also without succes :-(
 
Have you tried with $formModel->getElementData('table___element', true); ?

And you replaced table___element by the real full name of the element of course?
 
Hi jfquistiaux,

i didn't tried this, but changing my code nothing happend. The code is now:

$ww = $formModel->getElementData('zorgverlener___device_wachtwoord',true);
if (strlen($ww) == 5) {
return true;
}
else {
return false;
}

The 'Condition' field is empty. I have read that the condition must be filled. Thats correct? If so - what's the best thing to fill out there?

When i check the sourcecode of the webpage after loading i found nothing of the validationcode. Is that correct?

thanks in advance for your help!
 
What type of element is zorgverlener___device_wachtwoord?

I tested this validation on a simple field element "name" in the table "ratings", and it is working as expected (I need to fill in 5 characters or it fails).
Here are the screenshots of my validation settings:
2014-06-04 07.48.04.png2014-06-04 07.46.17.png
 
type is: field input type = text - max length = 5 - In the database is the type varchar(5) - below the screenshots
 

Attachments

  • pw1.png
    pw1.png
    17.5 KB · Views: 184
  • pw2.png
    pw2.png
    37.9 KB · Views: 187
  • pw3.png
    pw3.png
    24.7 KB · Views: 170
Well, providing that your PHP validation is set on "Match" and not "Replace", the only difference I see is that I made my test with the default varchar(255) setting. I don't think this is relevant, but you may try and change it.
What is actually happening: the validation always fails or always succeed? Is the data recorded in the table?
 
Yes - validation is set to Match and the data is correct recorded in the database. I will set the length to default varchar(255) and test again. Thanks for your help!
 
changing to varchar(255) has no effect. I have two different lists on the same table. One for admin (show all records) and one for the logged in user (show only own record). Is that possibly the problem?
 

Attachments

  • pw4.png
    pw4.png
    7.8 KB · Views: 158
yes i did - no better result - no error message at all. I'm afraid i do something terribly wrong - but don't no what ;)
 
You mean that with that validation, you can submit the form?
If so, that means that the validation does not run at all. It seems that another user is reporting validations not working.
Have you updated your Fabrik intall to the latest GitHub?
 
sorry for the late reaction - i was on holiday and traveling.

On your question - yes - even with the simple validation the form is submitted.
I have installed the latest official release of Fabrik (3.1) Joomla version 3.3.0

i never downloaded direct from Github - suggestions?
 
If you are running Joomla 3.3, you must upgrade your Fabrik install with the latest GitHub release. There are issues with validations with the core 3.1 version.
 
okay - unfortunately i have not yet many expirience with GitHub. Would you send me the URL where i can download the latest release? Thanks in advance.
 
hi - YES

update direct from GitHub was succesfull! Thanks! Validation works! Great - thanks for the support.

Fabrik 3.1.1

Validation code:
$ww = $formModel->getElementData('table___element',true);
if (strlen($ww) == 5) {
return true;
}
else {
return false;
}
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top