lovephp Posted July 7, 2016 Share Posted July 7, 2016 ok this code below what i am trying to achieve is say a user fills up everything but forgot the jobtitle1 only then error message shows else if rest there is no value then data gets posted if($rjobtitle1 == '' || $rjobcompany1 != '' || $rjobcity1 != '' || $rjobfrom1 != '' || $rjobto1 != ''){ $error[] = 'Job title is required in <b>Experience</b> field 1.'; } but the error im facing now is even after i add data to jobtitle1 field i still get error message Quote Link to comment https://forums.phpfreaks.com/topic/301436-how-this-logic-work-form-handling/ Share on other sites More sharing options...
Jacques1 Posted July 7, 2016 Share Posted July 7, 2016 (edited) You should fix your other problems first. The logic you've described is rather confusing. Are you saying that if the job title is empty, all other fields must be empty as well? Right now, you're forcing the user to always fill out the job title but never fill out any of the other fields. Edited July 7, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/301436-how-this-logic-work-form-handling/#findComment-1534281 Share on other sites More sharing options...
lovephp Posted July 7, 2016 Author Share Posted July 7, 2016 no no i will try to explain again 1. field 2. field 3. field by default if user adds nothing in those 3 fields form should throw no error but if user filled 2. field 3. field and forgot 1. field only then error shows you forgot to enter title Quote Link to comment https://forums.phpfreaks.com/topic/301436-how-this-logic-work-form-handling/#findComment-1534282 Share on other sites More sharing options...
Jacques1 Posted July 7, 2016 Share Posted July 7, 2016 (edited) And if field 1 and field 2 are empty but field 3 is filled out? In other words, does it make sense to have, say, a job city but no other information? I expect not, which brings us back to my original interpretation. Edited July 7, 2016 by Jacques1 1 Quote Link to comment https://forums.phpfreaks.com/topic/301436-how-this-logic-work-form-handling/#findComment-1534283 Share on other sites More sharing options...
lovephp Posted July 7, 2016 Author Share Posted July 7, 2016 so what you suggest i just leave the field as it is without any validation? Quote Link to comment https://forums.phpfreaks.com/topic/301436-how-this-logic-work-form-handling/#findComment-1534284 Share on other sites More sharing options...
Solution Muddy_Funster Posted July 7, 2016 Solution Share Posted July 7, 2016 your if statement is too loose, all it's checking is: if jobtitle is empty, OR any other field has content then throw the error, you need to add some more complexity if($rjobtitle1 == '' &&( $rjobcompany1 != '' || $rjobcity1 != '' || $rjobfrom1 != '' || $rjobto1 != '')){ //this checks that if the jobtitle is empty AND anyother fields have any information in them then throw the error $error[] = "you need to add your job title to go with the company information"; } elseif($rjobtitle1 != '' && ($rjobcompany1 == '' || $rjobcity1 == '' || $rjobfrom1 == '' || $rjobto1 == '')){ //this checks that, if the jobtitle has content and none of the other fields have content then throw the error $error[] = "you have not told us some or all the info about the company that your job - {$rjobtitle1} - was with, please provide these details (all fields are required)"; } And so on. 1 Quote Link to comment https://forums.phpfreaks.com/topic/301436-how-this-logic-work-form-handling/#findComment-1534285 Share on other sites More sharing options...
lovephp Posted July 7, 2016 Author Share Posted July 7, 2016 your if statement is too loose, all it's checking is: if jobtitle is empty, OR any other field has content then throw the error, you need to add some more complexity if($rjobtitle1 == '' &&( $rjobcompany1 != '' || $rjobcity1 != '' || $rjobfrom1 != '' || $rjobto1 != '')){ //this checks that if the jobtitle is empty AND anyother fields have any information in them then throw the error $error[] = "you need to add your job title to go with the company information"; } elseif($rjobtitle1 != '' && ($rjobcompany1 == '' || $rjobcity1 == '' || $rjobfrom1 == '' || $rjobto1 == '')){ //this checks that, if the jobtitle has content and none of the other fields have content then throw the error $error[] = "you have not told us some or all the info about the company that your job - {$rjobtitle1} - was with, please provide these details (all fields are required)"; } And so on. thanks bro that did the job Quote Link to comment https://forums.phpfreaks.com/topic/301436-how-this-logic-work-form-handling/#findComment-1534286 Share on other sites More sharing options...
lovephp Posted July 7, 2016 Author Share Posted July 7, 2016 You should fix your other problems first. The logic you've described is rather confusing. Are you saying that if the job title is empty, all other fields must be empty as well? Right now, you're forcing the user to always fill out the job title but never fill out any of the other fields. bro that link u posted its already fixed no issues with it now Quote Link to comment https://forums.phpfreaks.com/topic/301436-how-this-logic-work-form-handling/#findComment-1534287 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.