For the initial form to add new and the editor to edit later:
Code: Select all
<?php // This would be somewhere in your code or an included set of functions
/**
* Outputs a list of radio buttons for a form
*
* @param string $strName Name of the input
* @param array $aryItems Array of the options, in key=>label format
* @param string $strCurrent Current set value to mark correct item checked (default to blank)
* @param string $strSeparator A string of HTML code to place between items (default is <br>)
*/
function echoRadioList($strName,$aryItems,$strCurrent='',$strSeparator='<br>') {
foreach($aryItems as $value=>$label) {
echo '<input id="',$strName,'_',$value,'" name="',$strName,'" type="radio" value="',$value,'" ';
if ($strCurrent==$value) { echo 'checked="checked"'; }
echo '><label for="',$strName,'_',$value,'">',htmlspecialchars($label),'</label>',$strSeparator;
}
}
?>
<td width="150">
<div align="right">
Link Type
</div>
</td>
<td>
<!-- Be sure that for adding new, that you had defaulted $link_type to be a blank string so you don't get a notice -->
<?php echoRadioList('link_type',array('direct'=>'Direct','playlist'=>'Playlist'),$link_type); ?>
</td>
To display value that already exists:
Code: Select all
echo '<b>Link Type:</b> ';
switch ($link_type) {
case 'direct':
echo 'Direct';
break;
case 'playlist':
echo 'Playlist';
break;
default:
echo 'Not Specified';
}
echo '<br>';
The example of the form is using the default of a <BR> between the inputs. Say you needed more (ex, you wanted each one on it's own table row):
Code: Select all
<tr><td><?php echoRadioList('link_type',array('direct'=>'Direct','playlist'=>'Playlist'),$link_type,"</td></tr>\n<tr><td>"); ?></td></tr>
-Greg