To do it in PHP, you should echo PHP variables rite on input feilds. While the form is not submited, they are null.
once the form is submited, if there is one which is not valid, set it to empty or null. Then the output would still be empty. Now you can output the error ms to your users.