Open YNSTakeru opened 5 months ago
動いたー gitバグったんでデータ吹っ飛ぶと怖いので避難所です src/api/post.php
<?php
require_once __DIR__ . '/../DataSource.php';
use db\DataSource;
use model\ChildTask;
// jsで送られてきたデータを取得
$data = json_decode(file_get_contents('php://input'), true);
try {
$db = new DataSource;
$db->begin();
$sql = 'INSERT INTO parent_tasks (project_id, user_id, title, progress) VALUES (:project_id, :user_id, :title, :progress)';
$db->execute($sql, [':project_id' => $data["project_id"] , ':user_id' => $data["user_id"], ':title' => $data["parent_task_name"], ':progress' => $data["parent_task_progress"]]);
$db->commit();
echo '送信成功!<br>';
} catch(PDOException $e) {
echo '時間をおいて再度お試しください。<br>';
$db->rollback();
}
?>
child_task.model.php
src/models/child_task.model.php
jsファイルregisterBtnのクリックハンドラー内で
fetch("http://localhost:8080/api/post.php", {
method: "POST",
body: JSON.stringify({
"user_id": +userId,
"project_id": projectId,
"parent_task_name": parentTaskName,
"parent_task_progress" : safeParentTaskProgress
}),
})
.then((res) => {
console.log(res);
})
.catch((e) => {
console.error(e);
})
views/member-task.php
<button class="btn transition__btn open__add__task__btn" data-user_id="<?php echo $user->id ?>" data-project_id="<?php echo $project->id ?>" >タスクを追加</button>
``
$user->idに変更
task-add-popup-content.php
```php
<form class="popup" id="task-add-popup" method="POST">
フォームにPOST追加しておいた方が安全?
src/api/post.phpにて作成
まだテストなんで確定ではないです