为什么我无法为一个变量分配一个wordpress函数? [英] Why I could not assign a wordpress function to a variable?

查看:99
本文介绍了为什么我无法为一个变量分配一个wordpress函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个表单,将表单的详细信息发送到我的电子邮件。这是我的代码:

I am creating a form that sends the form's details to my email. Here is my code:

<?PHP
$errors = array();
if (isset($_POST["submit"])) {
    $to = "myemail@email.com";
    $subject = "This is my subject";    
    $hotel = echo get_permalink();
    $headers = array('From: '.$_POST['sendername'].' <'.$_POST['senderEmail'].'>');
    //Check the name and make sure that it isn't a blank/empty string.
        if(empty($sender)){
            //Blank string, add error to $errors array.        
            $errors['sendername'] = "Please enter your name!";
        }
        if(empty($senderEmail)){
            //Blank string, add error to $errors array.        
            $errors['senderEmail'] = "Please enter your email!";
        }
    $mailBody = "<h3>Hotel Details</h3>"

    $mail_sent = wp_mail( $to, $subject, $mailBody, $headers ); 

}
    if ($mail_sent) { ?>

<h1 style="color: #007f00;">Request sent.</h1>

<?php 
} else {
?>

<form id="" name="" action="<?php echo get_permalink(); ?>" method="post">
    <div class="label-input-wrapper">
        <div class="form-label">Name</div>
        <div class="form-input">
            <input type="text" name="sendername" value="<?PHP if(!empty($errors)) { echo $sender;} ?>" />
            <div class="error-msg">
                <?php if(isset($errors['sendername'])) { echo '<span style="color: red">'.$errors['sendername'].'</span>'; } ?>
            </div>
        </div>
    </div>
    <div class="label-input-wrapper">
        <div class="form-label">E-Mail</div>
        <div class="form-input">
            <input type="email" name="senderEmail" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" required value="<?PHP if(!empty($errors)) { echo $senderEmail;} ?>" />
            <div class="error-msg">
                <?php if(isset($errors['senderEmail'])) { echo '<span style="color: red">'.$errors['senderEmail'].'</span>'; } ?>
            </div>  
        </div>
    </div>

    <input type="submit" value="Submit" name="submit">
</form>

<?php
}  
?>

如果我提交表单,它会显示一个解析错误一个意外的回显变量对于行 $ hotel = echo get_permalink(); 。不能将wordpress函数 get_permalink(); 赋值给一个变量?

If I submit the form it shows a parse error an unexpected echo variable for the line $hotel = echo get_permalink();. Can't I assign the wordpress function get_permalink(); value to a variable?

如果我更改行来自 $ hotel = echo get_permalink(); to $ hotel = permalink(); 它说致命错误:调用未定义的函数permalink()

If I change the line from $hotel = echo get_permalink(); to $hotel = permalink(); it says Fatal error: Call to undefined function permalink()

但是,如果我将一个隐藏的字段放入窗体中,它可以工作:
< input type =hiddenname =hotel_urlvalue =<?php echo get_permalink();?> /> c $ c $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b这样我就可以将该函数的值分配给一个变量,并向我发送具有正确页面URL的电子邮件。

But it works if I put a hidden field into the form: <input type="hidden" name="hotel_url" value="<?php echo get_permalink(); ?>" /> and getting the value like this: $hotel = isset($_POST["hotel_url"]); In this way I am able to assign that function's value into a variable and it send me the email with the correct page URL.

但是我不想使用隐藏了这个。因为还有一些敏感信息,我希望在提交表单时发送到我的电子邮件。如果我使用上述工作方法,任何人都可以看到值,如果看到源代码。

But I do not want to use hidden filed for this. Because there are some sensitive information also I want to send to my email when the form is submitted. If I do that using the above working method anyone can see the values if the see the source code.

那么如何将wordpress函数的值分配给一个变量? / p>

So how can I assign wordpress functions' value to a variable?

推荐答案

您不能像

$hotel = echo get_permalink();

您可以像

$hotel = get_permalink();

这篇关于为什么我无法为一个变量分配一个wordpress函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆