Jump to content


I THINK this is possible to do, can someone verify?

  • Please log in to reply
2 replies to this topic

#1 BadGoat

  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 07 May 2006 - 02:42 AM


I have a form-driven PHP script that I have been adding on to for some time. The newest attribute I wanted to add to it was to try to make a 'form within a form', where in the overall 15ish variables of the form, I can add a few grouped variables. Being still noobish to PHP I am not sure how to describe it well, but I'll try with an example.

Var 1: Husband Name
Var 2: Wife Name
Var3: Child #1 Name Var 4: Child 1 age Var 5: Child 1 sex

What would be ideal is to be able to add multiple children before submitting the form. Is this possible?

I am not asking anyone to code something, I would like to get a hint or to be explained the concept so I can try to code it on my own. (Best way to learn!)

Thank you

#2 .josh

  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 07 May 2006 - 06:23 AM

well you can make the name for the children text input fields an array. i think that's what you're asking? like so:

$form = "<form blah=blah etc...>";
$form.="Husband <input type = 'text' name='husband'><br>";
$form.="Wife <input type='text' name='wife'><br>";

$x = 1; 
while ($x < 4) { // will count 1 to whatever. 
   $form.="Child ".$x." <input type='text name='child[]'><br>";

$form.="<input type='submit' value='submit'>";

echo $form;

then when the form submits, you would get the info from these variables:


and to make it easier for coding, i suggest doing this for the children:

$children = $_POST['child'];

that way you will have an array called children that holds the children. you can use this array in a loop to quickly list them later like so:

$x = 0;
while ($children[$x]) {
   echo $children[$x] . "<br>";

or just refer to them directly with the (in this example) 3 individual variables:


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 BadGoat

  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 07 May 2006 - 02:18 PM

Hi Crayon,

Yes, I believe that is what I'm looking to accomplish. Would it also be possible to have only one set of child input variables visible, which when filled in display the sets of children below the inputs, so I remember which kids I already entered?

In the meantime,I'm going to go back to my PHP books and read up on arrays.

Thank you kindly for the guidance!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users