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 7307889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:28:59+00:00 2026-05-28T23:28:59+00:00

I have a form for user to input some feedbacks, and this form has

  • 0

I have a form for user to input some feedbacks, and this form has to be resided in a product detail page. I am required to print out some error validation on the detail page instead of having the form redirected to the feedback form page with the validation message.

The product detail page is located at ‘index.php/product/view/1’, while the feedback form is at ‘index.php/product/add_feedback’.

How can I print out the error form validation message so that it shows on the product detail page, instead of redirection to the add_feedback. Thank you.

My controller:

class Product extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->model('mproduct');
        $this->load->model('mfeedback');
    }

    public function index()
    {
        //get product details
        $data['content'] = $this->mproduct->get_details();
        $this->load->view('listing', $data);
    }

    public function add_feedback()
    {
        // feedback form

        $this->form_validation->set_rules('name', 'Name', 'required|xss_clean|max_length[200]');
        $this->form_validation->set_rules('feedback', 'Feedback', 'required|xss_clean|max_length[200]');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('feedback');
        }
        else
        {
            $pid = $this->input->post('pid');
            $name = $this->input->post('name');
            $feedback = $this->input->post('feedback');

            $this->MFeedback->add($pid, $name, $feedback);
            redirect('product/view/'.$pid);
        }
    }
}

Model:

class MFeedback extends CI_Model {
    function add_feedback($name, $pid, $feedback)
    {
        $data = array(
            'name' => $name,
            'feedback' => $feedback,
            'pid' => $pid,
        );
        $this->db->insert('feedback', $data);
    }
}

view – feedback.php

<h1>Add Feedback</h1>

<?php echo validation_errors(); ?>

<?php echo form_open('product/add_feedback'); ?>

<p>Name</p>
<input type="text" name="name" size="50" value="<?php echo set_value('name'); ?>" />

<p>Feedback</p>
<textarea type="text" name="feedback"><?php echo set_value('feedback'); ?></textarea>

<?php echo form_hidden('pid', $this->uri->segment(3, 0)); ?>

<div><input type="submit" value="Add Feedback" /></div>

</form>
  • 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-28T23:28:59+00:00Added an answer on May 28, 2026 at 11:28 pm

    Simple! Just add the validation to Product/index-method, like this:

    class Product extends CI_Controller {
    
        function __construct()
        {
            parent::__construct();
            $this->load->model('mproduct');
            $this->load->model('mfeedback');
        }
    
        public function index()
        {
            // feedback form validation
            $this->form_validation->set_rules('name', 'Name', 'required|xss_clean|max_length[200]');
            $this->form_validation->set_rules('feedback', 'Feedback', 'required|xss_clean|max_length[200]');
    
            if ($this->form_validation->run() == TRUE)
            {
                // the validation passed, lets use the form data!
                $pid = $this->input->post('pid');
                $name = $this->input->post('name');
                $feedback = $this->input->post('feedback');
    
                $this->MFeedback->add($pid, $name, $feedback);
                redirect('form/success'); // redirect to a page, where the user gets a "thanks" message - or redirect to the product page, and show a thanks there (but be sure to use redirect and nocht $this->load->view(..), because then the form data would be still in the header and a reload of the page would send another mail :)
            }
    
            // form did not pass the validation, lets get and show the product details
            $data['content'] = $this->mproduct->get_details();
            $this->load->view('listing', $data);
        }
    }
    

    And in the file feedback.php you’ll have to change the form target to something like this:

    <?php echo form_open('product/'.$this->uri->segment(3, 0)); ?>
    

    … or even better:

    <?php echo form_open('product/'.$content->id); ?>
    

    … depends on your product view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an order form where a user gives some input about a product
On a website if I have a form where the user can input some
So I have a form that accepts some input from a user that may
I have a form on a page where the user has inputs to edit
Let's say I have some form where user input some WCF/RIA Services URL and
I have a form in which user input some details and then click a
I have a form field that uses some Javascript to format user input 'price'
I have one form in JSP. I have some input fields in that page,
i have form that has multiple input text boxes, Which has got some text
I have a form with a number of text boxes for user input (this

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.