473,605 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unable to read checkbox and radio

54 New Member
i am using a self submitting form
[php]
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST" id="test2" name="test1">

i need to do a validation of textfields, checkboxes, radio buttons

i am able to read, display and validate textfields after the form has been submitted however i am getting an error for

checkbox and radio buttons.

code for textfields

username <input type="text" name="username" value="<?php echo($username) ; ?>" />

$username = htmlentities($_ POST["username"]);

if($username == "") { $error.=" enter username <br />"; }

for checkboxes and radio buttons i am getting
"Notice: Undefined index: checkboxname " for checkbox
"Notice: Undefined index: radiobuttonname " for radio button

presently the code for checkbox and radio button is

<input type="checkbox" name="cbox" value="abc" />

$deposit = $_POST["cbox"];


<input type="radio" name="radioname " value="one"> one
<input type="radio" name="radioname " value="two"> two

$radioname = $_POST["radioname"];
[/php]
i have tried cbox[] radioname[] however i keep getting
"Notice: Undefined index: cbox " and "Notice: Undefined index: radioname "
for checkbox and radio button

please advice.

thanks.

Use the appropriate code tags when showing any code in this forum! See the Posting Guidelines before you continue - moderator
Feb 29 '08 #1
2 2804
hsriat
1,654 Recognized Expert Top Contributor
Although I didn't get what you are trying to ask. But I'll tell you a good way to debug such things.

In the file, whom you have set as the value of action attribute in form tab, comment all the code and add this in the starting (just temporarily).[php]<?php
echo "<pre>";
print_r($_POST) ;
echo "</pre>";
?>[/php]

This may help you solve your problem.
Feb 29 '08 #2
henryrhenryr
103 New Member
I reckon the error is caused because your form doesn't know if it's been submitted or not...

Try adding something like:

Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="submitted" value="true" />
  2.  
inside the form tags.

Then at the TOP (ie before the form-display itself) put something like:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (isset($_POST['submitted'])) {
  3.   $radioname= $_POST['radioname'];
  4.   //now do something with this value...
  5.   echo $radioname;
  6. }
  7. else {
  8.   $radioname=NULL;
  9. }
  10. ?>
  11.  
This way if you reference $radioname, you won't get the notice about the missing index when you first load the page (and the $_POST array has nothing in it). You can avoid all notices like this by using "isset " on the variable before using it. IE:

Expand|Select|Wrap|Line Numbers
  1. $radioname = (isset($_POST['radioname'])) ? $_POST['radioname'] : NULL;
  2.  
Something to note too - when you use self-submitting forms, if you hit refresh on your browser, the form will resubmit so normally you have to keep a track of whether it's been submitted - I use sessions, you can use DB too...
Feb 29 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2295
by: Arun Nair | last post by:
Hi, I have the following jsp page. I am able to view only a part of it(until the occurence of the first City text box). If i remove the first few fields from the page, I am able to see a few more fields at the bottom. My form class contains all the properties that are used in the jsp page. I don't know what I am doing wrong. I am using struts1.1 & JDK 1.4.2.
1
6207
by: David Wake | last post by:
I have two radio buttons and two checkboxes in a form. I'm trying to write some code so that when a radio button is selected, its corresponding checkbox is disabled. My code looks like this: function radioClicked(index) { document.table_config_form.my_checkbox.disabled = true;
1
3499
by: John Mullen | last post by:
I want to take the following HTLM and use javascript to turn on radio buttons if checkbox is checked, can I do this with javascript (maybe onClick or an array) or do i need a server side script ? <li>ABACAVIR SULFATE</li> <INPUT NAME="ingredient0" TYPE=checkbox VALUE="ABACAVIR SULFATE"><br> <input name="ABACAVIR SULFATE AMOUNT" type="radio" value="EQ 300MG BASE">EQ 300MG BASE<br> <input name="ABACAVIR SULFATE AMOUNT" type="radio" value="EQ...
4
7284
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button if the condition is checked on the same page. Thanks in advance for your help
2
9188
by: /.. | last post by:
Hi all, I'm working on a report display page that currently uses 5 checkboxlists with a total of 86 items to display values from 5 different tables in an Access database. The page works fine now. On presenting it to the users they pointed out that their users could change the values in the checkboxes and then print them out, ultimately documenting false information.
5
3362
by: tshad | last post by:
Is there a way to allow a user to press a radio button if it is already selected? There is an onCheckedChanged event that fires when the person presses the button and it is isn't selected already. If it is selected, it doesn't fire. This isn't the case with a checkbox. The event fires whether the control is already checked or not. Thanks,
3
4432
by: newjazzharmony | last post by:
Hello group, I want to automatically select a specific checkbox when a user clicks (selects) a specific item in a radiobutton group. Both controls are in the same form. Let's say for argument's sake that the form looks like this (inessential items left out for the sake of clarity): <form name=form1>
0
2745
by: ballamber | last post by:
This is a solution to the problem. Works with .NET 2.0. So the problem is displaying a data bound read-only checkbox or radio button in a GridView without actually disabling those controls. I assume you know what templates are in a GridView. Examples are in VB.NET. Sorry... So as a first step create a function in the page's underlying class that returns the string "checked" based on the bound data. Here's what I did. The underlying data...
3
1946
by: chiku1523 | last post by:
Hi, Please find the following code. In function setAnswers, I am looping with each question. I have inner loop, which is looping for each answers of the questions. If any of the answer for question 1 and question2 is selected this code is working fine. But if None of answer of either question selected, it is not iterating through outer loop. Please help me to point out the error. <html> <head> <style type="text/css"> body...
0
8004
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8425
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1271
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.