plugindev:event:validateform

event_ValidateForm

(v3.2以降) コメント、メンバー間メール、アカウント認証のいずれかが処理されるときに呼ばれます。プラグインはこれで各データの評価を実行でき、もし不具合があれば処理を中断できます。event_FormExtraと共に使うとフォームにフィールドを追加できます。

呼び出し元

  • ACTION.php(メンバー間メッセージを送信する過程)
            $manager->notify(
                'ValidateForm', 
                array(
                    'type' => 'membermail', 
                    'error' => &$result
                )
            );
  • ADMIN.php(アカウント認証の過程)
    $manager->notify(
        'ValidateForm', 
        array(
            'type' => 'activation', 
            'member' => $mem, 
            'error' => &$error
        )
    );
  • COMMENTS.php(コメント受付の過程)
            $manager->notify(
                'ValidateForm', 
                array(
                    'type' => 'comment', 
                    'comment' => &$comment, 
                    'error' => &$result
                )
            );

使用例

NP_Captcha.php

自動投稿スクリプトに読みとられにくいランダム文字列画像を表示、正しい文字列の入力がない場合は、投稿の受入処理を中断させるプラグイン

    /**
     * Called when a comment or member mail message is validated. We'll check if the 
     * provided captcha solution is correct here. If not, we'll return an error.
     */
    function event_ValidateForm(&$data) {
    
        switch ($data['type'])
        {
            case 'comment':
            case 'membermail':
            case 'activation':
                break;
            default:
                return;
        }
        
        // initialize on first call
        if (!$this->inited)
            $this->init_captcha();
        
        // don't do anything when no GD libraries are available
        if (!$this->isAvailable())
            return;
        
        global $member;
        
        // captchas are not used for registered members
        if ($member->isLoggedIn())
            return;
    
        // get key and attempted solution from request
        $ver_key = postVar('ver_key');
        $ver_sol = postVar('ver_sol');
    
        // check if the solution matches what is in the database
        if (!$this->check($ver_key, $ver_sol))
            $data['error'] = $this->getOption('FailedMsg');
 
    }

このプラグイン自身がFormExtraイベントにより投稿フォームに追加した隠しキーと、投稿者に入力してもらったキーが一致しない場合に$data[’error’]にエラーメッセージを代入して処理を中断させている。

NP_Blacklist.php

    function event_ValidateForm(&$data) {
        $comment = $data['comment'];
        $result = $this->blacklist('comment',$comment['body'].' '.$comment['host'].' '.$comment['user'].' '.$comment['userid']);
        if ($result != '') {
            pbl_logspammer('comment: '.$result);
            redirect($this->getOption('redirect'));
        }
    }

コメント受付の過程で、コメントの本文・コメント記入者情報をスパムかどうか判定し、スパムと判断した場合は即座にリダイレクトジャンプさせる処理。
($data[’type’]が’comment’であるかどうかの分岐は特に行っていない)

 
plugindev/event/validateform.txt · 最終更新: 2006/04/24 12:20 by nakahara21