Name in mailform mandatory

Third Party Plugins to CMSimple - how to install, use and create plugins

Moderator: Tata

Post Reply
Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Name in mailform mandatory

Post by Tata » 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.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Name in mailform mandatory

Post by cmb » Sat Jun 01, 2019 9:45 am

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 == '') {
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Name in mailform mandatory

Post by Tata » 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.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

frase
Posts: 5085
Joined: Thu Apr 21, 2016 6:32 am
Location: Saxony
Contact:

Re: Name in mailform mandatory

Post by frase » Sat Jun 01, 2019 10:27 am

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.

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Name in mailform mandatory

Post by Tata » 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.
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"
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

frase
Posts: 5085
Joined: Thu Apr 21, 2016 6:32 am
Location: Saxony
Contact:

Re: Name in mailform mandatory

Post by frase » Sat Jun 01, 2019 10:43 am

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
Last edited by frase on Sat Jun 01, 2019 10:49 am, edited 1 time in total.

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Name in mailform mandatory

Post by Tata » Sat Jun 01, 2019 10:47 am

You were faster, I have found it and it works :) .
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Post Reply