SwiftD
SwiftD

Reputation: 6069

Codeigniter $this->lang->line(errors) without paragraph tags for tank auth error messages

I'm wondering if someone can help me with this. I am currently trying to integrate tank auth into my codeigniter site. I am slowly getting there but have run into a minor stumbling block in that when I have moved the error messages from being displayed as part of an html view to a javascript alert they are still printing out the paragraph tags around the error message.

The error messages which are passed to my login form as an array/ or multidimensional array I think are produced in the controller by the following lines of code:

$data['errors'] = array();
foreach ($errors as $k => $v)   $data['errors'][$k] = $this->lang->line($v);

Here is my code for displaying the error messages:

if ((isset($errors[$login['name']]))||(isset($errors[$password['name']]))||(form_error($login['name']))||(form_error($password['name']))){
        echo'<script type="text/javascript">alert("';
}
echo form_error($login['name']);
echo isset($errors[$login['name']])?$errors[$login['name']]:'';
echo form_error($password['name']); 
echo isset($errors[$password['name']])?$errors[$password['name']]:'';
if ((isset($errors[$login['name']]))||(isset($errors[$password['name']]))||(form_error($login['name']))||(form_error($password['name']))){
        echo'")</script>';
}

Now my primary question here is how to remove the paragreaph tags ande I have found a clue here in the codeigniter documentation: http://codeigniter.com/user_guide/libraries/file_uploading.html They key part here is that It says you can set the delimeters for the errors on the upload script by doing this:

$this->upload->display_errors('<p>', '</p>');

But I have no idea how and where to apply this to tank auth.

I also have a second question which I would be grateful to anyone who can answer, I am slightly confused by the code for displaying the error messages. For example:

echo form_error($password['name'])

can someone explain this to me, it has no $ at the beginning so is not a variable so whats it all about, and the thing I am really trying to get to is how to simplify my logic in checking for the error messages, since it is incredibly long winded at the moment and there are a lot of error messages to handle.

I appreciate there is a lot to deal with here but any help/explainations will be gratefully recieved.

Upvotes: 3

Views: 6644

Answers (1)

Fad
Fad

Reputation: 9858

To remove the tags wrapping the error message, you'll have to call the set_error_delimiters() method of the Form Validation object with 2 empty strings as the parameters.

$this->form_validation->set_error_delimiters('', '');

More on this: https://codeigniter.com/user_guide/libraries/form_validation.html#changing-the-error-delimiters

As for your second question, I'm not sure what you're asking actually. It's only a function call where the returned value of the call will be outputted to the user.

Upvotes: 20

Related Questions