您还可以使用 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 的顶部)