Show alert/confirmation if post is too short

From PunBB Resource Wiki

Jump to: navigation, search

Contents

What it does

This small modification adds the possibility to specify a minimum length for posts.

How to make it work

Using an alert

Find:

if (elem.type && (elem.type=="text" || elem.type=="textarea" || elem.type=="password" || elem.type=="file") && elem.value=='')
                {
                    alert("\"" + element_names[elem.name] + "\" is a required field in this form.")
                    elem.focus()
                    return false
                }

Replace with:

if(elem.type == "textarea" && elem.value.length < 8)
                {
                    alert("Your message should be at least 8 characters long!");
                    return false;
                }
                else
                {
                    if (elem.type && (elem.type=="text" || elem.type=="textarea" || elem.type=="password" || elem.type=="file") && elem.value=='')
                    {
                        alert("\"" + element_names[elem.name] + "\" <?php echo $lang_common['required field'] ?>")
                        elem.focus()
                        return false
                    }
                }

Using a confirmation box

With this, a user can still post but just gets a warning
Replace:

alert("Your message should be at least 8 characters long!");
                    return false;

With:

return confirm("Your message is shorter than 8 characers. Do you still want to submit?");
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox