dumdumsareyum Posted May 27, 2007 Share Posted May 27, 2007 I'm very new to php and I'm having trouble getting values from a form. The form has 3 text fields, 4 checkboxes and 4 radio buttons, and then the script is supposed to simply display all the values in the $_POST array after submitted. The problem I'm having is that, no matter what order I put the elements of the form in, the first value submitted is not displayed (i.e. if i put the text fields first, the first text field value is not reported, if the checkboxes are first then the first checkbox will not have a value displayed. Thanks for any advice. Quote Link to comment https://forums.phpfreaks.com/topic/53110-solved-form-help/ Share on other sites More sharing options...
AndyB Posted May 27, 2007 Share Posted May 27, 2007 Without seeing any code .... you do know that the beginning element of an array is element[0] not element[1], right? Quote Link to comment https://forums.phpfreaks.com/topic/53110-solved-form-help/#findComment-262349 Share on other sites More sharing options...
dumdumsareyum Posted May 27, 2007 Author Share Posted May 27, 2007 Here's the code for the display: echo "<html> <head><title>Survey results</title></head> <body"; foreach ($_POST as $field => $value) { echo "$field = $value<br>"; } ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/53110-solved-form-help/#findComment-262358 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 can we see the form please you may have a duplicate name's or something as the php is ok Quote Link to comment https://forums.phpfreaks.com/topic/53110-solved-form-help/#findComment-262366 Share on other sites More sharing options...
kenrbnsn Posted May 27, 2007 Share Posted May 27, 2007 We also need to see the source for your form. Please surround your code with the tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/53110-solved-form-help/#findComment-262370 Share on other sites More sharing options...
dumdumsareyum Posted May 27, 2007 Author Share Posted May 27, 2007 Sure, don't laugh at the content too much, it was just for practice <html> <head> <title>Forms Practice</title </head> <body> <form action = "processforms.php" method = "POST"> Please check all that apply: <br> <INPUT TYPE = "checkbox" NAME = "Catlover"> I love cats. <br> <INPUT TYPE = "checkbox" NAME = "Doglover" > I love dogs. <br> <INPUT TYPE = "checkbox" NAME = "Cat" > I am a cat. <br> <INPUT TYPE = "checkbox" NAME = "Dog" > I am a dog. <br> Last Name: <INPUT TYPE = "TEXT" NAME = "LastName" SIZE = "25" MAXLENGTH = "40"> <br> First Name: <INPUT TYPE = "TEXT" NAME = "FirstName" SIZE = "25" MAXLENGTH = "40"> <br> Password: <INPUT TYPE = "PASSWORD" NAME = "Password" SIZE = "25" MAXLENGTH = "40"> <p> Please select your favorite activity: <br> <INPUT TYPE = "Radio" NAME = "favorite" Value = "hairball"> Cough up hairballs <br> <INPUT TYPE = "Radio" NAME = "favorite" Value = "dogwalk"> Take my dog for walks <br> <INPUT TYPE = "Radio" NAME = "favorite" Value = "catwalk" > Take my cat for walks <br> <INPUT TYPE = "Radio" NAME = "favorite" Value = "poop"> Eat my own poop <br> </p> <INPUT TYPE = "submit" NAME = "submit form" VALUE = "Submit" > <INPUT TYPE = "reset" NAME = "reset form" VALUE = "Reset"> <br> </form> </body> Quote Link to comment https://forums.phpfreaks.com/topic/53110-solved-form-help/#findComment-262372 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 Seams OK to me heres my test built from yours <?php foreach ($_POST as $field => $value) { echo "$field = $value<br />"; } ?> <html> <head> <title>Forms Practice</title </head> <body> <form method = "POST"> Please check all that apply: <INPUT TYPE = "checkbox" NAME = "Catlover"> I love cats. <INPUT TYPE = "checkbox" NAME = "Doglover" > I love dogs. <INPUT TYPE = "checkbox" NAME = "Cat" > I am a cat. <INPUT TYPE = "checkbox" NAME = "Dog" > I am a dog. Last Name: <INPUT TYPE = "TEXT" NAME = "LastName" SIZE = "25" MAXLENGTH = "40"> First Name: <INPUT TYPE = "TEXT" NAME = "FirstName" SIZE = "25" MAXLENGTH = "40"> Password: <INPUT TYPE = "PASSWORD" NAME = "Password" SIZE = "25" MAXLENGTH = "40"> <p> Please select your favorite activity: <INPUT TYPE = "Radio" NAME = "favorite" Value = "hairball"> Cough up hairballs <INPUT TYPE = "Radio" NAME = "favorite" Value = "dogwalk"> Take my dog for walks <INPUT TYPE = "Radio" NAME = "favorite" Value = "catwalk" > Take my cat for walks <INPUT TYPE = "Radio" NAME = "favorite" Value = "poop"> Eat my own poop </p> <INPUT TYPE = "submit" NAME = "submit form" VALUE = "Submit" > <INPUT TYPE = "reset" NAME = "reset form" VALUE = "Reset"> </form> </body> Quote Link to comment https://forums.phpfreaks.com/topic/53110-solved-form-help/#findComment-262380 Share on other sites More sharing options...
dumdumsareyum Posted May 27, 2007 Author Share Posted May 27, 2007 Thanks guys....I ran the php code in the same file as my form like you had and it worked.....so upon further examination I found I was missing a > after the body tag in my processform.php file. Quote Link to comment https://forums.phpfreaks.com/topic/53110-solved-form-help/#findComment-262396 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 Ahh cool if your done in this thread can you click solved (bottom left) Quote Link to comment https://forums.phpfreaks.com/topic/53110-solved-form-help/#findComment-262398 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.