【发布时间】:2020-08-14 18:00:10
【问题描述】:
我在模态中创建了表单,但是在提交表单时,它没有进入正确的页面,它应该去的地方,在这种情况下是edithw.php。
这里是modal的内容:
$dialogContent = " <div class=\"modal-header\">
<h4 class=\"modal-title\" id=\"editModalLabel\">Muokkaa Läksy</h4>
</div>
<div class=\"modal-body\">
<form action='https://developerfromjokela.com/homework/web/edithw.php' method=\"post\">
<div class=\"form-group\">
<label for=\"hwtitle\">Läksyn otsikko</label>
<input type=\"text\" class=\"form-control\" name=\"hwtitle\" id=\"hwtitle\" placeholder=\"Biologian läksy...\" value=\"$name\"/>
</div>
<div class=\"form-group\">
<label for=\"hwdetails\">Läksyn tiedot</label>
<input type=\"text\" class=\"form-control\" name=\"hwdetails\" id=\"hwdetails\" placeholder=\"Sivu 12 tehtävä 1 luettavaksi...\" value=\"$details\"/>
</div>
<div class=\"form-group\">
<label class=\"label-control\">Palautuspäivä</label>
<input type=\"date\" name=\"hwdonedate\" value=\"$donedate\"/>
</div>
<div style='visibility: hidden;'>
<input type='text' name='hwid' value='$hwid'/>
</div>
<label class=\"mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect\" for=\"checkbox-1\">
<input type=\"checkbox\" id=\"checkbox-1\" name=\"done\" value=\"1\" class=\"mdl-checkbox__input\" $checked />
<span class=\"mdl-checkbox__label\">Tehty</span>
</label>
<input type=\"submit\" name='submit' class=\"btn btn-primary\" value='Tallenna'/>
<a href='memberpage.php' class='btn btn-primary'>Takaisin</a>
</form>
</div>";
整个代码在pastebin中: https://pastebin.com/JTr9pVmC
edithw.php:
<?php require('includes/config.php');
if(!$user->is_logged_in()){ header('Location: login.php'); exit(); }
if (isset($_POST['submit'])) {
$stmt = $db->prepare('SELECT * FROM homeworks WHERE homeworkID = :id');
$stmt->execute(array(':id' => $_POST['hwid']));
$row2save = $stmt->fetch(PDO::FETCH_ASSOC);;
$username = $row2save['owner'];
if ($username === $_SESSION['username']) {
$done = 0;
if ($_POST['done'] === 1) {
$done = 1;
}
$stmt = $db->prepare('UPDATE homeworks
SET name = :name, details = :details, donedate = :donedate, done = :done
WHERE homeworkID = :id');
$stmt->execute(array(':id' => $_POST['hwid'], ':name' => $_POST['hwtitle'], ':details' => $_POST['hwdetails'], ':donedate' => $_POST['hwdonedate'], ':done' => $done));
} else {
$params = session_get_cookie_params();
setcookie(session_name('USERNAME'),'RESTRICTED',1,
isset($params['path']),
isset($params['domain']),
isset($params['secure']),
isset($params['httponly']));
header('Location: memberpage.php?restricted='.$row2save['owner']);
}
} else {
echo 'Error! No form inputs found!';
}
?>
为什么会发生这种情况?我将早期操作从 edithw.php 更改为完整 URL,希望可以解决问题,但没有。
注意:表单无处可去,停留在也有提交的memberpage.php上,用于将作业添加到数据库。 edithw.php 用于编辑。
【问题讨论】: