|
|
|
| script6_1.php и script6_2.php объединил в один:
<?
# Скрипт script6_1.php к задаче 6
if ($_REQUEST['ok'])
file_put_contents('data.txt', serialize($_REQUEST));
if (!file_exists('data.txt'))
{
include 'index.html';
die();
}
preg_match_all('/type="radio".*?value="([^"]*)"/i', file_get_contents('index.html'), $arr);
$mass = unserialize(file_get_contents('data.txt'));
echo "<form name=script6_1 action=\"\" method=post>";
foreach ($mass as $key=>$val)
{
preg_match('/([^_]*_)/', $key, $type);
if ($val!=="0") $chec = "CHECKED"; else $chec = "";
switch ($type[0])
{
case 'radio_':
foreach ($arr[1] as $val2)
{
if ($val2===$val) $chec = "CHECKED"; else $chec = "";
echo "<input type=\"radio\" name=\"$key\" value=\"$val2\" $chec>radio<br>";
}; break;
case 'check_':echo "<input type=hidden name=$key value=0>";
echo "<input type=checkbox name=$key value=1 $chec>checkbox<br>"; break;
case 'text_': echo "<input type=text name=$key value=$val >text<br>"; break;
case 'textarea_': echo "<textarea name=$key>$val</textarea>textarea<br>"; break;
}
}
echo "<input type=submit name=ok>";
echo "</form>";
?>
|
index.html:
<form name="script6_1" action="script6_1.php" method="post">
<input type="radio" name="radio_" value="1" CHECKED>radio<br>
<input type="radio" name="radio_" value="2">radio<br>
<input type="radio" name="radio_" value="3">radio<br>
<input type="radio" name="radio_" value="4">radio<br>
<input type="hidden" name="check_1" value="0">
<input type="checkbox" name="check_1" value="1">checkbox<br>
<input type="hidden" name="check_2" value="0">
<input type="checkbox" name="check_2" value="2">checkbox<br>
<input type="hidden" name="check_3" value="0">
<input type="checkbox" name="check_3" value="3">checkbox<br>
<input type="text" name="text_" >text<br>
<textarea name="textarea_"></textarea>textarea<br>
<input type="submit" name="ok">
</form>
|
| |
|
|