PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Am developing a CMS, and the current page I am working on has a number of options for the user to select using radios. They have the option to include some external links, the number of which can be selected from a jump menu. The code below work perfectly, but when the page is redisplayed with input fields for the external links, the radios are reset.
<form name="form1" method="post" action="">
<table width="445" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="315"><strong>Do you require "back" and "next" buttons? </strong></td>
<td width="66"><input name="bn_buttons" type="radio" value="1" checked>
Yes </td>
<td width="64"><input name="bn_buttons" type="radio" value="0">
No</td>
</tr>
<tr bgcolor="#CCCCCC">
<td><strong>Would you like a "quick menu"? </strong></td>
<td><input name="q_menu" type="radio" value="1">
Yes</td>
<td><input name="q_menu" type="radio" value="radiobutton">
No</td>
</tr>
<tr>
<td><strong>How many external links would you like?</strong></td>
<td colspan="2"><select name="el_menu" class="el_menu" onChange="MM_jumpMenu('parent',this,1)">
<option selected><? if(isset($_GET['el'])){ echo $_GET['el']; }else{ echo "None"; } ?></option>
<option value="<? echo $_SERVER['PHP_SELF'] . "?el=1"; ?>">1</option>
<option value="<? echo $_SERVER['PHP_SELF'] . "?el=2"; ?>">2</option>
<option value="<? echo $_SERVER['PHP_SELF'] . "?el=3"; ?>">3</option>
<option value="<? echo $_SERVER['PHP_SELF'] . "?el=4"; ?>">4</option>
</select> </td>
</tr>
<tr bgcolor="#CCCCCC">
<td><strong>Will the main menu display on every page? </strong></td>
<td><input name="m_menu" type="radio" value="1">
Yes</td>
<td><input name="m_menu" type="radio" value="0" checked>
No</td>
</tr>
<tr bgcolor="#FFFFFF">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor="#CCCCCC">
<td>
<? if(isset($_GET['el'])){
if($_GET['el']){
$s = s;
}
echo "<p><b>Please enter the URL$s and the name$s of the link$s below</b></p>";
$el_num = $_GET['el'];
$i = 1;
while($i <= $el_num){
echo "External link # $i <input type=\"text\" name=\"el_name_$i\" value=\"Label\"> <input type\"text\" name=\"el_url_$i\" value=\"URL\"><br><br>";
$i++;
}
}
?>
</td>
</tr>
</table>
</form>
Is there a way to make the radios sticky without submitting the form? If not (and I suspect this will be the case), is there a better method to use than a jump menu to reload the page with the input fields?
the jump menu could submit the form for redisplay, however I usually code this sort of thing to dynamically generate and inject the additional form element tags needed. With your code, I'd add an id to the table cell where these are two be displayed and use the appendChild() DOM methods to inject the elements into the table and associate them with the form. Search my posts for appendChild for a, albeit slightly complex, example of it.