Browse Source

Correção de bug para CPFs começados com dígito zero

master
Sesostris Vieira 11 years ago
parent
commit
cb8de1ba21
  1. 24
      field.class.php
  2. 1
      lang/en/profilefield_cpf.php

24
field.class.php

@ -1,38 +1,23 @@
<?php
class profile_field_cpf extends profile_field_base {
/**
* Overwrite the base class to display the data for this field
*/
function display_data() {
/// Default formatting
$data = parent::display_data();
$data = str_pad($data, 11, '0', STR_PAD_LEFT); // Prevent low digits formatting errors
if ($data !== '') {
$data = substr($data,0,3).'.'.substr($data,3,3).'.'.substr($data,6,3).'-'.substr($data,9,2);
}
/*
/// Are we creating a link?
if (!empty($this->field->param4) and !empty($data)) {
/// Define the target
if (! empty($this->field->param5)) {
$target = 'target="'.$this->field->param5.'"';
} else {
$target = '';
}
/// Create the link
$data = '<a href="'.str_replace('$$', urlencode($data), $this->field->param4).'" '.$target.'>'.htmlspecialchars($data).'</a>';
}
*/
return $data;
}
function edit_field_add($mform) {
/// Create the form field
$mform->addElement('text', $this->inputname, format_string($this->field->name), 'maxlength="11" size="11"');
$mform->setType($this->inputname, PARAM_INT);
$mform->setType($this->inputname, PARAM_TEXT);
}
function edit_validate_field($usernew) {
@ -40,6 +25,9 @@ class profile_field_cpf extends profile_field_base {
$errors = array();
if (isset($usernew->{$this->inputname})) {
$cpf = $usernew->{$this->inputname};
if (ctype_digit($cpf)) {
return array($this->inputname => get_string('cpf_digits', 'profilefield_cpf'));
}
if (strlen($cpf) != 11) {
return array($this->inputname => get_string('cpf_size', 'profilefield_cpf'));
}
@ -62,5 +50,3 @@ class profile_field_cpf extends profile_field_base {
}
}

1
lang/en/profilefield_cpf.php

@ -24,5 +24,6 @@
*/
$string['pluginname'] = 'Brazilian CPF';
$string['cpf_digits'] = 'CPF must have only numeric digits';
$string['cpf_size'] = 'CPF must have 11 digits';
$string['cpf_invalid'] = 'Invalid CPF';

Loading…
Cancel
Save