Because you're already using Java Script, using a polyfill isn't an added burden to your website or web application's design or implementation.
Here is the PHP script that checks the name for empty input and throws an error if the input is empty.
When we display the form back again, it should not loose the form data the user already had filled-in.
If the argument is the empty string, the custom error is cleared.
For legacy browsers, it's possible to use a polyfill such as Hyperform to compensate for the lack of support for the constraint validation API.