0

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?

3
  • 2
    if the radio button is not chosen, it's empty, which will result in "". do a: if (empty($_GET['radio_button']) { /* do something */ } else { /* do something */ } Commented Jun 13, 2017 at 14:45
  • 2
    Can you share your code, please? Commented Jun 13, 2017 at 14:46
  • the name of radio button won't exist in $_POST Commented Jun 13, 2017 at 14:51

2 Answers 2

2

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
}
Sign up to request clarification or add additional context in comments.

Comments

1

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
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.