cURL を使用して、ロジックに応じて form.php から edit.php または add.php への POST リクエストを作成することもできます。
フォーム.php
$value1 = $_POST["field1"];
//assuming your field names are field1 etc..
//assign variables for all fields.
$body = "field1=".value1."&field2=".value2;
//etc for all field/value pairs
//to transmit same names to edit.php or add.php
//pseudo code for condition based on $_POST["action"]
if(condition TRUE for add.php){
$url = "example2.com/add.php";
} elseif((condition TRUE for edit.php){
$url = "example3.com/edit.php";
}
if(isset($url)){ //most probably true, but just for safe-guard
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1); //we are making POST request
curl_setopt($ch, CURLOPT_POSTFIELDS, $body); //setting the POST fields
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
}
//do something based on $response
//like doing a simple header redirect to $url
これで、add.php または edit.php は、POST フォーム リクエストを受け取っているように見えます。
両方が 200 (成功) または 404 (失敗) で応答を送信するようにして、$response で取得し、必要に応じて続行できるようにします。
ユーザー入力は既にサニタイズされていると想定していることに注意してください。(これは、$value1 に何かを割り当てる前に、form.php の上に置く必要があります)