Jump to content

form validation echoing divs.


takn25

Recommended Posts

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!

 

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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.

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.