If - Else problem
Posted: Mon Oct 10, 2011 5:30 am
Hi guys, new to the board, and new to PHP, hope you can help 
I'm trying to retain the values that a user has clicked on radio buttons and still display them when the form reloads.
I have this code to keep the variable :
and then this to enter the value in the correct radio button on reload:
This isn't working and I can't see why, no matter which radio is selected, when the form is reloaded, they are all unchecked other than the bottom (Offline NB) which is checked. It's as if it's completely ignoring all the 'If' statements.
Can anyone shed any light on this for me? Thankyou!
I'm trying to retain the values that a user has clicked on radio buttons and still display them when the form reloads.
I have this code to keep the variable :
Code: Select all
//Check which PolicyType is checked
$FirstOnlineRNWLStatus = 'unchecked';
$OnlineRNWLStatus = 'unchecked';
$FirstOfflineRNWLStatus = 'unchecked';
$OfflineRNWLStatus = 'unchecked';
$OnlineNBStatus = 'unchecked';
$OfflineNBStatus = 'unchecked';
if (isset($_POST['post'])){
$selectedPolicyType = $_REQUEST["PolicyType"];
if ($PolicyType == '1stOnlineRNWL')
{
$FirstOnlineRNWLStatus = 'checked';
}
elseif ($PolicyType == 'OnlineRNWL')
{
$OnlineRNWLStatus = 'checked';
}
elseif ($PolicyType == '1stOfflineRNWL')
{
$FirstOfflineRNWLStatus = 'checked';
}
elseif ($PolicyType == 'OfflineRNWL')
{
$OfflineRNWLStatus = 'checked';
}
elseif ($PolicyType == 'OnlineNB')
{
$OnlineNBStatus = 'checked';
}
elseif ($PolicyType == 'OfflineNB')
{
$OfflineNBStatus = 'checked';
}
}Code: Select all
label>
<input name="PolicyType" type="radio" id="PolicyType_3" value="1stOnlineRNWL" checked="<?php print $FirstOnlineRNWLStatus; ?>" />
1st Yr Online RNWL</label>
<br />
<label>
<input type="radio" name="PolicyType" value="OnlineRNWL" id="PolicyType_4" checked="<?php print $OnlineRNWLStatus; ?>"/>
Online Renewal</label>
<br />
<label>
<input type="radio" name="PolicyType" value="1stOfflineRNWL" id="PolicyType_5" checked="<?php print $FirstOfflineRNWLStatus; ?>" />
1st Yr Offline RNWL</label>
<br />
<label>
<input type="radio" name="PolicyType" value="OfflineRNWL" id="PolicyType_6" checked="<?php print $OfflineRNWLStatus; ?>" />
Offline RNWL</label>
<br />
<label>
<input type="radio" name="PolicyType" value="OnlineNB" id="PolicyType_7" checked="<?php print $OnlineNBStatus; ?>"/>
Online NB</label>
<br />
<label>
<input type="radio" name="PolicyType" value="OfflineNB" id="PolicyType_8" checked="<?php print $OfflineNBStatus; ?>"/>
Offline NB</label>
<br />
<br />Can anyone shed any light on this for me? Thankyou!