WordPress - 在表单提交上运行功能

时间:2017-06-05 04:43:32

标签: php wordpress forms

我正在尝试为我网站上的用户执行以下操作。

  1. 如果用户尝试登录但尚未激活,则允许用户重新发送激活电子邮件。

  2. 检查他们输入的电子邮件是否在尚未激活的当前用户列表中

  3. 我试图通过短代码执行此操作,因此页面本身的代码包含在以下函数中。我还没有编写功能来检查用户当前的用户列表(但在其他地方有这个代码,并且不一定需要该代码。 我知道我需要在表单上采取行动,但这是我空白的地方,似乎无法找到对我有意义的答案。

    function resend_activation_email_form() {
    echo 'Activation Email Form<br>';
    echo '<form><input type="email"><br>';
    echo '<button type="submit">Resend Activation Email</button></form>';
    }
    add_shortcode('resend_activation','resend_activation_email_form'); 
    

1 个答案:

答案 0 :(得分:0)

向表单添加操作,然后在短代码中添加条件

add_shortcode('resend_activation','resend_activation_email_form'); 
$post_arr = array();
if(isset($_POST['reSendMail']))
{
$post_arr = $_POST;
}
do_shortcode('[resend_activation passdata='.$post_arr.']'); 

修改功能

function resend_activation_email_form($attr) {
var_dump($attr);
    if(isset($attr['passdata']) && !empty($attr))
    {
        var_dump($attr);
    }
    else
    {
    echo 'Activation Email Form<br>';
    echo '<form action=""><input type="email"><br>';
    echo '<button name="reSendMail" type="submit">Resend Activation Email</button></form>';
    }
}