このイベントは、プラグインがコメント、メンバー間メール、アカウント追加フォーム、追加メンバー認証フォームのいずれかのフォーム内に追加フィールドを挿入するときに使います。フォーム処理の際に発生する ValidateForm イベントに対応します。
createaccount.php 92行目
$manager->notify('FormExtra', array('type' => 'membermailform-notloggedin'));
ADMIN.php 2254行目
$manager->notify('FormExtra', array('type' => 'activation', 'member' => $mem));
フォームのテンプレートが格納されている「nucleus/form」ディレクトリのテンプレート内で、特殊なテンプレート変数を使用することによって、ACTIONS.phpの565行目の
$manager->notify($eventName, array('type' => $type));
から呼び出される例
additemform.template 28行目
<%callback(FormExtra,additemform)%>
commentform-loggedin.template 16行目
<%callback(FormExtra,commentform-loggedin)%>
commentform-notloggedin.template 21行目
<%callback(FormExtra,commentform-notloggedin)%>
membermailform-loggedin.template 11行目
<%callback(FormExtra,membermailform-loggedin)%>
membermailform-notloggedin.template 14行目
<%callback(FormExtra,membermailform-notloggedin)%>
すべて二つ目の引数が、「type」として渡される。
ADMIN.php 2254行目のみの追加の引数
NP_Captcha.php (自動投稿スクリプトに読みとられにくいランダム文字列画像を表示、正しい文字列の入力がない場合は、投稿の受入処理を中断させるプラグイン。)
function event_FormExtra(&$data) { switch ($data['type']) { case 'commentform-notloggedin': // anonymous comments case 'membermailform-notloggedin': // anonymous message to site member case 'activation': // activation or re-activation of member account 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; // create captcha key. This key is required to // // 1. create the captcha image // 2. check the validity of the entered solution $key = $this->generateKey(); $aVars = array( 'imgHtml' => $this->generateImgHtml($key), 'key' => htmlspecialchars($key) ); switch ($data['type']) { case 'activation': echo TEMPLATE::fill($this->getOption('ActivationHtml'), $aVars); break; case 'commentform-notloggedin': echo TEMPLATE::fill($this->getOption('CommentFormHtml'), $aVars); break; case 'membermailform-notloggedin': echo TEMPLATE::fill($this->getOption('MemberMailHtml'), $aVars); break; } }
コメント受付フォームに追加echoしているフォームのテンプレートはデフォルトで次のように定義されている。
$commentFormHtml =
'<br />' . "\n"
.'<label for="nucleus_cf_verif"><%imgHtml%></label>' . "\n"
.'<br />' . "\n"
.'<label for="nucleus_cf_verif">Enter the string of characters appearing in the picture:</label><input name="ver_sol" size="6" maxlength="6" value="" class="formfield" id="nucleus_cf_verif" />' . "\n"
.'<input name="ver_key" type="hidden" value="<%key%>" />';