Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/53110-solved-form-help/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/53110-solved-form-help/#findComment-262372
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/53110-solved-form-help/#findComment-262380
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.