Reputation: 591
I have one html page with on top php form validation to check if the fields are empty, after that a html form and after that some html that displays a error message if fields are not filled in. The top of the form looks like:
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
In the PHP that is on top of the page, I check to see if the input fields are empty.
if($_SERVER["REQUEST_METHOD"]==='POST')
{
if($_POST["field1"]==""){
$errormessage = "field1 is not empty";
}elseif($_POST["field2"]==""){
$errormessage = "field1 is not empty";
}else{
// if the fields are both filled in i want to send the form
//variables to mailing.php where are the variables are mailed
}
This is the html for the errorcode that is part of my page:
If both fields are filled I want to send the POST data to mailing.php
where I can format the variables into a html email.
Because i have a lot of variables I want to send the whole $_POST variable to mailing.php using:
header('location:mailing.php?post='.$_POST);
But how do i acces a varable inside the $_POST in mail.php? This did not work:
$inputfield = $_GET["post"]["field1"];
Upvotes: 0
Views: 32
Reputation: 12937
This is a bad design. You should include mailing.php
and write a logic to access $_POST
depending on some conditions. However if you still wish to forward the request, you can achieve it using cURL
.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/mailing.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
$data = curl_exec($ch);
curl_close($ch);
Upvotes: 1