Moved validation code to php