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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:52:51+00:00 2026-05-22T22:52:51+00:00

This is my first question, i would be very pleased if you can help

  • 0

This is my first question, i would be very pleased if you can help me.

I have to catch the values of a set of dynamic inputs, i am generating the inputs with jQuery. I dont know if it’s a good solution to use the same name for all with brackets at the end like this:

<!-- first set of entries -->
<input type="text" name="nombre_contacto[]">
<input type="text" name="mail_contacto[]">

<!-- second set of entries -->
<input type="text" name="nombre_contacto[]">
<input type="text" name="mail_contacto[]">

<!-- etc... -->  

Or just use a counter at the end of the name, like this:

<!-- first set of entries -->
<input type="text" name="nombre_contacto1">
<input type="text" name="mail_contacto1">

<!-- second set of entries -->
<input type="text" name="nombre_contacto2">
<input type="text" name="mail_contacto2">

<!-- etc... -->  

How i can catch every single item at my controller? it’s this possible?

Thanks!

  • 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-22T22:52:52+00:00Added an answer on May 22, 2026 at 10:52 pm

    Your best bet is definitely to use an array, as you are doing in your first example.

    To get all the results, something like this will work:

    $names = $this->input->post('nombre_contacto');
    $emails = $this->input->post('mail_contacto');
    

    Both variables are now arrays, their values are whatever the user input is, and their keys are the order in which they appeared in your form.

    Something like this should give you an idea:

    foreach ($names as $key => $value)
    {
        $contact[$key] = $value;
    }
    foreach ($emails as $key => $value)
    {
        $contact[$key] .= ' - '.$value;
    }
    

    Now you have a new array whose values look like: John Smith - jon@smith.com

    This is just an example, I don’t know what you’re doing with the values.

    One more example: If for some reason you had to access the third name posted, you could use this:

    echo $_POST['nombre_contacto'][2]; // Arrays have 0 based index, so this is #3
    

    This is with your input names containing brackets[]. This in my opinion, is definitely the best way. You won’t need to guess how many inputs there are, because it will be an array.

    Just to clarify: Using brackets in your field names turns the input into an array when it hits the server, making it possible to post multiple values with the same field name. Without brackets, it will be a string value and technically a different field.

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

Sidebar

Related Questions

This question can have different answers because everyone would do it his own way.
this is my first question here so I hope I can articulate it well
this is my first question.. so, here we go. i have a site, 100%
Hello this is may first question and I have found so far the following
First of all, I want to say sorry for this very big question, but
This is my first question on this site, and I only have a basic
First of all, I am sorry that this is not a 'question that can
Hihi all, This could very well be a silly question. I would like to
this is my first question to stackoverflow so here it goes... I use cruise
This is my first question so please be patient :) Background: I'm implementing an

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.