Welcome Guest, Not a member yet? Register   Sign In
Problem with errors delimiters

Hello all!

I have a problem with setting delimiters via config file.
According to the documentation (http://www.codeigniter.com/user_guide/li....html#id23), I created form_validation.php at /application/config/ folder. Then I added there two lines:
PHP Code:
$config['error_prefix'] = "<div class=\"error\">";
$config['error_suffix'] = "</div>"
But there is no change in my site.
When I use
PHP Code:
$this->form_validation->set_error_delimiters("<div class=\"error\">""</div>"); 
everything is OK.

What's wrong am I doing?

Thank you in advance!

Did you try it with single quotes around the div tags? That's how it's described in the documentation:
$config['error_prefix'] = '<div class="error">';
$config['error_suffix'] = '</div>';

(This post was last modified: 04-29-2015, 11:08 AM by mwhitney. Edit Reason: removed stray URL code )

Single vs. double quotes should not make a difference. The documentation uses single quotes because it matches the Style Guide.

However, I'm not sure why loading them from the config file wouldn't work unless there was something wrong with the config file or the error delimiters were being set somewhere else, after the library is loaded.

Allow me a stupid question... did you add them inside the php tags?


@Wouter60, @Avenirer,
Of course I did.

Maybe is array $config redeclared somewhere?

I'm having the exact same problem
Anybody solved this.

CI Version 3.0.0

Apparently not. I have spent the last couple of hours on this and feel like I am getting stupider by the minute.

(This post was last modified: 10-16-2015, 01:23 AM by PaulD. Edit Reason: Added note about autoloading libraries )


I made a test file and it all seems to be working perfectly.

Controller: Test.php
defined('BASEPATH') OR exit('No direct script access allowed');

class Test extends CI_Controller {

    public function index()
        // validate form with values set in config file
        if ($this->form_validation->run())
            // valid form

View: test_view.php
        <!-- Testing validation errors -->
        <p><?php echo validation_errors(); ?></p>

        <!-- Test form - submit as blank to see if required error is picked up and formatting applied to error delimiters -->
        <?php echo form_open('test'); ?>
            <div class="form-group">
                <label for="email">Your Email Address</label>
                <input type="text" class="form-control" name="email" id="email" maxlength="100" value="<?php echo set_value('email', ''); ?>">
                <?php echo form_error('email'); ?>
            <input type="submit" class="btn btn-success" value="Login">

Config file: form_validation.php
$config = array(
       'test/index' => array(
                       'field' => 'email',
                       'label' => 'Email',
                       'rules' => 'required'

$config['error_prefix'] = '<div style="color: Purple;">';
$config['error_suffix'] = '</div>';

Both the automatic running of the form validation rules and the error delimiters are both working fine.

Try using these three files and see if it is working for you too.

I hope that helps,


Edit: Just to mention that I am autoloading the required libraries in my application config files for this example, such as url helper and form_validation.

Same issue here. Config doesn't work for me. It's autoloaded, but all error messages, for single message or for a whole form, isn't using prefix and suffix.

In your config array have you set them separately?

PHP Code:
$config = array(
'error_prefix' => '<span>',
'error_suffix' => '</span>',

I have not experienced any problems with using this at all.

Hope that helps,


Theme © iAndrew 2016 - Forum software by © MyBB