Hi People,
I have a problem with the API to make a simple username validation. Here is the code:
<?php
$error= array();
$errorTxt= array();
$errorMessage='';
if(strlen($_POST['username'])<6) {
$error[] = "username";
$errorTxt[] = "El nombre de usuario debe tener más de 5 caracteres";
}
if(!preg_match("/[^a-zA-Z0-9]+$/s",$_POST['username'] )) {
$error[] = "username";
$errorTxt[] = "El nombre de usuario debe contener sólo números y letras";
}
if (count($error)>0) {
for ($i=0;$i<count($errorTxt);$i++) {
$errorMessage .=$errorTxt[$i];
if ($i<count($errorTxt)-1) {
$errorMessage.='.<br/> ';
}
}
echo $errorMessage;
return false;
}
?>
What I want to do is, if an error is detected ( short username o invalid username ) to stop executing the snippet, dont save the user ( onBeforeSaveUser event ) and display the error message.
The way I’ve done it, I show the message, but the snippet continue being executed and the user is registered. The example I used to do my implementation (
http://modxcms.com/forums/index.php?topic=34924.0 ) used $wlpe->FormatMessage($errorMessage); instead my "echo" and "return false;"; but to use it I have to do an small hack I don’t want to do. Is there another way?
Thanks in advance