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
https://forums.phpfreaks.com/topic/234562-form-validation-echoing-divs/
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 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.