Setup JForm XML form with a group + use field to validate equals:
ex:
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="example">
<field name="name" type="text" ... />
<field name="password" type="password"
autocomplete="off"
class="validate-password"
description="DESIRED_PASSWORD"
field="password"
filter="raw"
label="PASSWORD_LABEL"
size="10"
validate="password"
required="true"
/>
<field name="password2" type="password"
autocomplete="off"
class="validate-password"
description="PASSWORD2_DESC"
field="password"
filter="raw"
label="PASSWORD2_LABEL"
message="PASSWORD1_MESSAGE"
size="30"
validate="equals"
required="true"
/>
</fields>
</form>
Comparing password fields when password == password2 return true
Comparing password fields dont return true if password == password2
Joomla : 3.3.6 Stable [ Ember ] 01-October-2014 02:00 GMT
PHP : 5.5.12
Apache : 2.4.9
Group are not taked into account when comparing value of those fields
// Method to test if two values are equal. To use this rule, the form
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
{
$field = (string) $element['field'];
// Check that a validation field is set.
if (!$field)
{
throw new UnexpectedValueException(sprintf('$field empty in %s::test', get_class($this)));
}
if (is_null($form))
{
throw new InvalidArgumentException(sprintf('The value for $form must not be null in %s', get_class($this)));
}
if (is_null($input))
{
throw new InvalidArgumentException(sprintf('The value for $input must not be null in %s', get_class($this)));
}
// HERE i added conditionnal to take account of group
if(isset($group))
{
$test = $input->get($group.'.'.$field);
}
else
{
$test = $input->get($field);
}
// Test the two values against each other.
if ($value == $test)
{
return true;
}
return false;
}
Title |
|
Labels |
Added:
?
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-03-18 11:31:45 |