marvinds Posted February 17, 2014 Share Posted February 17, 2014 I have an index.html page that has a form. I am doing the validation with Javascript, however I would also like to validate with PHP if the user has JS disabled. The problem I am having is reloading the index.html page if the user didn't fill out the required fields. I am using--header('Location: index.html')-- to redirect the user back to the html form. For some reason I can't figure out how to get the error messages to display letting the user know what fields need to be completed, and it just displays an empty form. Any suggestions would be much appreciated. Thanks Link to comment Share on other sites More sharing options...
HartleySan Posted February 17, 2014 Share Posted February 17, 2014 Change index.html to index.php. After that, do the validation in PHP before displaying the form, and then based on any errors, display the form accordingly. Link to comment Share on other sites More sharing options...
marvinds Posted February 17, 2014 Author Share Posted February 17, 2014 Unfortunately that is not an option. It is an assignment for a class that I am taking, and it specifically says to create an index.html file that displays a form, and have it submit the form to calc.php. Link to comment Share on other sites More sharing options...
Larry Posted February 18, 2014 Share Posted February 18, 2014 If it's a .html page, you can't use PHP to tell it to display errors (unless you configure your web server to run .html files through PHP, which would be highly unusual). Link to comment Share on other sites More sharing options...
HartleySan Posted February 18, 2014 Share Posted February 18, 2014 If that's the assignment, then you can't validate and submit back to the same form unless you put the same form in the calc.php script, which would be pointless when you can just submit to the same page to begin with. Like Larry said though, you need a PHP file, not an HTML file, to do PHP validation. Link to comment Share on other sites More sharing options...
Recommended Posts