Jump to content

if else with radio buttons


psquillace

Recommended Posts

Hello All:

 

I am writing a php snip or at least trying too where if one radio button is selected we go to this URL otherwise go to this URL.

 

I started something like this but I get lost real quick after that because I never did an if else with radio buttons before.

 

Any help would be appreciated.

 

<?php

 

if ($radio1 'selected' ? "http://"){

}else{

"http://"

}

 

 

sorry for such a hack job on that above I just don't know that much about php...

 

 

Link to comment
https://forums.phpfreaks.com/topic/163443-if-else-with-radio-buttons/
Share on other sites

ok, I was able to learn for my self how this is supposed to get done

 

<?php

if(isset($_POST['radio00'])) header("location $url"); {

$URL="http://emrcontractor.com/index.php?option=com_content&view=article&id=8&Itemid=2"

}else{

$URL="http://emrcontractor.com/index.php?option=com_content&view=article&id=1&Itemid=3"

}

?>

 

in case anyone else needs it....

bit wrong the if() header() won't work for both URL cases.

 

 

<?php 
if(isset($_POST['radio00']))  {
$URL="http://emrcontractor.com/index.php?option=com_content&view=article&id=8&Itemid=2"
}else{
$URL="http://emrcontractor.com/index.php?option=com_content&view=article&id=1&Itemid=3"
}
header("location $URL");
?>

 

the correct way

Hey!

 

Remember that radio buttons are form elements. It means that it contains a name and a value, like other elements (type="text", textarea...).

 

So, if you have a form like this:

 

<form method="post" action="">
<input type="radio" name="myRadio" value="1" /> Option 1
<input type="radio" name="myRadio" value="2" /> Option 2
<input type="submit" value="Send" />
</form>

 

On PHP, you can use $_POST['myRadio'] to retrieve the selected radio button:

 

<?php
$myRadio = intval($_POST['myRadio']);

if ($myRadio === 2)
{
    header("Location: http://www.address1.com");
    die;
} else {
    header("Location: http://www.address2.com");
    die;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.