|
-
Nov 17th, 2004, 09:33 AM
#1
Thread Starter
Member
Radio Buttons and Checkboxes Not posting
Hello everyone,
I am hoping some PHP expert out there can help this newbie with the problem I am having.
I have a form with textfields, checkboxes, and radio buttons. These value are submitted using the POST method to another php page. The problem is if a checkbox is not checked or a radio button in a group is not selected, then nothing shows up in the corresponding $_POST array. By nothing I mean the checkbox or radio button name is not present in the array. I don't understand this.
Here is how I am creating the checkboxes and radio buttons.
<INPUT type=RADIO name=\"q1\" value=\"2\">2
<INPUT type=RADIO name=\"q20\" value=\"Yes\">Yes
Any help with this problem would be greatly appreciated.
-
Nov 17th, 2004, 11:17 AM
#2
That is how radio buttons and checkboxes work, if they are checked/selected they are present in $_POST/$_GET, otherwise they are not.
-
Nov 17th, 2004, 12:20 PM
#3
Thread Starter
Member
Thanks twanvl,
I have found a way to get around the problem. I have another question though. I need to know when a textarea comes in empty. What is the value of an empty textfield? I have tried using "" and NULL, but that doesnt seem to work.
if ($temp != NULL) {
print $temp;
}
Still prints
Thanks
-
Nov 17th, 2004, 01:13 PM
#4
if a textarea is empty it's value should =="" and also ==="". How can you see that it prints if it prints an empty string?
-
Nov 17th, 2004, 01:59 PM
#5
Thread Starter
Member
Hi twanvl,
I can't actually see the empty string printing, but the value for the field is printing. The field name is only supposed to show up if there is an entry.
(like this)
Field Name: "The field text"
if there is no text in the field then I should get nothing, but instead I get
Field Name: <nothing>
I have found a work around though. Instead of checking for "" or null, I just check to see if the length of the string is equal to 0.
Thanks for all of your help
-
Nov 30th, 2004, 05:46 PM
#6
If you want to force a value for a particular field, use a hidden input tag.
Code:
<input tyoe="hidden" name="q1" value="undefined" />
<input type="radio" name="q1" value="2">2
<input type="radio" name="q20" value="Yes">Yes
If the use doesn't select a radio button, then the hidden field value provails and gets sent through, if they do, the value of the radio button selected is submitted instead.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|