ich habe der Code geschrieben wie du sagst , aber bekomme nichts... , wenn auf Webformular schreibe name, email und message , sie werde schrieben auf dem webformular noch auf test.txt .…
Mein Code:
<?php
header('Content-Type: text/html; Charset=utf-8');
mb_internal_encoding('UTF-8');
date_default_timezone_set('Europe/Berlin');
error_reporting(-1);
error_reporting(E_ALL);
class ClassProveContakt3 {
private $Name;
private $Email;
private $Message;
function __construct() {
$this->Name="";
$this->Email="";
$this->Message="";
}
function Form() {
// y aqui muestras lo que recuperaste, al inicio nombre="" asi que no sale nada
// en el primer submit se recupera nombre y se debe mostrar en el inpu
echo('<table>');
echo('<label for="name">Name </label>');
echo('<input type="text" name="Name" value="'.$this->Name.'">');
echo('<label for="email"> Email </label>');
echo('<input type="email" value="'.$this->Email.'" name="Email" ');
echo('<tr>');
echo('<td>');
echo('<br>');
echo('<label> Message: <br><textarea cols="45" rows="6" name="Message">'.$this->Message.'</textarea></label>');
echo('<br><br>');
echo('<input type="submit" name="post" value="POST COMMENT" id="comment">');
echo('</td>');
echo('</tr>');
echo('</table>');
}
function GetPostData()
{
if (!isset($_POST['Name']) || empty($_POST['Email']) || empty($_POST['Message']))
{
$this->Name = trim($_POST['Name']);
$this->Email = trim($_POST['Email']);
$this->Message = trim($_POST['Message']);
}
}
function PostOk()
{
// aqui recuperas las variables desde Post
// pon los filtros que consideres necesarios
if (!isset($_POST['post']))
{
return;
}
if (empty($this->Name) || empty($this->Email) || empty($this->Message))
{
echo "<br>" . "<b>" . "<h3>*** Please enter all required fields ***</h3>" . "</b>";
}
else {
$file = "test.txt";
$name = filter_input( INPUT_POST, 'Name', FILTER_SANITIZE_STRING);
$email = filter_input(INPUT_POST, 'Email', FILTER_SANITIZE_STRING);
$message = filter_input(INPUT_POST, 'Message', FILTER_SANITIZE_STRING);
$datetime = date('m/d/Y h:i:s a', time());
$data = array("name" => $name, "email" => $email, "message" => $message, "datetime" => $datetime);
$data = serialize($data);
file_put_contents($file, $data . "\n", FILE_APPEND|LOCK_EX);
$messages = file($file);
foreach ($messages as $value) {
$data = unserialize($value);
echo "<br>"
. "<b>From: </b>" . htmlspecialchars( $data["name"])
. "<b> at: </b>" . htmlspecialchars( $data["datetime"])
. "<br><br>" . htmlspecialchars( $data["email"])
. "<br><br>" . htmlspecialchars( $data["message"])
. "<br><hr>";
}
}
}
}
?>