我制作了一个名为esrnumber的额外自定义字段。我onUserBeforeSave()
在插件中的 php 文件中添加了一个函数。这应该从我的自定义字段中获取 esrnumber 以及从注册表单中获取名称,检查数据库,如果它们匹配则返回 true。从而允许用户注册。
问题是我似乎无法将表单中的字段值获取到这个 php 脚本中。下面是我的代码。
function onUserBeforeSave($user, $isnew, $new){
//sql code removed for example
$foundesr = false;
if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['esrnumber'])) {
$test = $_GET['esrnumber'];
} else if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['esrnumber'])) {
$test = $_POST['esrnumber'];
} else {
$test = "booo";
}
if($foundesr == false){
JError::raiseWarning(1000, JText::_('There is a problem with your ESR number, ' . JRequest::getVar('username') . JRequest::getVar('esrnumber') . JRequest::getVar('jform_username') . $test . 'it does not match that name in our records.'));
return false;
}
return true;
}
正如您所看到的,其中大部分是不必要的,我刚刚尝试了几种不同的方法来从注册表单字段中检索值,它们都返回空值。我哪里错了?我怎样才能简单地从我的表单中获取值到这个方法中?
这是 Joomla 为表单生成的HTML代码(asfaik 这是所有默认内容)
<div class="registration">
<form id="member-registration" action="/index.php/component/users/?task=registration.register" method="post" class="form-validate">
<fieldset>
<legend>User Registration</legend>
<dl>
<dt>
<span class="spacer"><span class="before"></span><span class="text"><label id="jform_spacer-lbl" class=""><strong class="red">*</strong> Required field</label></span><span class="after"></span></span> </dt>
<dd> </dd>
<dt>
<label id="jform_name-lbl" for="jform_name" class="hasTip required" title="Name::Enter your full name">Name:<span class="star"> *</span></label> </dt>
<dd><input type="text" name="jform[name]" id="jform_name" value="pirateballoon@gmail.com" class="required" size="30"/></dd>
<dt>
<label id="jform_username-lbl" for="jform_username" class="hasTip required" title="Username::Enter your desired user name">Username:<span class="star"> *</span></label> </dt>
<dd><input type="text" name="jform[username]" id="jform_username" value="pirateballoon@gmail.com" class="validate-username required" size="30"/></dd>
<dt>
<label id="jform_password1-lbl" for="jform_password1" class="hasTip required" title="Password::Enter your desired password - Enter a minimum of 4 characters">Password:<span class="star"> *</span></label> </dt>
<dd><input type="password" name="jform[password1]" id="jform_password1" value="" autocomplete="off" class="validate-password required" size="30"/></dd>
<dt>
<label id="jform_password2-lbl" for="jform_password2" class="hasTip required" title="Confirm Password::Confirm your password">Confirm Password:<span class="star"> *</span></label> </dt>
<dd><input type="password" name="jform[password2]" id="jform_password2" value="" autocomplete="off" class="validate-password required" size="30"/></dd>
<dt>
<label id="jform_email1-lbl" for="jform_email1" class="hasTip required" title="Email Address::Enter your email address">Email Address:<span class="star"> *</span></label> </dt>
<dd><input type="text" name="jform[email1]" class="validate-email required" id="jform_email1" value="pirateballoon@gmail.com" size="30"/></dd>
<dt>
<label id="jform_email2-lbl" for="jform_email2" class="hasTip required" title="Confirm email Address::Confirm your email address">Confirm email Address:<span class="star"> *</span></label> </dt>
<dd><input type="text" name="jform[email2]" class="validate-email required" id="jform_email2" value="pirateballoon@gmail.com" size="30"/></dd>
</dl>
</fieldset>
<fieldset>
<legend>User ESR Profile</legend>
<dl>
<dt>
<label id="jform_esrprofile_esrnumber-lbl" for="jform_esrprofile_esrnumber" class=" required">ESR Number<span class="star"> *</span></label> </dt>
<dd><input type="text" name="jform[esrprofile][esrnumber]" id="jform_esrprofile_esrnumber" value="" class="required"/></dd>
</dl>
</fieldset>
<div>
<button type="submit" class="validate">Register</button>
or <a href="/" title="Cancel">Cancel</a>
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="registration.register" />
<input type="hidden" name="b44564159b9c7ebe3b7caf93cc5ce8de" value="1" /> </div>
</form>
我个人从未调用过我创建的新方法,我只是创建了该方法,而 Joomla 似乎在提交表单时会自动调用它。
干杯。