
Originally Posted by
kduv
Looks like it's this line:
PHP Code:
list($responseOK, $errors[$articleSurveyQuestionID]) = validateSurveyResponse($dbc, $articleSurveyQuestionID, $surveyResponse);
No matter what, you're setting a key in the $errors array. It doesn't matter if the value for that key is NULL, an empty string, or anything else. If there is a key, empty($errors) will return false.
So how do I redesign things to get what I want???
Normally - when I have hard-coded Forms - I would use something like this...
PHP Code:
// ************************
// Validate Form Data. *
// ************************
// Validate First Name. (Required)
$firstName = $trimmed['firstName'];
if (empty($firstName)){
// First Name does Not Exist.
$errors['firstName'] = 'Enter your First Name.';
}else{
// First Name Exists.
if (preg_match('#^[A-Z \'.-]{2,30}$#i', $firstName)){
// Valid First Name.
// Continue processing...
}else{
// Invalid First Name.
$errors['firstName'] = 'First Name must be 2-30 characters (A-Z \' . -)';
}
}//End of VALIDATE FIRST NAME
And then after my validation block, I would have...
PHP Code:
// ******************************
// Attempt to Change Details. *
// ******************************
if (empty($errors)){
// Valid Form Data.
}else{
// Invalid Form Data.
// Drop through to display Errors.
}//End of ATTEMPT TO CHANGE DETAILS
When I run my validateSurveyResponse() function, I need a way to keep track of which Question (i.e. $articleSurveyQuestionID) has a validation-error, and the actual Error-Message itself.
So - in greater detail - my Function has code like this...
PHP Code:
// OPEN-ENDED QUESTION.
case 'OPEN':
if (empty($surveyResponse)){
// Response does Not Exist.
return array(91, NULL);
}else{
// Response Exists.
$responseLength = strlen($surveyResponse);
if ($responseLength <= 10){
// Valid Response.
return array(92, NULL);
}else{
// Invalid Response.
$errors[$articleSurveyQuestionID] = "Response cannot exceed 1,024 characters. ($articleSurveyQuestionID)";
return array(93, $errors[$articleSurveyQuestionID]);
}
}
break;
(The 91, 92, and 93 where actually "TRUE", but I switched to numbers to track where my code was firing...)
Hope that makes sense?! 
Thanks,
Debbie
Bookmarks