CodeIgniter: How can I display one validation error?

If I used this

<?= validation_errors(); ?>

result

Username field is required
Password field is required
<textbox for username>
<textbox for password>

what I really need is to display these errors in a line with their element

Example:

<textbox for username> Username field is required
<textbox for password> Password field is required
+5
source share
3 answers

To display the error individually, you must use the form_error ('username') function . And so that you get the value of the field being checked, use the set_value ('username') function .

For these two functions to work, you would have to set a rule for the "username" field in your controller. If you specify which validation rules apply to this field.

<?php echo form_error('username'); ?>
<input type="text" name="username" value="<?php echo set_value('username'); ?>">

Here is a simple tutorial on the Login form

+7

:

http://codeigniter.com/user_guide/libraries/form_validation.html#individualerrors

, , form_error().

, username, form_error('username').

. , . : <?php echo form_error('options[size]'); ?>

$this->form_validation->error(), , .

+4

, . , : " ?"

, . .

        $this->form_validation->set_rules('username', 'Username', 'callback_check_username');

        if ($this->form_validation->run() == TRUE){
            $this->form_validation->set_rules('password', 'Password', 'callback_check_password');
        } 
0
source

All Articles