myndcraft Posted October 7, 2008 Share Posted October 7, 2008 Logic and reasoning have left me for a warmer climate so I'm turning to forum members. I have two variables that have been set from a form lets call them $item1 and $item1_color What I am trying to do is append to an error string ($errmsg) if either variable has been set or is not empty AND the other variable has. So basically if a user selects an item, but not the color set the error. Or if they have set the color, but not selected an item set the error. Can someone help me with the best way to do this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/ Share on other sites More sharing options...
trq Posted October 7, 2008 Share Posted October 7, 2008 if ((isset($item1) && !isset($item1_color)) || (!isset($item1) && isset($item1_color))) { Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/#findComment-659471 Share on other sites More sharing options...
myndcraft Posted October 8, 2008 Author Share Posted October 8, 2008 Hi Thorpe, so I am encountering a problem here somewhere. So here is the code… echo $bumper_left . " " . $bumper_left_color; if ((isset($bumper_left) && !isset($bumper_left_color)) || (!isset($bumper_left) && isset($bumper_left_color))) { $errmsg .= "Mismatch error"; } echo $errmsg; If I set both values in the form I see them both in the initial echo. If I refresh the page and enter just one field I see only that field, but the errmsg echo never appears. Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/#findComment-659520 Share on other sites More sharing options...
myndcraft Posted October 8, 2008 Author Share Posted October 8, 2008 /bumping to the front page for the daytime crew Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/#findComment-659793 Share on other sites More sharing options...
waynew Posted October 8, 2008 Share Posted October 8, 2008 echo $bumper_left . " " . $bumper_left_color; if ((isset($bumper_left) && !isset($bumper_left_color)) || (!isset($bumper_left) && isset($bumper_left_color))) { $errmsg .= "Mismatch error"; echo $errmsg; } Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/#findComment-659841 Share on other sites More sharing options...
myndcraft Posted October 8, 2008 Author Share Posted October 8, 2008 Hi waynewex. Unfortunately the same thing happens. I see the contents of the fields displayed, but if leave one blank the error never appears. Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/#findComment-659851 Share on other sites More sharing options...
waynew Posted October 8, 2008 Share Posted October 8, 2008 Try] if( (isset($bumper_left) && isset($bumper_left_color)) && ($bumper_left == "" || $bumper_left_color == "")){ $errmsg .= "Mismatch error"; echo $errmsg; } Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/#findComment-659856 Share on other sites More sharing options...
myndcraft Posted October 8, 2008 Author Share Posted October 8, 2008 well we are almost there now! So it works in that if I enter text in both fields there is no error AND if I leave one field blank it errors as well which is correct. The problem is it also errors if I leave both fields blank which should be acceptable. Thanks btw for helping out thus far Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/#findComment-659860 Share on other sites More sharing options...
waynew Posted October 8, 2008 Share Posted October 8, 2008 if( (isset($bumper_left) && isset($bumper_left_color)) && ($bumper_left == "" || $bumper_left_color == "") && !($bumper_left == "" && $bumper_left_color == "")){ $errmsg .= "Mismatch error"; echo $errmsg; } Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/#findComment-659862 Share on other sites More sharing options...
myndcraft Posted October 8, 2008 Author Share Posted October 8, 2008 Well I thank you tremendously because it works, but could you walk thru what's happening there? I am trying to reason myself thru it and am getting hung up. Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/#findComment-659872 Share on other sites More sharing options...
waynew Posted October 8, 2008 Share Posted October 8, 2008 Well I thank you tremendously because it works, but could you walk thru what's happening there? I am trying to reason myself thru it and am getting hung up. Basically it is split up into three parts. All of which need to be proved true in order for the error message to be shown. IF 1: Both variables are set. AND 2: One is empty AND 3: Both are not empty Quote Link to comment https://forums.phpfreaks.com/topic/127468-validating-form-field/#findComment-660137 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.