Re: [PHP] Re: A form and an array
Jason Carson wrote: Jason Carson wrote: Hello everyone, Lets say I have a file called form.php with the following form on it that redirects to index.php when submitted. I would like to take the values of the text fields in the form and put them into an array, then be able to display the values in that array on index.php Does anyone know how I would do that? Here is my form... form action=index.php method=post table tr tdOption1/td tdinput type=text name=option[] //td /tr tr tdOption2/td tdinput type=text name=option[] //td /tr tr td/td tdinput value=submit name=submit type=submit //td /tr /table /table/form You'll find they are already in an array which you can access as $_POST['option'] - from there foreach() should be the next step. Cheers -- David Robley Polls show that 9 out of 6 schizophrenics agree. Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I am new to programming. How would I use foreach()to display the entries in the array? You could read TFM which has an example - http://php.net/manual/en/control-structures.foreach.php Cheers -- David Robley Why are you wasting time reading taglines? Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: A form and an array
Jason Carson wrote: Jason Carson wrote: Hello everyone, Lets say I have a file called form.php with the following form on it that redirects to index.php when submitted. I would like to take the values of the text fields in the form and put them into an array, then be able to display the values in that array on index.php Does anyone know how I would do that? Here is my form... form action=index.php method=post table tr tdOption1/td tdinput type=text name=option[] //td /tr tr tdOption2/td tdinput type=text name=option[] //td /tr tr td/td tdinput value=submit name=submit type=submit //td /tr /table /table/form You'll find they are already in an array which you can access as $_POST['option'] - from there foreach() should be the next step. Cheers -- David Robley Polls show that 9 out of 6 schizophrenics agree. Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I am new to programming. How would I use foreach()to display the entries in the array? You could read TFM which has an example - http://php.net/manual/en/control-structures.foreach.php Cheers -- David Robley Why are you wasting time reading taglines? Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php What I currently have is... foreach ($_POST['option'] as $value) { echo Value: $valuebr /\n; } ...but that doesn't work. TFM didn't help me :-( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: A form and an array
Did you correct the missing double quote in your sending form first? Warren Vail -Original Message- From: Jason Carson [mailto:ja...@jasoncarson.ca] Sent: Thursday, July 23, 2009 9:33 PM To: php-general@lists.php.net Subject: Re: [PHP] Re: A form and an array Jason Carson wrote: Jason Carson wrote: Hello everyone, Lets say I have a file called form.php with the following form on it that redirects to index.php when submitted. I would like to take the values of the text fields in the form and put them into an array, then be able to display the values in that array on index.php Does anyone know how I would do that? Here is my form... form action=index.php method=post table tr tdOption1/td tdinput type=text name=option[] //td /tr tr tdOption2/td tdinput type=text name=option[] //td /tr tr td/td tdinput value=submit name=submit type=submit //td /tr /table /table/form You'll find they are already in an array which you can access as $_POST['option'] - from there foreach() should be the next step. Cheers -- David Robley Polls show that 9 out of 6 schizophrenics agree. Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I am new to programming. How would I use foreach()to display the entries in the array? You could read TFM which has an example - http://php.net/manual/en/control-structures.foreach.php Cheers -- David Robley Why are you wasting time reading taglines? Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php What I currently have is... foreach ($_POST['option'] as $value) { echo Value: $valuebr /\n; } ...but that doesn't work. TFM didn't help me :-( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: A form and an array
Yes Did you correct the missing double quote in your sending form first? Warren Vail -Original Message- From: Jason Carson [mailto:ja...@jasoncarson.ca] Sent: Thursday, July 23, 2009 9:33 PM To: php-general@lists.php.net Subject: Re: [PHP] Re: A form and an array Jason Carson wrote: Jason Carson wrote: Hello everyone, Lets say I have a file called form.php with the following form on it that redirects to index.php when submitted. I would like to take the values of the text fields in the form and put them into an array, then be able to display the values in that array on index.php Does anyone know how I would do that? Here is my form... form action=index.php method=post table tr tdOption1/td tdinput type=text name=option[] //td /tr tr tdOption2/td tdinput type=text name=option[] //td /tr tr td/td tdinput value=submit name=submit type=submit //td /tr /table /table/form You'll find they are already in an array which you can access as $_POST['option'] - from there foreach() should be the next step. Cheers -- David Robley Polls show that 9 out of 6 schizophrenics agree. Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I am new to programming. How would I use foreach()to display the entries in the array? You could read TFM which has an example - http://php.net/manual/en/control-structures.foreach.php Cheers -- David Robley Why are you wasting time reading taglines? Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php What I currently have is... foreach ($_POST['option'] as $value) { echo Value: $valuebr /\n; } ...but that doesn't work. TFM didn't help me :-( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: A form and an array
In php.ini turn the display_errors to on. If any error,warn or notice shown,copy them and paste here. So you can tell us what doesn't work. good luck~ 2009/7/24 Jason Carson ja...@jasoncarson.ca Jason Carson wrote: Jason Carson wrote: Hello everyone, Lets say I have a file called form.php with the following form on it that redirects to index.php when submitted. I would like to take the values of the text fields in the form and put them into an array, then be able to display the values in that array on index.php Does anyone know how I would do that? Here is my form... form action=index.php method=post table tr tdOption1/td tdinput type=text name=option[] //td /tr tr tdOption2/td tdinput type=text name=option[] //td /tr tr td/td tdinput value=submit name=submit type=submit //td /tr /table /table/form You'll find they are already in an array which you can access as $_POST['option'] - from there foreach() should be the next step. Cheers -- David Robley Polls show that 9 out of 6 schizophrenics agree. Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I am new to programming. How would I use foreach()to display the entries in the array? You could read TFM which has an example - http://php.net/manual/en/control-structures.foreach.php Cheers -- David Robley Why are you wasting time reading taglines? Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php What I currently have is... foreach ($_POST['option'] as $value) { echo Value: $valuebr /\n; } ...but that doesn't work. TFM didn't help me :-( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: A form and an array
I have it working now. I had a comma where a semicolon should have been. Silly error on my part but thanks to everyone who tried to help me. In php.ini turn the display_errors to on. If any error,warn or notice shown,copy them and paste here. So you can tell us what doesn't work. good luck~ 2009/7/24 Jason Carson ja...@jasoncarson.ca Jason Carson wrote: Jason Carson wrote: Hello everyone, Lets say I have a file called form.php with the following form on it that redirects to index.php when submitted. I would like to take the values of the text fields in the form and put them into an array, then be able to display the values in that array on index.php Does anyone know how I would do that? Here is my form... form action=index.php method=post table tr tdOption1/td tdinput type=text name=option[] //td /tr tr tdOption2/td tdinput type=text name=option[] //td /tr tr td/td tdinput value=submit name=submit type=submit //td /tr /table /table/form You'll find they are already in an array which you can access as $_POST['option'] - from there foreach() should be the next step. Cheers -- David Robley Polls show that 9 out of 6 schizophrenics agree. Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I am new to programming. How would I use foreach()to display the entries in the array? You could read TFM which has an example - http://php.net/manual/en/control-structures.foreach.php Cheers -- David Robley Why are you wasting time reading taglines? Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php What I currently have is... foreach ($_POST['option'] as $value) { echo Value: $valuebr /\n; } ...but that doesn't work. TFM didn't help me :-( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: From form to an array
* Thus wrote Jeff McKeon ([EMAIL PROTECTED]): Form two has 2 fields for every line and the fields need to be kept in separate arrays. /* form2.php */ form action=?PHP Echo $_SERVER['PHP_SELF'] ? method=POST input type=hidden name=tiers value=?PHP ECHO $_POST['form1info'] ? input type=text name=tier[] input type=text name=price[]br input type=text name=tier[] input type=text name=price[]br At this point I'm not sure what your question is now, but while I'm here I would suggest to define your fields like this to make it easier to handle: input type=text name=levels[1][tier] input type=text name=levels[1][price]br input type=text name=levels[2][tier] input type=text name=levels[2][price]br Then in php: $levels = $_POST['levels']; foreach ($levels as $i = $level) { echo $level['tier']; echo $level['price']; ... } Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: From form to an array
DvDmanDT wrote: Hmm... Intresting... Like... Hmm.. Name the elements of the second form like input name=array1[LINE_NUM] input name=array2[LINE_NUM] Then turn on register_globals, then you'll very automaticly have $array1 and $array2.. Sorry register_globals are off and not getting turned on... e=swen http://securityresponse.symantec.com/avcenter/venc/data/[EMAIL PROTECTED] ml ## Jeff McKeon [EMAIL PROTECTED] skrev i meddelandet news:[EMAIL PROTECTED] . Is it possible to pass the values of a form directly into an array? I have a multi level, dynamic form. The first level (first form actually) askes how many levels there are and gives you a field to enter in that number. Then upon submit of form1 it creates a new form (form2) that contains 2 fields for each level (the number of levels was entered in form1). So if you entered 2 in the first form, you'd be given another form with 2 lines, each containing 2 fields. Ok, now on submit of this second form I want to take field1 from each line and put it into $array1 and field2 from each line and put it into $arrray2. Then pass those array's to a function as elements. Any idea how I can do this? Thanks, Jeff -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Jeff McKeon IT Manager Telaurus Communications LLC [EMAIL PROTECTED] (973) 889-8990 ex 209 ***The information contained in this communication is confidential. It is intended only for the sole use of the recipient named above and may be legally privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication, or any of its contents or attachments, is expressly prohibited. If you have received this communication in error, please re-send it to the sender and delete the original message, and any copy of it, from your computer system. Thank You.*** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: From form to an array
[snip] Ok, now on submit of this second form I want to take field1 from each line and put it into $array1 and field2 from each line and put it into $arrray2. [/snip] Form 1's info would have to be held as hidden fields in Form 2's construction. An example ... /* formOne.php */ form action=nextForm.php method=POST input type=text name=formOneArray[] input type=submit /form /* nextForm.php */ form action=processForms.php method=POST input type=text name=formTwoArray[] input type=text name=formTwoArray[] input type=hidden name=formOneArray[] value=?php echo $_POST['formOneArray[0]']; ? /form Not tested, but should be pretty close -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: From form to an array
Jay Blanchard wrote: [snip] Ok, now on submit of this second form I want to take field1 from each line and put it into $array1 and field2 from each line and put it into $arrray2. [/snip] Form 1's info would have to be held as hidden fields in Form 2's construction. An example ... /* formOne.php */ form action=nextForm.php method=POST input type=text name=formOneArray[] input type=submit /form Jay, Sorry but I don't follow what your doing here. Form one doesn't need an array, it only has one piece of data, the number of rows that form2 should have. /* nextForm.php */ form action=processForms.php method=POST input type=text name=formTwoArray[] input type=text name=formTwoArray[] input type=hidden name=formOneArray[] value=?php echo $_POST['formOneArray[0]']; ? /form Not tested, but should be pretty close Form two has 2 fields for every line and the fields need to be kept in separate arrays. /* form2.php */ form action=?PHP Echo $_SERVER['PHP_SELF'] ? method=POST input type=hidden name=tiers value=?PHP ECHO $_POST['form1info'] ? input type=text name=tier[] input type=text name=price[]br input type=text name=tier[] input type=text name=price[]br input type=text name=tier[] input type=text name=price[]br input type=submit name=submit value=submit /form Does that make more sense or am I just not understanding what your trying to do? Thanks, Jeff -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php