PHP-HTML-Preview函数
今天我试着做一个PHP“HTML”编辑器, 你可以编写你的“HTML”代码,预览它,然后发送到我的电子邮件。 代码如下:PHP-HTML-Preview函数,php,html,Php,Html,今天我试着做一个PHP“HTML”编辑器, 你可以编写你的“HTML”代码,预览它,然后发送到我的电子邮件。 代码如下: <?php ini_set('display_errors', 1); error_reporting(E_ALL); if (isset($_POST['submit'])){ // $to = file_get_contents('to.txt'); $to = "jonas.geiler@gmail.com"; $subject = "Form to e
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
if (isset($_POST['submit'])){
// $to = file_get_contents('to.txt');
$to = "jonas.geiler@gmail.com";
$subject = "Form to email message";
$message = $_POST["message"];
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$header .= 'From: Skayos Blog <blog.skayo@mail.com>' . "\r\n";
mail($to,$subject,$message,$header);
} else if (isset($_POST['preview'])){
$output = $_POST["message"];
echo $output;
}
?>
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="" method="post">
Message:<br>
<textarea rows="5" name="message" cols="30"><html> <body> </body> </html></textarea><br>
<input type="submit" name="preview" value="Preview">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
提交表格
信息:
html body/body/html
我的问题是:如果我按Preview,则侧边将重新加载预览,代码将被删除。
有没有一种简单的方法让代码停留在文本区域
谢谢,Skayo1)简单的解决方案当您的代码发布时更改textarea的值。
<?php
$msg = "";
if (strlen($_POST['message'] > 0)
$msg = $_POST['message'];
?>
Message:<br><textarea rows="5" name="message"
value="<?php echo $msg; ?>" cols="30"><html>
<body> </body> </html></textarea><br>
<script>
function prewiev() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("message").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "preview.php?str=" + document.getElementById("message").value, true);
xmlhttp.send();
}
<form action="" method="post">
Message:<br>
<textarea id="message" rows="5" name="message" cols="30">
<html><body> </body>
</html>
</textarea><br>
<button name="preview" onClick="prewiev()">
<input type="submit" name="submit" value="Submit">
</form>