Page 2 of 2

Posted: Wed Mar 21, 2007 6:22 am
by dude81

Code: Select all

$errors = array(); 
$strErrorMessage = ""; 
if(empty($domaincompany)) { $errors['domaincompany'] = "Domain Company"; } 
if(empty($domainexp)) { $errors['domainexp'] = "Domain Expiry Date"; } 
if(empty($domainuser)) { $errors['domainuser'] = "Domain User"; } 
if(empty($domainpass)) { $errors['domainpass'] = "Domain Password"; } 
if(empty($domainregkey)) { $errors['domainregkey'] = "Domain Reg Key"; } 
if (count($errors)>0) { 
    $strErrorMessage = "You must complete the following fields: <br>".implode("<br>",$errors)."<br>"; 
} 
if (!checkValidDate($domainexp)) { $strErrorMessage .= "Domain Expiry Date is not a valid date.<br>"; } 
if (!checkValidUser($domainuser)) { $strErrorMessage .= "Domain User is not valid.<br>"; } 
if (!checkValidRegKey($domainregkey)) { $strErrorMessage .= "Domain Reg Key is not valid.<br>"; } 

if (empty($strErrorMessage)) { 
    $allgood = $allgood + 1; 
} else { 
    $save_result = $strErrorMessage; 
}

Your code looks more readable, I think this will show where the error happened soon. More user friendly code

Posted: Wed Mar 21, 2007 10:37 am
by RobertGonzalez
dhrosti wrote:Does php not treat empty variables as false? if it does you can strip out all the "!empty()"s
No, it treats them as empty.