在联系表单 7 文本区域中执行 PHP 代码


Executing PHP Code in Contact Form 7 Textarea

我有一个联系表单 7 表单,我希望在文本区域字段中执行 php。

当我用普通形式(即不是插件)对此进行测试时,它工作正常;

 <textarea name="customer-issue" rows="10" cols="40"><?php if(isset($_GET['content'])) { echo $_GET['content']; } ?></textarea>

有谁知道您将如何在CF7中做到这一点

除了 JpDevs 的代码:

他在设置$html变量时忘记了一些''。这是有效的:

function cs7() {
    $var=$_GET['content'];
    $html='<p>'.$var.'</p>';
    return $html;
}
add_shortcode('cs7', 'cs7');

然后只需将 [cs7] 添加到表单中即可。

当你使用''时,你必须通过连接点来将变量写在外面

$result = '<p>'.$var.'</p>';

当你使用" "时,你可以把它们写进去

$result = "<p>$var</p>";

请查看下面提到的链接:

https://wordpress.org/support/topic/contact-form-7-input-fields-values-as-php-get-viarables

希望这对您有帮助

制作代码

$var=$_GET['content']; 

到短代码,

并将生成的短代码粘贴到您的联系表单 7 文本区域中

例如:

函数.php

function cs7() 
{
$var=$_GET['content'];
$html='<p>.$var.</p>';
return $html;
}
add_shortcode('cs7', 'cs7');

在联系人窗体区域中添加 [CS7]