Welcome Guest, Not a member yet? Register   Sign In
Form validation error delimiter
#1

(This post was last modified: 12-19-2016, 08:54 AM by mla.)

Hello

I read form validation documentation about error delimiter setup:


PHP Code:
$config['error_prefix'] = '<div class="error">';
$config['error_suffix'] = '</div>'

But if I use "in line" messages (Showing Errors Individually), for example on the right of each field of a form, the messages are (automatically?) formatted with <p>message</p>

Is it possible to suppress paragraph html tag?

Thanks
Reply
#2

(This post was last modified: 12-18-2016, 04:44 PM by PaulD. Edit Reason: clarification )

Yes, you can do it like this, just before you set your validation rules in your controller you can add this:

PHP Code:
$this->form_validation->set_error_delimiters(''''); 

(Those are empty single quotes by the way). Or you can add whatever you need on a case by case basis:

PHP Code:
$this->form_validation->set_error_delimiters('<span>''</span>'); 

This will overide the config settings. I normally have config set to something general like you have, then overide for different uses or layouts or stylings as needed per form with the above.

You can also set delimeters individually for each error message in the view if you need to mix and match them in one form.

PHP Code:
<?php echo form_error('field name''<div class="error">''</div>'); ?>

It is here in the docs:

https://www.codeigniter.com/user_guide/l...delimiters

Hope that helps,

Paul.
Reply
#3

The real question is that I create a form_validation.php file in my config directory.

It contains:


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

$config['error_prefix'] = '<div class="error">';
$config['error_suffix'] = '</div>'


But validation messages are created with <p> htlm tags... (default?)

It seems configuration file is not loaded...

If I set:


PHP Code:
$this->form_validation->set_error_delimiters('<div class="error">''</div>'); 


in my controller, it works correctly.
As you say.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB