<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$hedef = $_POST["hedef"] ?? "Bilinmiyor";
echo "Form $hedef hedefi ile post edildi";
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>R10</title>
<script>
function butonEkle() {
let container = document.getElementById("butonlar");
let butonSayisi = container.getElementsByTagName("button").length + 1;
let yeniForm = document.createElement("form");
yeniForm.method = "POST";
yeniForm.action = "index.php";
let yeniButton = document.createElement("button");
yeniButton.type = "submit";
yeniButton.innerText = "Gönder " + butonSayisi;
let gizliInput = document.createElement("input");
gizliInput.type = "hidden";
gizliInput.name = "hedef";
gizliInput.value = (butonSayisi % 2 === 0) ? "Amerika" : "Türkiye";
yeniForm.appendChild(gizliInput);
yeniForm.appendChild(yeniButton);
container.appendChild(yeniForm);
}
</script>
</head>
<body>
<h2>Buton Kopyalama ve Farklı Post Verileri Gönderme</h2>
<div id="butonlar">
<form method="POST" action="index.php">
<input type="hidden" name="hedef" value="Türkiye">
<button type="submit">Gönder 1</button>
</form>
</div>
<button onclick="butonEkle()">Buton Ekle</button>
</body>
</html>