Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:31:58+00:00 2026-05-26T15:31:58+00:00

I am using Codeigniter’s validation class to validate my form. Could you please tell

  • 0

I am using Codeigniter’s validation class to validate my form. Could you please tell me how to redirect to the previous page from controller if found any validation error?

In my controller:

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

  //**** Here is where I need to redirect  

} else  {
     // code to send data to model...           

  }                             
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:31:58+00:00Added an answer on May 26, 2026 at 3:31 pm

    UPDATE

    You want to post a form, validate it, then show the form again with the validation errors if validation fails, or show something entirely different if validation passes.

    The best way to do this is to post a form back to itself. So the action of your form would be action="". This way, in your method, you can check to see if the form was submitted, and determine what to do there:

    // in my form method
    if ($this->input->post('submit')) // make sure your submit button has a value of submit
    {
         // the form was submitted, so validate it
         if ($this->form_validation->run() == FALSE)
         {
             $this->load->view('myform');
     }
     else
     {
             $this->load->view('formsuccess');
     }
    }
    else
    {
        // the form wasn't submitted, so we need to see the form
        $this->load->view('myform');
    }
    

    OLD ANSWER

    You can always pass the current URI in a hidden field in the form:

    <input name="redirect" type="hidden" value="<?= $this->uri->uri_string() ?>" />
    

    And then redirect if the validation fails:

    redirect($this->input->post('redirect'));
    

    Or you can set the redirect url in a flashdata session variable:

    // in the method that displays the form
    $this->session->set_flashdata('redirect', $this->uri->uri_string());
    

    And then redirect if the validation fails:

    redirect($this->session->flashdata('redirect'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using CodeIgniter to pass some parameters to my PHP page through $_POST
I am using Codeigniter framework and I have a form with input fields. When
I am using codeigniter and its pagination class. It works perfectly and it looks
I am using codeigniter. My products page shows all the products we have and
Using CodeIgniter, I am trying to place several images onto my view page as
I am using CodeIgniter for PHP. Can anybody tell me why is this code
I'm using CodeIgniter (v1.7.2) and I've created a custom controller that incorporates authentication called
I am using codeigniter php framework. I am suffering from the problem that all
Using CodeIgniter's Active Record class and MySQL, I have a table of posts with
I am using codeigniter's session class to handle my PHP sessions. One of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.