views:

40

answers:

1

Hello,

I must warn you, this code will hurt your eyes, so please don't judge me, i'm trying to improve the way I handle errors

all my tests are like this :

if ($something < 27)
{
$error_IP= '<div class="error_message">something bad</div> ';
}else{
$erreur_IP='';
}

and here's the ugliest thing :

if( !isset($_POST) || ($erreur_captcha !='') || ($erreur_email !='') || ($erreur_hebergeurVide != '') || ($erreur_paysVide != '') || ($erreur_slotVide != '') || ($erreur_rconVide != '')  || ($erreur_tick != '') + a lot more :d ) 

What do you suggest to me to optimize my errors handling ?

Thank you

+4  A: 
$errors=array();
if ($something < 27) $errors[]= 'something bad';
if ($another > 333) $errors[]= 'even worse';

if (!$errors) {
  //writing
} else {
  foreach ($errors as $msg) {
    echo "<div class='error_message'>$msg</div>";
  }
}
Col. Shrapnel
Beautiful ;) thank you !
Tristan