redarrow Posted March 24, 2009 Share Posted March 24, 2009 advance thank you. if i got a huge form and i want to make a condition using $_POST and only let it update the database if there no $warning. is it ok using it this way or not. <?php foreach($_POST as $key=>$val){ if(empty($val)){ echo"<div style='font-size: 36; color: #FF0000; text-align: center;'> PLEASE USE ALL THE FORM!</div>"; $warning="stop"; break; } } if(!$warning){ //do somethink } ?> Quote Link to comment https://forums.phpfreaks.com/topic/150874-solved-post-and-valadation/ Share on other sites More sharing options...
Daniel0 Posted March 24, 2009 Share Posted March 24, 2009 Something like this would probably be better: $requiredFields = array('field1', 'field2', 'field3' /* etc. */); $missingFields = array(); foreach ($requiredFields as $field) { if (!isset($_POST[$field]) || empty($_POST[$field])) { $missingFields[] = $field; } } if (count($missingFields)) { echo 'Please fill out the remaining fields: ' . join($missingFields, ', '); // show form } else { // process form } That'll be more user friendly seeing as you give feedback about which fields they are missing. This will be especially helpful considering that the form is "huge". It would also allow you to have optional fields should you decide that at a later point. Quote Link to comment https://forums.phpfreaks.com/topic/150874-solved-post-and-valadation/#findComment-792588 Share on other sites More sharing options...
redarrow Posted March 24, 2009 Author Share Posted March 24, 2009 Thank you mate! Quote Link to comment https://forums.phpfreaks.com/topic/150874-solved-post-and-valadation/#findComment-792591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.