Forums

Custom server side validation

webbuilders 02 Oct, 2012
I want to validate all fields at different alphabet. The problem is that only english chars are validated properly by default.

I have seen the tutorial http://www.chronoengine.com/faqs/2622-my-alphabet-uses-characters-other-than-a-z---.html but i have some questions...

I have made the form and i have added at all my fields the type of validation i wanted. Then i created the events i wanted and the form was working properly. Finally i saw that Tutorial and i added a "Custom server Side Validation "

I used the code with many regex expressions but none worked. Like not even seeing that php. Shall i change anything else ??

The only thing i want is to make the validation accept one more alphabet. Is there a better way ??

Is there something else i shall do ?
GreyHead 02 Oct, 2012
Hi webbuilders,

Provided that your regex does what you want and the Custom Serverside Validation action is correctly set up there is nothing else required.

What alphabet are you checking and what code do you have in the action?

Bob
webbuilders 03 Oct, 2012
I am checking greek alphabet. I have the Serverside Validation "onSubmit" event with the code...

<?php
$data =& $form->data['input_name'];
$regex = '\p{InGreek}';
if ( isset($data) && $data ) {
  if ( preg_match($regex, $data) === false ) {
    $form->validation_errors['input_name'] = "Invalid data";
    return false;
  }
}
?>
GreyHead 03 Oct, 2012
Hi webbuilders,

A bit of research required but this version seems to work OK
<?php
$data =& $form->data['input_text_1'];
$regex = '/\A\p{Greek}+\Z/iu';
if ( isset($data) && $data ) {
  if ( preg_match($regex, $data) === 0 ) {
    $form->validation_errors['input_text_1'] = "Invalid data";
    return false;
  }
}
?>
This has a different regex from yours and critically the test is === 0

NB === false won't work here, I got that wrong in the FAQ :-( It is now corrected. (false is returned if there is an error in the test, zero is returned if there is no match.

This passes 'ολκκ' and fails 'abde'

Bob
webbuilders 03 Oct, 2012
The Action is not seems to working can you please check it ?

Shall i replace "input_text_1" with the field name i want to validate?
Shall i disable the Validation from the element?
How can i let pass both greek and english ?
GreyHead 03 Oct, 2012
Hi webbuilders,

The Action is not seems to working can you please check it ?

I have, it works OK.

Shall i replace "input_text_1" with the field name i want to validate?

Yes

Shall i disable the Validation from the element?

No, you don't need to.

How can i let pass both greek and english ?

Change the regex to allow both, and numbers, . . .

Bob
GreyHead 03 Oct, 2012
Hi webbuilders,

You can see a copy of your form here with the serverside validation working OK. I copied the code from this thread and changed 'input_name' to 'name' to match your form.

Do you have an Event Loop in he On Fail event of the Custom Serverside Validation action?

Bob
webbuilders 04 Oct, 2012
Thanks for your help

But the form you have copied has exactly the same problem with mine!
If you add at first field greek chars like "τεστ" and fill in all others in english just to test you will see that the validation will pop up an error at the first field that accepts only alphabetic characters. That shows that the validation with greek chars is not working but i would like if it works to work with both english and greek.

My problem was that from the beggining and sorry if my english were bad.
GreyHead 04 Oct, 2012
Hi webbuilders,

I'm sorry I do not understand what you are saying here. You asked for Serverside validation for Greek characters and that is working on my test form with the code I have posted here.

If you want both Greek and English characters then you will need to change the regex to accept both.

Bob
webbuilders 04 Oct, 2012
Check the image here http://postimage.org/image/obde73991/
You will see that the Serverside validation for greek is not working. It does not accept greek chars


Hi webbuilders,

I'm sorry I do not understand what you are saying here. You asked for Serverside validation for Greek characters and that is working on my test form with the code I have posted here.

If you want both Greek and English characters then you will need to change the regex to accept both.

Bob

GreyHead 04 Oct, 2012
Hi webbuilders,

Ah OK. That's the Client side validation - I've removed it now.

Bob
webbuilders 04 Oct, 2012
OK.

Now how can i add at the fields to be "Required" if at your example i press Submit at empty form then the form is sent empty.
GreyHead 04 Oct, 2012
Hi webbuilders,

Hmmm . . . that would be because I removed the Client side validation so that you could see the Serverside validation is working.

As I said before you probably need both. Client Side Validation helps the user complete the form correctly. Serverside Validation validates (and possibly cleans) the submitted data to make sure that you have valid and save data to work with.

Bob
webbuilders 06 Nov, 2012
hmm... OK

CAn you enable both server and client side validation and see if the form works properly ?
GreyHead 06 Nov, 2012
Hi webbuilders,

Please remind me next week when I'm back from my travels.

Bob
This topic is locked and no more replies can be posted.