jay7981 Posted November 15, 2012 Share Posted November 15, 2012 Hey guys, I need help with an if statement, if a user chooses Yes from a radio button (Change) I need the next text field (MemberID) validated if the answer is No I want the validation skipped here is the code that I have so far: if (empty($Change)) { $msg_error['Change'] = "Are you changing chapters?"; } if ($Change == 'Yes'){ if (empty($MemberID)) { $msg_error['MemberID'] = "What is your previous Member ID?"; }} else{ } if (empty($fname)) { $msg_error['fname'] = "Please enter your firstname"; } Quote Link to comment https://forums.phpfreaks.com/topic/270752-if-statement-for-form-validation-help-needed/ Share on other sites More sharing options...
RayTaylorII Posted November 15, 2012 Share Posted November 15, 2012 Hey guys, I need help with an if statement, if a user chooses Yes from a radio button (Change) I need the next text field (MemberID) validated if the answer is No I want the validation skipped here is the code that I have so far: if (empty($Change)) { $msg_error['Change'] = "Are you changing chapters?"; } if ($Change == 'Yes'){ if (empty($MemberID)) { $msg_error['MemberID'] = "What is your previous Member ID?"; }} else{ } if (empty($fname)) { $msg_error['fname'] = "Please enter your firstname"; } Try this: if (empty($Change)) { $msg_error['Change'] = "Are you changing chapters?"; } if ($Change == 'Yes' and (empty($MemberID))){ $msg_error['MemberID'] = "What is your previous Member ID?"; } if (empty($fname)) { $msg_error['fname'] = "Please enter your firstname"; } This assumes the only requirement is that memberid have some value... Quote Link to comment https://forums.phpfreaks.com/topic/270752-if-statement-for-form-validation-help-needed/#findComment-1392741 Share on other sites More sharing options...
jay7981 Posted November 15, 2012 Author Share Posted November 15, 2012 Thanks I knew there was an easier way Quote Link to comment https://forums.phpfreaks.com/topic/270752-if-statement-for-form-validation-help-needed/#findComment-1392765 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.