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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:05:35+00:00 2026-06-04T10:05:35+00:00

I have the following form: <label>One</label> Product ID:<input type=text name=productid[] value=> Product Quantity: <input

  • 0

I have the following form:

<label>One</label> 
 Product ID:<input type="text" name="productid[]" value=""> 
 Product Quantity: <input type="text" name="quantity[]" value=""> <br>

<label>Two</label> 
 Product ID:<input type="text" name="productid[]" value=""> 
 Product Quantity: <input type="text" name="quantity[]" value=""> <br>

<label>Three</label> 
 Product ID:<input type="text" name="productid[]" value=""> 
 Product Quantity: <input type="text" name="quantity[]" value=""> <br>

 <!-- there may be more inputs like above (users can create new inputs 
    as many as they want) // I have a jquery function to create new rows-->


  <input type="submit" value="submit">

Now My question is how to validate the form using Codeigniter when I have input names like this- name="productid[]" instead of name="productid" in my form.

Usually I use to validate my form like this way but this time it won’t work for the form above.

How to validate it?

  • 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-04T10:05:36+00:00Added an answer on June 4, 2026 at 10:05 am

    You would use the literal field names, with brackets:

    $this->form_validation->set_rules('product_id[]', 'Product', 'required');
    $this->form_validation->set_rules('quantity[]', 'Quantity', 'required');
    

    This will run the validation on every field with that name. If you have to validate only a specific index, once again – use the literal field name (and specify the index in your HTML):

    // <input name="product_id[3]">
    $this->form_validation->set_rules('product_id[3]', 'Product', 'required');
    

    It’s all in the documentation for Codeigniter’s Form Validation class:

    Using Arrays as Field Names

    The Form Validation class supports the use of arrays as field
    names. Consider this example:

    <input type="text" name="options[]" value="" size="50"
    />

    If you do use an array as a field name, you must use the EXACT
    array name in the Helper Functions that
    require the field name, and as your Validation Rule field name.

    For example, to set a rule for the above field you would use:

    $this->form_validation->set_rules('options[]', 'Options',
    'required');

    Or, to show an error for the above field you would use:

    <?php echo form_error('options[]'); ?>

    Or to re-populate the field you would use:

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

    You can use multidimensional arrays as field names as well. For
    example:

    <input type="text" name="options[size]" value="" size="50"
    />

    Or even:

    <input type="text" name="sports[nba][basketball]" value=""
    size="50" />

    As with our first example, you must use the exact array name in the
    helper functions:

    <?php echo form_error('sports[nba][basketball]'); ?>

    If you are using checkboxes (or other fields) that have multiple
    options, don’t forget to leave an empty bracket after each option, so
    that all selections will be added to the POST array:

    <input type="checkbox" name="options[]" value="red" />
    <input type="checkbox" name="options[]" value="blue" />
    <input type="checkbox" name="options[]" value="green" />

    Or if you use a multidimensional array:

    <input type="checkbox" name="options[color][]" value="red"
    />
    <input type="checkbox" name="options[color][]"
    value="blue" />
    <input type="checkbox"
    name="options[color][]" value="green" />

    When you use a helper function you’ll include the bracket as
    well:

    <?php echo form_error('options[color][]'); ?>

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

Sidebar

Related Questions

I have following checkbox arrays in html form <label><input name=columns[] type=checkbox value=pname />Property Name</label>
I have the following piece of code: <form [attributes]> <input class=bound type=radio name=radioGroup value=1
I have HTML in the following form: <div id=filters> <ul> <li><label class=checkbox><input type=checkbox value=
I have the following code: <form class=form-inline id=myform0> <fieldset> <label class=radio><input type=radio name=optionsRadios id=optionHere2
I have the following form: echo $this->Form->input('Person.name'); echo $this->Form->input('Person.phone'); echo $this->Form->input('Person.email'); echo $this->Form->input('Message.0.plainmsg'); echo
I have a simple form right now: <form action='<? echo $PHP_SELF;?>' method='POST'> Username:<input type='text'
I have the following code: <ul id=litemsd> <li class=litemd> <input type=checkbox id=d1 name=d1 />
I have the following in jsp: <form action=/ucReady2/uploadservlet method=post enctype=multipart/form-data> <label for=filename_1>File: </label> <input
I have the following form <form name=myForm id=myForm method=post enctype=multipart/form-data action=script.php> and this jQuery
i have the following form item { fieldLabel:'Username' ,id:username ,name:'username' ,allowBlank:false ,plugins:[Ext.ux.plugins.RemoteValidator] ,rvOptions: {

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.