链接到自定义Wordpress主题中的自定义.php文件


Linking to a custom .php file in custom Wordpress theme

我正在制作一个Wordpress主题,其中有一个Jquery动画联系人表单。我已经得到了js工作(一个div得到显示/隐藏点击,在它的形式)。下面是一个静态HTML/PHP示例(点击"contact"按钮)。你说有什么问题?问题是实际的表单没有被发送。我已经得到了php文件'contact engine.php',在我的模板目录中发送一个名为'php'的文件夹内的表单。在HTML中,我有:

<form method="post" action="<?php bloginfo('template_directory'); ?>/php/contactengine.php">
            <label for="Name">Name:</label>
            <input type="text" name="Name" id="Name" />
            <label for="Email">Email:</label>
            <input type="text" name="Email" id="Email" />
            <label id="bericht" for="Message">Message:</label><br />
            <textarea name="Message" rows="10" cols="20" id="Message"></textarea>
            <input type="submit" name="submit" value="Submit" class="submit-button" />
</form>

经过一番折腾后,我将问题缩小到指向php文件的实际链接。Wordpress不会将输入发送到php文件,什么也不会做。经过几次Google会话后,我发现大多数人使用插件来实现这一点,我不喜欢这个插件。此外,Wordpress似乎不允许您编写自己的php代码片段来实现主题。我还发现了一些建议,我应该把php代码片段放在每个模板自带的functions.php文件中,但我不知道如何链接到functions.php中的特定php代码片段。有人知道怎么解吗?提前感谢!

注:php脚本如下所示:

<?php
$EmailFrom = "contactformulier@stefanhagen.nl";
$EmailTo = "info@stefanhagen.nl";
$Subject = "Contactformulier StefanHagen.nl";
$Name = Trim(stripslashes($_POST['Name'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv='"refresh'" content='"0;URL=error.htm'">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "'n";
// $Body .= "Tel: ";
// $Body .= $Tel;
// $Body .= "'n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "'n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "'n";
// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page 
if ($success){
print "<meta http-equiv='"refresh'" content='"0;URL=../index.html'">";
}
else{
print "<meta http-equiv='"refresh'" content='"0;URL=error.htm'">";
}
?>

我知道当你在WordPress中提交表单时,你的代码将无法工作,因为WordPress过滤了所有的post变量。当您使用自己的脚本时,不应该发生这种情况。那么contactenengine .php脚本是什么样的呢?你在里面使用了WordPress的include吗?如果是这样,你可以处理WordPress脚本。

我在你的网站上看到的是& lt;php bloginfo ?("template_directory");?>没有出现。使用起来也更好& lt;php echo get_template_directory_uri();?>

对于人们使用的插件,我也这样做。很容易在后端更改表单,但这可能是一个缺点,因为客户可以更改它。