Kynan Pacheco
Kynan Pacheco

Reputation: 207

PHP Radio button form handling

I'm using radio buttons on a form for my website. I am currently trying to write some error checking. If the radio button isn't set when the form is submitted what will $_GET return? I tried echoing it and it appears to be "", but my if statement isn't picking up on it. Is it just not returning a value at all?

Upvotes: 0

Views: 77

Answers (2)

philip mudenyo
philip mudenyo

Reputation: 754

when radio button is not selected it is not set in the $_GET. Do this

$radion_value = isset($_GET['radio_button_name']) ? true : false;
if($radio_value){
// value is set 
}
else { 
// not set
}

Upvotes: 2

Dhanesh
Dhanesh

Reputation: 324

Use form method as POST , using GET method in form submit is not good practice . If you are using POST method, you can check like below

if(!isset($_POST['radio_buttonname'])){
//Your error message set here
} 

If you are using GET method.Use below code,

if(!isset($_GET['radio_buttonname'])){
//Your error message set here
} 

Upvotes: 1

Related Questions