0

I m new to codeigniter developement. I created simple login form as follows:

In my login_view page

  <?php echo validation_errors(); ?>
  //my form html code comes here

In my controller page

$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');

if ($this->form_validation->run() == FALSE)
{
  $this->load->view('login_view',$data);
}
else
{
 //form validated do some work here
}

Now problem is that when I submit form with empty username and password field this shows me errors as

The Username field is required.
The Password field is required.

This is right but I want to show only single message as

Please enter username and password......

instead of two or N number of messages per field. I already tried form_error('fieldname') function but no use. How do I get above mentioned output.

Thanks in advance.

1 Answer 1

1

In the view you can use:

<?php if (form_error('username') || form_error('password')): ?>
  <div class="error">Please enter username and password......</div>
<?php endif; ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.