我嘗試了下面的代碼,我無法弄清楚我做錯了什麼。我知道我通過將表格分散到兩個不同的div中來打破規則,但我不知道其他任何方式。嘗試將表單中單選按鈕的值發送到php變量。
<?php
echo '<form name="form" method="POST">';
$directory = '/var/www/admin/html/content';
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
echo 'Files<br>';
while($it->valid()) {
if(!$it->isDot()) {
echo '<input type="radio" name="file_picked" value="content/' . $it->getSubPathName() . ' " id="file_picked" />' . $it->getSubPathName() . '</br>';
}
$it->next();
}
echo '<input type="submit" name="pickedName" value="Edit File" /></div>
<div class="editor">
<h1>SS Code Editor</h1>';
$file_picked = $_POST['file_picked'];
$edit_field = $_POST['edit_field'];
if(isset($_POST['pickedName'])) {
//get file contents and display in textarea box
$theData = file_get_contents($file_picked);
echo "<textarea name=\"edit_field\" id=\"edit_field\" cols=\"100\" rows=\"60\">";
echo $theData;
echo "</textarea><br />";
}
if(isset($_POST['submitChanges'])) {
//grab new textarea contents and put into file.
$theData = file_put_contents($file_picked, $edit_field);
//redraw textarea with new contents
$theData = file_get_contents($file_picked);
echo "<textarea name=\"edit_field\" id=\"edit_field\" cols=\"100\" rows=\"60\">";
echo $theData;
echo "</textarea><br />";
}
?>
<input type="submit" name="submitChanges" value="Save">
</form>