它在 jform 中:components/com_users/models/forms/registration.xml
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset name="default"
label="COM_USERS_REGISTRATION_DEFAULT_LABEL"
>
<!-- STUFF HERE -->
<field name="password2" type="password"
autocomplete="off"
class="validate-password"
description="COM_USERS_DESIRED_PASSWORD"
field="password1"
filter="raw"
label="COM_USERS_PROFILE_PASSWORD1_LABEL"
message="COM_USERS_PROFILE_PASSWORD1_MESSAGE"
size="30"
validate="equals"
required="true"
/>
<field name="password1" type="password"
autocomplete="off"
class="validate-password"
description="COM_USERS_PROFILE_PASSWORD2_DESC"
filter="raw"
label="COM_USERS_PROFILE_PASSWORD2_LABEL"
size="30"
validate="password"
required="true"
/>
<!-- OTHER STUFF THERE -->
</fieldset>
</form>
在libraries 文件夹中:libraries/joomla/form/fields/password.php
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see JFormField::setup()
* @since 3.2
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$return = parent::setup($element, $value, $group);
if ($return)
{
$this->maxLength = $this->element['maxlength'] ? (int) $this->element['maxlength'] : 99;
$this->threshold = $this->element['threshold'] ? (int) $this->element['threshold'] : 66;
$meter = (string) $this->element['strengthmeter'];
$this->meter = ($meter == 'true' || $meter == 'on' || $meter == '1');
}
return $return;
}
/**
* Method to get the field input markup for password.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
// Translate placeholder text
$hint = $this->translateHint ? JText::_($this->hint) : $this->hint;
// Initialize some field attributes.
$size = !empty($this->size) ? ' size="' . $this->size . '"' : '';
$maxLength = !empty($this->maxLength) ? ' maxlength="' . $this->maxLength . '"' : '';
$class = !empty($this->class) ? ' class="' . $this->class . '"' : '';
$readonly = $this->readonly ? ' readonly' : '';
$disabled = $this->disabled ? ' disabled' : '';
$required = $this->required ? ' required aria-required="true"' : '';
$hint = $hint ? ' placeholder="' . $hint . '"' : '';
$autocomplete = !$this->autocomplete ? ' autocomplete="off"' : '';
$autofocus = $this->autofocus ? ' autofocus' : '';
if ($this->meter)
{
JHtml::_('script', 'system/passwordstrength.js', true, true);
$script = 'new Form.PasswordStrength("' . $this->id . '",
{
threshold: ' . $this->threshold . ',
onUpdate: function(element, strength, threshold) {
element.set("data-passwordstrength", strength);
}
}
);';
// Load script on document load.
JFactory::getDocument()->addScriptDeclaration(
"jQuery(document).ready(function(){" . $script . "});"
);
}
// Including fallback code for HTML5 non supported browsers.
JHtml::_('jquery.framework');
JHtml::_('script', 'system/html5fallback.js', false, true);
return '<input type="password" name="' . $this->name . '" id="' . $this->id . '"' .
' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $hint . $autocomplete .
$class . $readonly . $disabled . $size . $maxLength . $required . $autofocus . ' />';
}
我想这就是你想要的。
如果您对 Joomla Jforms 不了解,请使用 jquery validation plugin。它的documentation。