0

This is the URL of form.

http://localhost/cig/index.php/Resetpassword?temporarycode=CLK6xW7j0I1psnk243wF&[email protected]

And this is how i validate it.but the problem is that i am unable to show the validation errors on the page

$this->form_validation->set_rules('password', 'Password', 'required');
            $this->form_validation->set_rules('confirmpassword', 'Password Confirmation', 'required|matches[password]');

            if ($this->form_validation->run() == FALSE) {

              redirect($_SERVER['HTTP_REFERER']);
          }
1
  • please also post the view code. Commented Jun 1, 2016 at 7:41

2 Answers 2

1

ok i have ran into a couple things that could be improved.


for starters why do you redirect the user somewhere when the fields are invalid? why not use:

$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confirmpassword', 'Password Confirmation', 'required|matches[password]');
if ($this->form_validation->run()) {
    redirect(base_url('emailSend'); // or wherever you want the visitor to be send to
} 
$this->load->view('register'); // or however your view file is called

This way you have no problems with showing errors if you have the rule <?= validation_errors() ?> in your view file, the <?= ?> is short php code for <?php echo ?> and the validation_erros() should contain the validation errors if there are any.

Sign up to request clarification or add additional context in comments.

2 Comments

oh! actually I didn't tried it thinking that it will not cause a problem and not work. But it worked.Thanks
np glad to help you
0

You can try CI flash data,

$this->session->set_flashdata('errors', validation_errors());

redirect($_SERVER['HTTP_REFERER']);

It keeps the data for next server request.

2 Comments

thanks for this idea. but can you show how to get this in view and show it.
In view, use $this->session->flashdata('errors'); to show the message

Your Answer

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