[英]send text from a php file to a variable in html
Can i send text from a php file into a variable in an html file? 我可以将文本从php文件发送到html文件的变量中吗? I have an if statement in my php, that checks if a field is empty.
我的PHP中有一个if语句,用于检查字段是否为空。 If it is empty then i want to send to my html file a text saying 'please fill the field' and put it in a label in my html.
如果为空,那么我想向我的html文件发送一个文本,说“请填写字段”,并将其放在html的标签中。 Is there a way for that?
有办法吗?
<?php
$name = $_REQUEST['author'];
$from = $_REQUEST['email'];
$subj = $_REQUEST['sub'];
$message = $_REQUEST['msg'];
$subject = $subj;
$body = $message;
$headers .= "From: ".$from;
$to = "mail@mail.com";
if ($name = ''){
HERE i want to send a text to a variable named 'reason' in my html in case $name is empty.
}
if(mail($to,$subject,$body,$headers)) {
header( "Location: http://www.mysite.com/contactForm-english" );
} else {
echo "There was a problem sending the mail. Check your code and make sure that the e-mail address ".$to." is valid";
}
?>
Yes, you'll just echo out the HTML like any other ordinary echo. 是的,您将像其他任何普通回声一样回显HTML。
echo '<label>Test</label>';
It can be embed right in your HTML (as long it's a PHP file, obviously) like this: 可以将其直接嵌入HTML中(显然,只要是PHP文件即可),如下所示:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<?php echo $something === true ? '<label>test</label>' : ''; ?>
</body>
</html>
<?php echo $variable; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.