Hey guys, Just wondering if there is a simple method in PHP which can allow for form protection so that all fields have to be completed before the form is submitted?
Thanks.
Well, other than looping through $_POST and making sure there are no empty values, no, there's no "simple way." Even if you did that, there's no guarentee that all of the elements you expect were even POSTed in the first place.
There isn't any way (simple or not) of preventing form from sending on any condition using PHP only. The reason is that PHP is working server-side. Form is submitted on client's computer where PHP isn't running. $_POST can be checked after the form is submitted. You would then display form again if you don't have all necessary data. JavaScript is probably what you're looking for if you want to check form data before submission as it runs client-side. But then - it can be switched off by user so you can't depend on it either 🙂 . Aparently you have to have both of them: client-side and server side form data validation - just to make sure.
Thanks for all the advice I will look into javascript. 🙂