BadGoat Posted May 7, 2006 Share Posted May 7, 2006 Hello!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 NameVar 2: Wife NameVar3: Child #1 Name Var 4: Child 1 age Var 5: Child 1 sexWhat 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 Quote Link to comment Share on other sites More sharing options...
.josh Posted May 7, 2006 Share Posted May 7, 2006 well you can make the name for the children text input fields an array. i think that's what you're asking? like so:[code]$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;[/code]then when the form submits, you would get the info from these variables:$_POST['husband'] $_POST['wife']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:[code]$x = 0;while ($children[$x]) { echo $children[$x] . "<br>";}[/code]or just refer to them directly with the (in this example) 3 individual variables:$children[0] $children[1]$children[2] Quote Link to comment Share on other sites More sharing options...
BadGoat Posted May 7, 2006 Author Share Posted May 7, 2006 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.