我想使用以下方法制作一个表单来验证WordPress中是否存在用户。
这是我对 HTML 页面的内容:
<html>
<head>
<title>Is it legit?</title>
</head>
<p><body>
<h3>Search by email</h3>
<p>Input the email address to verify membership.</p>
<form method="post" action="search.php" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
</body>
</html>
</p>
然后,我希望输出为:
if ( $exists )
echo "Yes! (their email) is a member!";
else
echo "No! (their email) is NOT a member!";
根据其他搜索,我发现了这个(需要将电子邮件输入到代码本身中:
<?php
require_once("wp-load.php");
$email = 'myemail@example.com';
$exists = email_exists($email);
if ( $exists )
echo "Member exists";
else
echo "Member does not exist";
?>
那么,我该如何将两者结合起来呢?我会把第三个示例中的 PHP 代码放入搜索中.php这是从第一个示例中寻址的 HTML 页面中使用的吗?
您可以找到完整的详细信息,了解和使用WordPress内置函数 email_exists
检查,电子邮件地址是否已注册。
如果注册,它将返回该注册电子邮件的id
。
如果没有,它将返回false
。
email_exists
完整的细节可以在这里找到。
不,没有必要在 php 文件中对电子邮件进行硬编码以将其与用户输入的email
进行比较。您必须将用户输入的值接收到search.php
文件中。
$email = $_POST['name'];
您的代码将如下所示。
<?php
require_once("wp-load.php");
$email = $_POST['name']; //Receiving and assigning user inputted value into $email.
$exists = email_exists($email);
if ( $exists )
echo "Yes! $email is a member!";
else
echo "No! $email is NOT a member!";
?>
建议:出于安全考虑,请在 html 文件中使用搜索框的输入type = email
。
您需要输入PHP代码才能在search.php文件中搜索电子邮件。此文件将在提交表单时执行。
也许这就是你想要的。
<?php
require_once("wp-load.php");
$email = addslashes($_POST['name']); //Since the form input name is name
$exists = email_exists($email);
if ( $exists )
echo "Yes! $email is a member!";
else
echo "No! $email is NOT a member!";
?>