可移动类型页面模板中的php代码

可移动类型页面模板中的php代码,php,movabletype,Php,Movabletype,我正试图为一家使用移动式平台的公司写一份联系表。我正在创建供他们使用的页面模板。我95%确信我的php代码和html对于表和相互引用都是正确的——这不是问题的根源。但是,MT不会自动呈现php。取而代之的是,我得到了一大块php文本。html呈现得很好。我不确定如何强制MT识别php。我找不到直接解决此问题的设置或任何内容。我能在机器翻译帮助/常见问题解答区域找到的最接近的是。但是我尝试过使用他们提供的代码,但是它完全没有改变页面的呈现方式。下面是我尝试使用的php,但我不认为这是问题的根源。我

我正试图为一家使用移动式平台的公司写一份联系表。我正在创建供他们使用的页面模板。我95%确信我的php代码和html对于表和相互引用都是正确的——这不是问题的根源。但是,MT不会自动呈现php。取而代之的是,我得到了一大块php文本。html呈现得很好。我不确定如何强制MT识别php。我找不到直接解决此问题的设置或任何内容。我能在机器翻译帮助/常见问题解答区域找到的最接近的是。但是我尝试过使用他们提供的代码,但是它完全没有改变页面的呈现方式。下面是我尝试使用的php,但我不认为这是问题的根源。我想我应该包括它以防万一。我只是错过了我需要如何为MT标记东西的要点吗?我第一次使用Movable-Type平台,第三次使用php,所以在解释我所缺少的东西时,请随意和我交谈,就像我是个婴儿一样

<?php

if(isset($_POST['email'])) {    

    // EDIT THE 2 LINES BELOW AS REQUIRED

    $email_to = "blank@mydomain.com";

    $email_subject = "Web Contact Response";

    function died($error) {

        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die(); 
    }


    // validation expected data exists

    if(!isset($_POST['name']) ||  
        !isset($_POST['email']) || 
        !isset($_POST['telephone']) || 
        !isset($_POST['comments'])) {

        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $name = $_POST['name']; // required  
    $email_from = $_POST['email']; // required 
    $telephone = $_POST['telephone']; // not required 
    $comments = $_POST['comments']; // not required



    $error_message = ""; 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }

    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) { 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
  }

  if(!preg_match($string_exp,$last_name)) { 
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; 
  }

  if(strlen($comments) < 2) { 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';   
  }

  if(strlen($error_message) > 0) {
    died($error_message);
  }

    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Name: ".clean_string($name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

Thank you for contacting us. We will be in touch with you very soon.  
<?php 
}
?>

感谢您联系我们。我们将很快与您联系。

Movable Type逐字输出模板中的文本,但MT模板标记除外,它们会被相应地处理

例如,如果索引模板仅包含以下代码:

<?php
<a href="<$mt:BlogURL$>"><$mt:BlogName$></a>
?>

它将在为该索引模板设置的发布路径处生成一个包含以下文本的文件:

<?php
<a href="http://blogurl.com">My Blog</a>
?>

如果发布的文件是通常通过PHP解析器运行的类型,例如
.PHP
文件,则只有在用户请求文件时,web服务器才会解析PHP。Movable Type在发布时不涉及任何PHP代码,也不涉及MT模板标记以外的任何内容。其余的只是按原样输出

根据您的问题,您可能试图将上述代码放在机器翻译页面的主体中,并在页面模板上使用类似于
的机器翻译标记。您将代码描述为输入时出现在结果页面上,这对我来说是意料之中的。我猜您可能在一个以
.html
结尾的页面上输出此PHP,因此PHP没有进行解析,但如果不知道您在哪里输入上述代码以及生成结果文件的模板的发布路径,我无法确定

如果是这样的话,您只需将模板发布路径的扩展名更改为
.php
,就可以解决问题。或者,如果模板自动使用系统扩展名,您可能需要转到博客设置“常规设置”页面,并将“归档设置”下的“文件扩展名”更改为
php


仅供参考,
encode_php
修饰符用于将数据插入php代码时,如文档示例所示:
$the_title=''。这不是为了在
PageBody
EntryBody
标记上用于您打算运行的代码的一般输出,因为它可能会最终转义您在页面上输入的代码中的各种内容。

您正确地猜测了我将php和.html文件扩展名放在哪里。我马上就要下班了,但我明天第一件事就是试试你的办法,看看会发生什么。