dokuwiki-plugin-bureaucracy icon indicating copy to clipboard operation
dokuwiki-plugin-bureaucracy copied to clipboard

Improve e-mail field validation by trimming ( trim() ) the value

Open gianfrus opened this issue 5 years ago • 0 comments

Hi. Users that submit data through a form implemented by the Bureaucracy plugin often complain about an e-mail field malfunction (expecially when they use smartphones filling the form).

Further investigation reveals that often they inadvertently add spaces at the end of the e-mail address string just typed in the field.

Although correct in principle (there's no reason to add spaces at the begin or the end of an e-mail address string) it could be a good idea, to improve the smartness of the code, trimming away such spaces from the e-mail address value just before the validation step.

To get it I added the following line of code in bureaucracy/fields/email.php:

<?php
require_once DOKU_PLUGIN . 'bureaucracy/fields/textbox.php';
class syntax_plugin_bureaucracy_field_email extends syntax_plugin_bureaucracy_field_textbox {

    function _validate() {
        parent::_validate();

        $value = $this->getParam('value');
        $value = is_null($value) ? NULL : trim($value); //***LINE ADDED***.
        if(!is_null($value) && !mail_isvalid($value)){
            throw new Exception(sprintf($this->getLang('e_email'),hsc($this->getParam('label'))));
        }
    }
}

gianfrus avatar Nov 02 '19 17:11 gianfrus