Active
Project:
Covert Fields
Version:
6.x-1.0-rc2
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 Mar 2010 at 08:28 UTC
Updated:
14 Jan 2011 at 20:22 UTC
Hi,
Ik hope someone can help help me. I found some php-code that I'd like to use for validating user input in a 'social insurance number field', but I don't now how to addapt the code for use with covert_fields.
The code:
/**
* Checks whether or not the sofinummer provided passes the test of 11.
* @version 2.0
* @param $sofinummer The sofinummer to be checked.
* @return boolean
* @author Ivo Peters
* @author Berry Langerak, al had Ivo hem als eerste goed :)
**/
function isSofinummer( $sofinummer ) {
$snummer = trim( $sofinummer );
// lijst met nummers die qua check kloppen, maar toch niet geldig zijn
$aInvalid = array( '111111110',
'999999990',
'000000000' );
if( strlen( $snummer ) != 9 || !ctype_digit( $snummer ) || in_array( $snummer, $aInvalid ) ) {
return false;
}
for( $i = 9, $som = -$snummer % 10; $i > 1; $i-- ) {
$som += $i * $snummer{( 9 - $i )};
}
return ( $som % 11 == 0 );
}
Thanks...
Comments
Comment #1
guypaddock commentedTry this in the "Code for Validation:
Comment #2
sportel commentedThanks GuyPaddock, this works! Except for the %entered_value in:
This only returns the string "%entered_value is not a valid social insurance number."
Thanks for your help. This also helps me a lot with making other validation rules.
Mike.
Comment #3
guypaddock commentedSorry, that should be:
Comment #4
sportel commented@ GuyPaddock,
Wow, maybe I'll learn to come up with these thing myself one day (I'm a php-noob). Thanks for your help.
I like Covert Fields more and more btw.
Mike.
edit:
It still doesn't work, but I'll try to figure it out.
Comment #5
john.karahalis commentedGreetings Mike,
Were you ever able to get the validation working? If not, we'd like to work with you to (finally :-)) resolve this issue.
Comment #7
john.karahalis commentedThank you for the interest, mmaaria.
I've changed the title back to "Social insurance number validation". Please be aware that the field "Issue title" is not a subject line, it is the name of this topic. (Don't worry, many people make this mistake.) Thanks!
As for the support request, we are still willing to help sportel resolve his original issue, but have not heard from him yet.
edit: It looks like mmaaria's comment was deleted, possibly due to spam.
Comment #9
john.karahalis commentedThanks tomleen. Will do.
ಠ_ಠ
edit: tomleen's comment (previously #8) has been removed due to spam.
Comment #10
sportel commentedHi Open Publishing,
Sorry for this very late reply. I have been busy with other things.
The validation works perfectly. The only thing not working is:
form_set_error($element_name_for_error, t('%entered_value is not a valid social insurance number.', array('%entered_value' => $entered_value));This only returns: "'%entered_value is not a valid social insurance number."
I have solved this for now by using "This is not a valid blablabla..." as an error message.
Mike.
Comment #11
john.karahalis commentedHello again, sportel.
I noticed two problems with your code snipped:
Try correcting these two issues. If that does not fix the problem, make sure your code does not contain any typos. The following worked correctly for me, replacing %entered_value with the text I entered into the Covert Field:
Comment #12
sportel commentedHi john.karahalis,
Yes, it was the parenthesis that was missing. I should have seen that.
I used the php delimeters btw for syntaxhighlighting here in the post.
Covert Fields did detect the syntax error, so my comment in #10 wasn't correct (it seems i didn't remembered the problem correctly when i wrote it).
Thanks for your help and your patience. And again: Great module!!!
Mike.