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

  • Home
  • SEARCH
  • 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 7163261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:52:25+00:00 2026-05-28T13:52:25+00:00

I need to create a form with the same group of fields (data is

  • 0

I need to create a form with the same group of fields (data is from database)

For example:

Group 1: Description field, Amount field, Others fields
Group 2: Description field, Amount field, Others fields
Group 3: Description field, Amount field, Others fields

So in my view I loop the database values:

$i = 0;

foreach ($data_from_db as $data) {

  $description = array(
    'name'  => 'description[]',
    'id'    => 'description_field['.$i.']',
    'value' => set_value('description[]', $data->description)
  );

  echo form_label(lang('reward_description'), 'description_field['.$i.']');
  echo form_textarea($description);
  echo form_error('description[]');

  // more fields generated here in similar ways

  $i++
}

In my controller I have:

$this->form_validation->set_rules('description[]', 'lang:project_edit_description', 'required');

// more similar rules here

According to the Codeigniter documentation this is the correct way to do it, but its no working correctly.

Codeigniter is getting confused with the validation messages.

For example, if I leave intentionally one of the descriptions fields empty and submit the form, I get the validation error message in all the groups (I get “the Description field is required” also for group 1, 2 and 3)

  • 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-28T13:52:26+00:00Added an answer on May 28, 2026 at 1:52 pm

    Just set rules for each indexed field. Following snippets show a working example (Improve it as you require):


    Test controller:

    function index()
    {
        if ($_POST)
        {
            foreach ($_POST as $key => $value)
            {
                if ($key == 'description' && is_array($value))
                {
                    foreach ($value as $i => $vector)
                    {
                        // set rule for each index
                        $this->form_validation->set_rules('description[' . $i . ']', 'description ' . ($i + 1), 'trim|required');
                    }
                }
            }
    
            $this->form_validation->run();
        }
    
        $this->load->view('test');
    }
    

    Test view views/test.php:

    <?php
    
    echo form_open('');
    
    $data_from_db = $_POST ? $_POST['description'] : array('aaa', 'bbb', 'ccc');
    $i = 0;
    
    foreach ($data_from_db as $data)
    {
        $description = array(
            'name' => 'description[]',
            'value' => set_value('description[]', $data)
        );
    
        echo form_label('description ' . ($i + 1) . ':');
        echo form_textarea($description);
        echo '<br>';
        // set error for each index
        echo form_error('description[' . $i . ']');
    
        // more fields generated here in similar ways
    
        $i ++;
    }
    
    echo form_submit('mysubmit', 'Try it');
    echo form_close();
    ?>
    

    This code will show The description x field is required. only in the empty fields.

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

Sidebar

Related Questions

I need to create a form that has many of the same fields, that
I need to create a form with, half linear view (textboxes and dropdownlists in
I need to create a full-text search form for a database of emails /
I need to create two (or more) WPF windows from the same process. But
I need to create a form in the view (not in the edit )
I need to create a form for the field: id After entering the value
I have a View with a form which displays data from objects that are
When I go to my donors_controller#create from a form in my view, it will
Run out of ideas... I need to group all entries form database. There are
I need to create a Gold bar for my windows form similar to what

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.