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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:51:42+00:00 2026-06-17T17:51:42+00:00

I have a form that has its fields dynamically added as such: function addFieldRow()

  • 0

I have a form that has its fields dynamically added as such:

function addFieldRow() {
  $('.form-container').append('
    <div><input type="text" name="name[1]"></div>
    <div>
      <select name="choice[1]">
        <option value="red">red</option>
        // . . .
      </select>
    </div>
     // . . .
  ');
}

I then pass these to its respective CodeIgniter controller with the declared array form_validation rules:

$this->form_validation->set_rules('name[]', 'text field', 'required');
// . . . other fields' rules

The problem is that if any of the dynamically added forms have an error, these are gone during the view loading.
I want to know if how can I preserve the dynamically added form fields after the validation run with errors:

if ($this->form_validation->run() == FALSE) {
  // do stuff to preserve the dynamically created fields to show their errors
  $this->load->view('user_addresses_view');
}

Better solution

I have found the solution to preserve these dynamically added elements by using ajax to connect to the form’s respective controller in the CodeIgniter framework. This method can:

  1. Do client-side and server-side validation without refreshing the page
  2. Since the page does not refresh, all these dynamically added form elements will not disappear!

Solution by james246

  • 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-06-17T17:51:44+00:00Added an answer on June 17, 2026 at 5:51 pm

    you can’t do it because page is actually refreshing and row is added client side so when validation done then you will redirected to same page with validation errors you will not see dynamically added dom because as i said it was happend client side not in your code…so all you can do is use session and then at load time manually validate and add them to page.

    Using SESSION might not be good idea because for that you will have to code more complex helpers and validation methods and etc…

    Other possible solution

    1. use jQuery.validate plugin that allow us to validate dynamically added rows ( fields , dom ).

    2. take benefit of mysql and add those field into database with possible error stored in db and send it to view file.

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

Sidebar

Related Questions

I have a rails form that has a datetime input. I'd like to make
I have a form that has a bunch of CCK fields, one of which
Using CakePHP 1.3 , I have a (working) form that has dynamically created form
I have a simple PHP script with a form that has two select fields,
I have a form that has label values that I would like to pass
I have a form that has a group of 3 text_fields. I need two
I have a form that has many long-methods. My quest is: What is the
I have a form that has 8 columns and a variable number of rows
I have a form that has a series of check boxes and some line
i have a form that has a multiple select drop down. a user can

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.