takn25 Posted April 24, 2011 Share Posted April 24, 2011 Hi, I used to do form validations in a totally different manner before this that aside. I would like to know how can I do something like this. What happens here is if none of the conditions are met I echo a div containing the error and so on. The problem I am facing is If the first condition is not met it goes to the second condition and at the end there are two error divs at the same time. I want to perform something like, if first condition is not met script stops, echos only the div where the condition is not met and the script does not carry on. If i use the die or exit functions it dies and html dies with it any solutions or another way? if (strlen($title)<=19) { echo "<div id='error'><div id='error_img'><img src='images/warning.gif' width='16' height='16' title='error' /></div> must of be atleast 20 characters. </div>";; } if ($on=="-1") { echo "<div id='error'><div id='error_img'><img src='images/warning.gif' width='16' height='16' title='error' /></div> Please select. </div>"; } any help is appreciated thanks! Quote Link to comment https://forums.phpfreaks.com/topic/234562-form-validation-echoing-divs/ Share on other sites More sharing options...
Drummin Posted April 24, 2011 Share Posted April 24, 2011 Maybe something like this? IF (strlen($title)<=19){ $titleck="bad"; echo "<div class='error'><div class='error_img'><img src='images/warning.gif' width='16' height='16' title='error' /></div> must of be atleast 20 characters. </div>"; } ELSE{ $titleck="good"; } IF ($titleck=="good"){ IF ($on=="-1"){ $selck="bad"; echo "<div class='error'><div class='error_img'><img src='images/warning.gif' width='16' height='16' title='error' /></div> Please select. </div>"; } ELSE{ $selck="good"; } } IF ($selck=="good"){ IF ($another=="badcondition"){ $anotherck="bad"; echo "<div class='error'><div class='error_img'><img src='images/warning.gif' width='16' height='16' title='error' /></div> Please change. </div>"; } ELSE{ $anotherck="good"; } } //add more Quote Link to comment https://forums.phpfreaks.com/topic/234562-form-validation-echoing-divs/#findComment-1205459 Share on other sites More sharing options...
PaulRyan Posted April 24, 2011 Share Posted April 24, 2011 Use simple if/else <?PHP if (strlen($title)<=19) { echo "<div id='error'><div id='error_img'><img src='images/warning.gif' width='16' height='16' title='error' /></div> must of be atleast 20 characters. </div>"; } else if ($on=="-1") { echo "<div id='error'><div id='error_img'><img src='images/warning.gif' width='16' height='16' title='error' /></div> Please select. </div>"; } ?> Tell me how it goes. Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/234562-form-validation-echoing-divs/#findComment-1205526 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.