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!