Jump to content

how this logic work? form handling


lovephp
Go to solution Solved by Muddy_Funster,

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Jacques1
  • Like 1
Link to comment
Share on other sites

  • Solution

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.

  • Like 1
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.