Here is the solution that i suggest:
After submiting the form ,in action.php you will check if username is empty,if it's empty , you will redirect to index.php page with a variable in the url that indicates if field is empty or not(you can also use sessions).
index.php page :
<?php
if (isset($_GET['empty'] )){$empty="class='empty'";}
else {
$empty="";
}
?>
<form method="post" action="action.php">
<input name="username" <?php echo $empty; ?> />
<input type="submit" name="submit" value="save" />
</form>
Your action.php page:
<?php
$username = $_POST['username'];
if(empty($username)) {
header('location:index.php?empty=1');
}
?>