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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:48:52+00:00 2026-05-20T18:48:52+00:00

Hi Stackoverflow i hope you are all well today, i seem to have run

  • 0

Hi Stackoverflow i hope you are all well today,

i seem to have run into an issue and am kindly requesting your assistance;

Basically i am using jQuery to manipulate a form, the form then stores in the session and upon returning to the page a foreach loop is used to return the values from the session into the page.

The issue is if I create more than one instance of this foreach loop it gives me an invalid argument (if i add the same code over and over again it works fine)

So firstly here is the code;

jQuery

    $(function(){
$('.add_child').click(function(){
    var attrName = $(this).attr('name');
    var count = $(this).attr('count');
    $(this).attr('count', (parseInt(count)+1))
    var input = $('<input />');
    var lineBreak = $('<br/>');
    input.attr('type','text')
    input.attr('name',attrName+"["+count+"]" ) 
    $('.children_form').append(input);
    $('.children_form').append(lineBreak);
})
$('.add_s_child').click(function(){
    var attrName = $(this).attr('name');
    var count = $(this).attr('count');
    $(this).attr('count', (parseInt(count)+1))
    var input = $('<input />');
    var lineBreak = $('<br/>');
    input.attr('type','text')
    input.attr('name',attrName+"["+count+"]" ) 
    $('.spouce_children').append(input);
    $('.spouce_children').append(lineBreak);
})
});

and the PHP / HTML CODE -> Button One (add_child)

Children, please name your natural and / or addopted children

<?php foreach($_SESSION['children'] as $index=>$child){ ?>
<?php echo "<input type='text' name='children[{$index}]' value='{$child}'/>";?>
<?php } ?>

<input type="button" count='<?php echo count($_SESSION['children']);?>' name="children" class="add_child" value="Add Another Child"/>

<div class="children_form">
<?php //add the inputs here?>   
</div>

and the PHP / HTML CODE -> Button Two (spouce_children)

<label>Spouces Children, please name all natural and addopted children</label>
<input type="text" name="spoucechild" id="spoucechild" />

<?php foreach($_SESSION['spoucechild'] as $index=>$child){ ?>
<?php echo "<input type='text' name='spoucechild[{$index}]' value='{$child}'/>";?>
<?php } ?>

<input type="button" count='<?php echo count($_SESSION['spoucechild']);?>' name="spoucechild" class="add_s_child" value="Add Another Child"/>
<div class="spouce_children">
    <?php //add the inputs here?>     
</div>

I would like to thank you for any help you can / will provide <3

Error Occurs here:

<?php foreach($_SESSION['spoucechild'] as $index=>$child){ ?>
  • 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-20T18:48:53+00:00Added an answer on May 20, 2026 at 6:48 pm

    @Xavier: You could try —

    <?php
    if (isset($_SESSION['spoucechild'])) {
        foreach($_SESSION['spoucechild'] as $index=>$child){
            echo '<input type="text" name="spoucechild[' . $index . ']" value="' . $child . '" />' . "\n";
        }
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this all day (and yesterday as well). Basically, I
Hello Stack Overflow i hope you are well today; I have a form that
First question on stackoverflow :) Hope I won't embarrass myself... I have a javascript
Hello all at StackOverflow.. Reasonably new to this site, but I have had nothing
I have read several interesting C#/F# comparisons here on stackoverflow. So, first of all,
Greetings all, I have posted this on the MSDN managed news groups as well
I have a pathological issue with SQL, so I usually sort all of my
Well I hope this question fits to Stackoverflow ( if otherwise, I want to
Hi fellow StackOverflow guys, First of all this is on Magento 1.7.0.2. I have
First time stackoverflow user but occasional lurker, hope you guys can help me out.

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.