Page 1 of 1

Name in mailform mandatory

Posted: Fri May 31, 2019 7:52 pm
by Tata
How can I make the sender's name in standard CMSimple_XH mailform mandatory?
There is only the sender's email, the message and the captcha mandatory.

Re: Name in mailform mandatory

Posted: Sat Jun 01, 2019 9:45 am
by cmb
Tata wrote:
Fri May 31, 2019 7:52 pm
How can I make the sender's name in standard CMSimple_XH mailform mandatory?
There is only the sender's email, the message and the captcha mandatory.
Basically you can replace this line with:

Code: Select all

        if (!$this->mail->isValidAddress($this->sender) || $this->subject == '' || $this->sendername == '') {

Re: Name in mailform mandatory

Posted: Sat Jun 01, 2019 10:11 am
by Tata
One more thing.
The Email and the Subject fields go red framed on Submit if empty. Where is this defined? If the Name field is empty, the warning is there on submit, but the field is not red framed. No big problem, but anyway, the uniformity would be better.

Re: Name in mailform mandatory

Posted: Sat Jun 01, 2019 10:27 am
by frase
Tata wrote:
Sat Jun 01, 2019 10:11 am
One more thing.
The Email and the Subject fields go red framed on Submit if empty. Where is this defined? If the Name field is empty, the warning is there on submit, but the field is not red framed. No big problem, but anyway, the uniformity would be better.
The red frame is set by the browser when the field is "required" and empty or has a wrong entry.
If the field is not "required", the system does not check it and does not output a message.

Re: Name in mailform mandatory

Posted: Sat Jun 01, 2019 10:37 am
by Tata
That's known. But how to tell the browser, that this field is mandatory? I have changed the line as cmb wrote. But the field seems to be ignored by the browser, anyway.
EDIT:
Hopefully found (required="required"):

Code: Select all

        $o .= '<div>' . "\n" . '<label for="xh_mailform_sendername">'
            . $tx['mailform']['sendername'] . '</label>' . '<br>' . "\n"
            . '<input type="text" class="text" size="35" name="sendername"'
            . ' id="xh_mailform_sendername" value="'
            . XH_hsc($this->sendername).'" required="required">' . "\n"

Re: Name in mailform mandatory

Posted: Sat Jun 01, 2019 10:43 am
by frase
Tata wrote:
Sat Jun 01, 2019 10:37 am
That's known. But how to tell the browser, that this field is mandatory? I have changed the line as cmb wrote. But the field seems to be ignored by the browser, anyway.
This line at the end extend with the red word:
XH_hsc($this->sendername).'" required>' . "\n"

(Untested)
(But - just tested. Seems to be working.)

:D you were faster

Re: Name in mailform mandatory

Posted: Sat Jun 01, 2019 10:47 am
by Tata
You were faster, I have found it and it works :) .