function validateEditActions(&$validation, $params) { $http = eZHTTPTool::instance(); $prefix = eZSurveyType::PREFIX_ATTRIBUTE; $attributeID = $params['contentobjectattribute_id']; eZSurveyQuestion::validateEditActions($validation, $params); $optionValues = array(); $optionCount = 0; foreach (array_keys($this->Options) as $key) { $option =& $this->Options[$key]; $optionID = $option['id']; $postValue = $prefix . '_ezsurvey_receiver_' . $this->ID . '_' . $optionID . '_value_' . $attributeID; if (!$http->hasPostVariable($postValue) or $http->hasPostVariable($postValue) and !eZMail::validate($http->postVariable($postValue))) { $validation['error'] = true; $validation['errors'][$this->ID] = array('message' => ezpI18n::tr('survey', "Entered text '%text' in the question with id %number is not an email address!", null, array('%number' => $this->ID, '%text' => $http->postVariable($postValue))), 'question_id' => $this->ID, 'code' => 'receiver_email_not_valid', 'question' => $this); break; } if (!$http->hasPostVariable($postValue) or $http->hasPostVariable($postValue) and in_array($http->postVariable($postValue), $optionValues)) { $validation['error'] = true; $validation['errors'][$this->ID] = array('message' => ezpI18n::tr('survey', 'Email addresses in the question with id %number must have unique values!', null, array('%number' => $this->ID)), 'question_id' => $this->ID, 'code' => 'receiver_email_not_unique', 'question' => $this); break; } $optionValues[] = $option['value']; } }
function validateEditActions(&$validation, $params) { $http = eZHTTPTool::instance(); $prefix = eZSurveyType::PREFIX_ATTRIBUTE; $attributeID = $params['contentobjectattribute_id']; eZSurveyQuestion::validateEditActions($validation, $params); foreach (array_keys($this->Options) as $key) { $option =& $this->Options[$key]; $optionID = $option['id']; if ($http->hasPostVariable('SurveyMC_' . $this->ID . '_' . $optionID . '_Value')) { $option['value'] = trim($http->postVariable('SurveyMC_' . $this->ID . '_' . $optionID . '_Value')); if (strlen($option['value']) == 0) { $validation['error'] = true; $validation['errors'][] = array('message' => ezpI18n::tr('survey', 'You must enter the value for an option in the question with id %question!', null, array('%question' => $this->ID)), 'question_id' => $this->ID, 'code' => 'mc_value_for_option', 'question' => $this); } } } // Need to check the POST varilables. $optionValues = array(); $optionCount = 0; $checkedCount = 0; // Check the extra option value to be not empty $postMCExtraValue = $prefix . '_ezsurvey_mc_' . $this->ID . '_extra_value_' . $attributeID; if ($http->hasVariable($postMCExtraValue)) { $optionValue = $http->postVariable($postMCExtraValue); if (strlen($optionValue) === 0) { $validation['error'] = true; $validation['errors'][] = array('message' => ezpI18n::tr('survey', 'Options in the question with id %question must have unique values!', null, array('%question' => $this->ID)), 'question_id' => $this->ID, 'code' => 'mc_option_unique_value', 'question' => $this); } } foreach (array_keys($this->Options) as $key) { $option =& $this->Options[$key]; $optionID = $option['id']; $postMCValue = $prefix . '_ezsurvey_mc_' . $this->ID . '_' . $optionID . '_value_' . $attributeID; if ($http->hasVariable($postMCValue)) { $optionValue = $http->postVariable($postMCValue); $optionCount++; if (in_array($optionValue, $optionValues) or strlen($optionValue) === 0) { $validation['error'] = true; $validation['errors'][] = array('message' => ezpI18n::tr('survey', 'Options in the question with id %question must have unique values!', null, array('%question' => $this->ID)), 'question_id' => $this->ID, 'code' => 'mc_option_unique_value', 'question' => $this); break; } $optionValues[] = $optionValue; } $postMCChecked = $prefix . '_ezsurvey_mc_' . $this->ID . '_' . $optionID . '_checked_' . $attributeID; $checkedCount += $http->hasPostVariable($postMCChecked) ? 1 : 0; } $postExtraMCChecked = $prefix . '_ezsurvey_mc_' . $this->ID . '_extra_value_checked_' . $attributeID; $checkedCount += $http->hasPostVariable($postExtraMCChecked) ? 1 : 0; }