I created form in modal, but when submitting form, it doesn't go to the right page, where it should go, which is in this case, edithw.php.
Here is content of 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>";
The whole code is in 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!';
}
?>
Why might this be happening? I changed early action from edithw.php to full URL, hoping that maybe fix the problem, but it didn't.
Note: Form is going nowhere, staying on memberpage.php which have submit also, and it's used to add homeworks to database. edithw.php is for editing.