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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;
}
?>

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.