IsSurveyNameAvailable($surveyName))
{
$errors['surveyNameError'] = 'This survey name is not available.';
$hasError = true;
}
//determine if survey is checked to be active immediately
if(!array_key_exists('isActive', $_REQUEST))
{
$isActive = '';
}
//get all values of question and corresponding co-ordinates
for($i = 1; $i<$questionsPerPage +1; $i++)
{
$quesId = 'q'.$i;
$question = array(
'text' => trim($_REQUEST[$quesId]),
'x' => trim($_REQUEST[$quesId.'x']),
'y' => trim($_REQUEST[$quesId.'y']),
'z' => trim($_REQUEST[$quesId.'z'])
);
$questions[$i] = $question;
//if either of the fields is full, check that all fields are full
//and x,y and z only have numbers in it.
if(strlen($question['text']) > 0 || strlen($question['x']) > 0
|| strlen($question['y']) > 0 || strlen($question['z']) > 0)
{
if(strlen($question['text']) == 0)
{
$errors[$quesId.'Error'] = 'Please enter some text for the question.';
$hasError = true;
}
//check for x values
if(strlen($question['x']) == 0)
{
$errors[$quesId.'xError'] = '\'x\' cannot
be empty';
$hasError = true;
}
else if(strlen($question['x']) > 17)
{
$errors[$quesId.'xError'] = 'Please enter
less than
17 characters.';
$hasError = true;
}
else if(StringToFloat($question['x']) === 'NaN')
{
$errors[$quesId.'xError'] = 'Invalid decimal
number.';
$hasError = true;
}
//check for y values
if(strlen($question['y']) == 0)
{
$errors[$quesId.'yError'] = '\'y\' cannot
be empty';
$hasError = true;
}
else if(strlen($question['y']) > 17)
{
$errors[$quesId.'yError'] = 'Please enter
less than
17 characters.';
$hasError = true;
}
else if(StringToFloat($question['y']) === 'NaN')
{
$errors[$quesId.'yError'] = 'Invalid decimal
number.';
$hasError = true;
}
//check for z values
if(strlen($question['z']) == 0)
{
$errors[$quesId.'zError'] = '\'z\' cannot
be empty';
$hasError = true;
}
else if(strlen($question['z']) > 17)
{
$errors[$quesId.'zError'] = 'Please enter
less than
17 characters.';
$hasError = true;
}
else if(StringToFloat($question['z']) === 'NaN')
{
$errors[$quesId.'zError'] = 'Invalid decimal
number.';
$hasError = true;
}
$numberOfQuestions++;
}
}
if(!$hasError && $numberOfQuestions > 0)
{
//if there are no errors, then try putting data in to database.
$isSuccessfulInsert = $biz->AddNewSurvey($surveyName, $isActive == 'checked', $questions);
if($isSuccessfulInsert)
{
$questions = array();
$errors = array();
$surveyName = '';
$saveMessage = 'Survey was successfully saved to the database.';
}
else
{
$saveMessage = 'There was an error saving the survey to the database.'.$isSuccessfulInsert->errorDescription.'';
}
}
else
{
$saveMessage = 'Kindly resolve the shown errors before saving the survey.';
if($numberOfQuestions === 0)
{
$saveMessage = 'Please enter at least one question to the survey.';
}
}
}
$biz->CloseDatabaseConnection();
?>
A few things to keep in mind
- Owing to the nature of the experience,
- please consider adding as less questions as possible.
- watch out for questions that may feel redundant to the end user.
- please remember that 'How do you feel about...' appears before every question in the application.
- You need not fill all questions. Fill the ones you want and hit Save.