terminal42 / contao-mailusername

MIT License
7 stars 5 forks source link

Use type="email" for username input #11

Closed richardhj closed 7 years ago

richardhj commented 8 years ago

Mobile devices (e.g. iOS) are very uncomfortable for entering a mail address in a input type="text" (automatic ucfirst, wrong keypad and so on). It would be nice to force a input type="email". I suggest:

$GLOBALS['TL_HOOKS']['parseFrontendTemplate'][] = array('MailUsername', 'alterInputType');

   /**
     * Alter the username input type
     * @category parseFrontendTemplate
     *
     * @param string $strBuffer
     * @param string $strTemplate
     *
     * @return mixed
     */
    public function alterInputType($strBuffer, $strTemplate)
    {
        if (0 !== strpos($strTemplate, 'mod_login') && 0 !== strpos($strTemplate, 'member_'))
        {
            return $strBuffer;
        }

        // Replace the type="text" with type="email" for username inputs
        return preg_replace('/(?<=input type=\")(text)(?=\" name=\"username\")/', 'email', $strBuffer);
    }

Do you approve at all? Should we check for a xhtml-template?

aschempp commented 8 years ago

I don't think that's something we should regex into the page. An email type field should first be part of Contao core so we can re-use it. I know the form generator does use set a text field to type number if regex is set to digits only, does that maybe already happen for email fields?

richardhj commented 8 years ago

The textfield widget class sets type="email" by it's rgxp too (see FormTextField@L154). Adding this rgxp to the username's dca would make it for the majority of modules. The problem with the login form is that the input type is hardcoded (see mod_login_Xcl). So, as far as I can see, the only possibility is modifying the template while parsing. Alternatively, all we can do is to make a recommendation for using a custom template.

aschempp commented 8 years ago

Maybe we should just write that into the README?

richardhj commented 8 years ago

IMO we should add the rgxp to the dca and add it to the README as the login form will not be influenced by the rgxp.

aschempp commented 7 years ago

I have update the rgxp of tl_member.username, though I don't think that will have any impact because the field is disabled anyway. I suggest you open an issue on contao/core to support this behavior in the frontend login module.