表单操作未转到右侧php页面



我在modal中创建了表单,但在提交表单时,它没有转到正确的页面,也就是本例中的edithw.php。

以下是模态的内容:

$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,希望能解决这个问题,但没有。

注意:Form不会去任何地方,它停留在memberpage.php上,memberpagephp也有提交,它用于将家庭作业添加到数据库中。edithw.php用于编辑。

我发现在其他模态上from标记没有关闭,所以无法创建新的form标记。

通过将</form>添加到exampleModal,我解决了这个问题。

我只是发现标签不小心丢了。

最新更新