Php 在wordpress页面中添加隐藏字段
在页面中具有自定义html表单:Php 在wordpress页面中添加隐藏字段,php,wordpress,Php,Wordpress,在页面中具有自定义html表单: <form action="localhost/mail.php" id="contactForm" method="post"> <ul> <li> <input type="hidden" name="submitted" value="USERNAME_HERE" /></li> <li> <butt
<form action="localhost/mail.php" id="contactForm" method="post">
<ul>
<li>
<input type="hidden" name="submitted" value="USERNAME_HERE" /></li>
<li>
<button type="submit">Send request</button>
</li>
</ul>
</form>
-
-
发送请求
我是否可以将当前登录的用户名添加到value=?
所以当用户点击“发送请求”按钮时,我会在电子邮件中收到他的用户名吗
已尝试使用[userinfo field=“user\u login”]和:
但是所有的php代码都被删掉了,因此毫无用处:(
请告知我做错了什么
谢谢!通常,我使用页面模板在页面中使用PHP。设置好模板后,您可以执行以下操作:
<?php
/*
* Template Name: Custom Form
* Description: Form with pre-filled username.
*/
global $current_user;
get_currentuserinfo();
?>
<form action="localhost/mail.php" id="contactForm" method="post">
<ul>
<li>
<input type="hidden" name="submitted" value="<?php echo $current_user->user_login; ?>" />
</li>
<li>
<button type="submit">Send request</button>
</li>
</ul>
</form>
-
也许这会有帮助:
<?php
$user_nameField = $_POST['user_name'];
?>
<form action="localhost/mail.php" id="contactForm" method="post">
<ul>
<li>
<input name="user_name" type="hidden" id="user_name" value="<?php echo $ulog; ?>"></li>
<li>
<button type="submit">Send request</button>
</li>
</ul>
</form>
-
使用此插件:
您需要在此插件中创建一块php代码,然后将其作为短代码放到页面中
因此,您的php代码如下所示:
<?php
global $current_user;
get_currentuserinfo();
$username = $current_user->user_login;
?>
<form action="localhost/mail.php" id="contactForm" method="post">
<ul>
<li>
<input type="hidden" name="submitted" value="<?php echo $username; ?>" /></li>
<li>
<button type="submit">Send request</button>
</li>
</ul>
</form>
-
您在哪里添加php代码?大家好,谢谢您的回复,可能我在主题中不太清楚。这里有没有办法在仪表板->页面->HTML页面中添加用户名?不是在模板页面中。再次感谢!我可以将此代码添加到仪表板->页面HTML中吗?否:(在我保存页面后,所有php代码都被删除了……不幸的是,您不能在帖子或页面中以本机方式使用php。我知道这可能需要做很多工作,但在使用WordPress时知道如何创建模板非常有用,我保证您不会后悔学习。
<?php
global $current_user;
get_currentuserinfo();
$username = $current_user->user_login;
?>
<form action="localhost/mail.php" id="contactForm" method="post">
<ul>
<li>
<input type="hidden" name="submitted" value="<?php echo $username; ?>" /></li>
<li>
<button type="submit">Send request</button>
</li>
</ul>
</form>