I'm trying to display the validation errors thrown by the Codeigniter validator function. Codeigniter validator function sends <p></p> with each and every error as default.
The JSON output back to the page displays this HTML as it is, instead of displaying it in HTML paragraph one below another.
The PHP Codeigniter code is as follows (here ouptut is an array containing formvalidation errors)
//Send output back to NG
$output['error'] = validation_errors();
$json = json_encode($output, JSON_HEX_QUOT | JSON_HEX_TAG);
echo $json;
The AngularJS code is as follows
var request = $http({
method: "post",
url: "/user/processregister",
data: $scope.regdata,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
request.then(
function (data) {
if(data.data.state == 1) {
$scope.alertMessage = "Registration Successful. Please wait while you are being redirected.";
$window.location.href = '/member';
} else {
$scope.alertMessage = data.data.error;
}
},
function(data) {
// Handle error here
$scope.alertMessage = 'Error in form submission. Please contact support.';
}
);
