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

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!
Reply
#2

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

(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.
Reply
#4

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

<?php
$config...
...
?>
Reply
#5

@Wouter60, @Avenirer,
Of course I did.

Maybe is array $config redeclared somewhere?
Reply
#6

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

CI Version 3.0.0
Reply
#7

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

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

Hi,

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

Controller: Test.php
Code:
<?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
        }
        
        $this->load->view('test_view');
    }
}

View: test_view.php
Code:
<html>
    <head>
        <title>Testing</title>
    </head>
    <body>
        <!-- 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'); ?>
            </div>
            <input type="submit" class="btn btn-success" value="Login">
        </form>    
    </body>
</html>

Config file: form_validation.php
Code:
<?php
$config = array(
       'test/index' => array(
               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,

Paul.

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.
Reply
#9

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.
Reply
#10

In your config array have you set them separately?

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

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

Hope that helps,

Paul.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB