MyBB Community Forums

Full Version: maxlenght conditional check
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please help, How to check if the maxlenght has the correct value before submitting?

I set maxlenght="50" but people will use Firebug to modify that so I want to some how maybe with conditional template check if the input value is not more that 50?
Well, you would have to check it serverside (with PHP, strlen on $mybb->input['xxx'] or whatever) and throw error if it's too long, maxlength isn't even supported in IE < 8.. Can't do it with Template Conditionals, need plugin/core modification. Neither can it be done with XThreads @down.
This is the line I want to restrict to max 50 characters
<input type="text" class="textbox" name="subject" size="40" maxlength="50" value="{$subject}" tabindex="1" />

Can I do it with xthreads?


Can I use something like this for conditional?
if($subject_length > 50)
        {
            // Subject is too long
            $this->set_error('subject_too_long', my_strlen($subject));
            return false;
        }
The easiest way would be to edit inc/datahandlers/post.php

if($subject_length > 85)
		{
			// Subject is too long
			$this->set_error('subject_too_long', my_strlen($subject));
			return false;
		}
Change 85 to your value.
Destroy do you know if I can do it with JavaScript form validate? Any good JavaScript code that will work with all the browsers?