Jump to content

unable to read checkbox and radio


sudhakararaog

Recommended Posts

 

i am using a self submitting form

 

<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"];

 

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.

 

Link to comment
Share on other sites

Try using isset()

 

$username = htmlentities($_POST["username"]);
if (!isset($username)) { $error = "enter username \n"; }

$deposit = $_POST["cbox"];
if (!isset($deposit)) { $error = "your error\n"; }

$radioname = $_POST["radioname"];
if (!isset($radioname)) { $error = "your other error\n"; }

Link to comment
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.