Help with limiting textarea characters

The web video script that I’m using allowed me to limit the text area characters in it by adding ‘maxlength’, like so, to the upload form on the html page:

<textarea name="description" id="description" maxlength="100" cols="30" rows="5" class="form-control"></textarea>

but now that the web video script has been updated to a new version. The new updated line of code is:

<textarea name="description" id="description" cols="30" rows="5" class="form-control description"></textarea>

and when I added in the maxlength=“100” it doesn’t affect the textarea.

So, I asked the script developer how to limit the charcters in the text area, his reply was:
“You will have to add validation check for that on your own within ./ajax/ for concerning ajax request”

I don’t know how to do that.

The corresponding file in the ajax folder is this:

<?php 
if (IS_LOGGED == false || $pt->config->upload_system != 'on') {
    $data = array('status' => 400, 'error' => 'Not logged in');
    echo json_encode($data);
    exit();
}
if ($pt->user->suspend_upload) {
    $data = array('status' => 400);
    echo json_encode($data);
    exit();
}

if (!empty($_FILES['video']['tmp_name'])) {
    if ($pt->config->shorts_system == 'on' && !empty($_POST['is_short']) && $_POST['is_short'] == 'yes') {
        try {
            $getID3   = new getID3;
            $file     = $getID3->analyze($_FILES['video']['tmp_name']);
            if (!empty($file) && !empty($file['playtime_seconds']) && $file['playtime_seconds'] > $pt->config->shorts_duration) {
                $data = array('status' => 402,'message' => str_replace('{D}', $pt->config->shorts_duration, $pt->all_lang->max_video_duration));
                echo json_encode($data);
                exit();
            }
        } catch (Exception $e) {
            $data = array('status' => 402,'message' => $e->getMessage());
            echo json_encode($data);
            exit();
        }
    }
    if (!PT_IsAdmin()) {
        if ($pt->user->user_upload_limit != '0') {
            if ($pt->user->user_upload_limit != 'unlimited') {
                if (($pt->user->uploads + $_FILES['video']['size']) >= $pt->user->user_upload_limit) {
                    $max  = pt_size_format($pt->user->user_upload_limit);
                    $data = array('status' => 402,'message' => ($lang->file_is_too_big .": $max"));
                    echo json_encode($data);
                    exit();
                }
            }
        }
        else{
            if ($pt->config->upload_system_type == '0') {
                if ($pt->config->max_upload_all_users != '0' && ($pt->user->uploads + $_FILES['video']['size']) >= $pt->config->max_upload_all_users) {
                    $max  = pt_size_format($pt->config->max_upload_all_users);
                    $data = array('status' => 402,'message' => ($lang->file_is_too_big .": $max"));
                    echo json_encode($data);
                    exit();
                }
            }
            elseif ($pt->config->upload_system_type == '1') {
                if ($pt->user->is_pro == '0' && ($pt->user->uploads + $_FILES['video']['size']) >= $pt->config->max_upload_free_users && $pt->config->max_upload_free_users != 0) {
                    $max  = pt_size_format($pt->config->max_upload_free_users);
                    $data = array('status' => 402,'message' => ($lang->file_is_too_big .": $max"));
                    echo json_encode($data);
                    exit();
                }
                elseif ($pt->user->is_pro > '0' && ($pt->user->uploads + $_FILES['video']['size']) >= $pt->config->max_upload_pro_users && $pt->config->max_upload_pro_users != 0) {
                    $max  = pt_size_format($pt->config->max_upload_pro_users);
                    $data = array('status' => 402,'message' => ($lang->file_is_too_big .": $max"));
                    echo json_encode($data);
                    exit();
                }
            }
        }
    }

    $allowed           = 'mp4,mov,webm,mpeg';

    $new_string        = pathinfo($_FILES['video']['name'], PATHINFO_FILENAME) . '.' . strtolower(pathinfo($_FILES['video']['name'], PATHINFO_EXTENSION));
    $extension_allowed = explode(',', $allowed);
    $file_extension    = pathinfo($new_string, PATHINFO_EXTENSION);
    if (!in_array($file_extension, $extension_allowed)) {
        $data = array('status' => 400, 'error' => $lang->file_not_supported);
        echo json_encode($data);
        exit();
    }

	$file_info = array(
        'file' => $_FILES['video']['tmp_name'],
        'size' => $_FILES['video']['size'],
        'name' => $_FILES['video']['name'],
        'type' => $_FILES['video']['type'],
        'allowed' => 'mp4,mov,webm,mpeg'
    );
    $pt->config->s3_upload = 'off';
    $pt->config->wasabi_storage = 'off';
    $pt->config->ftp_upload = 'off';
    $pt->config->spaces = 'off';
    $file_upload = PT_ShareFile($file_info);
    if (!empty($file_upload['filename'])) {
        $explode3  = @explode('.', $file_upload['name']);
        $file_upload['name'] = $explode3[0];
    	$data   = array('status' => 200, 'file_path' => $file_upload['filename'], 'file_name' => $file_upload['name']);
        $update = array('uploads' => ($pt->user->uploads += $file_info['size']));
        $db->where('id',$pt->user->id)->update(T_USERS,$update);
        $data['uploaded_id'] = $db->insert(T_UPLOADED,array('user_id' => $pt->user->id,
                                                            'path' => $file_upload['filename'],
                                                            'time' => time()));

    } 

    else if (!empty($file_upload['error'])) {
        $data = array('status' => 400, 'error' => $file_upload['error']);
    }
}
?>

Any help or suggestion is appreciated.

That makes no sense. Adding a class should not break a maxlength attribute. Did some JS code get added which targets the form-control or description classes that perhaps removes the maxlength attribute (which would be kind of dumb, but whatever…)

Thanks for your reply.
It made me look at the JS, and yes this was added:

  var el = $(".description").emojioneArea({
      pickerPosition: "bottom",
       tonesStyle: "radio",
       events: {
         keyup: function (editor, event) {
          }
       },
       filters: {
           flags : false,
           objects : false,
           travel_places : false,
           activity : false
       }
   });
   var el2 = $(".move_description").emojioneArea({
      pickerPosition: "bottom",
       tonesStyle: "radio",
       events: {
         keyup: function (editor, event) {
          }
       },
       filters: {
           flags : false,
           objects : false,
           travel_places : false,
           activity : false
       }
  });

and when it’s commented-out, the maxlength is successful.

So, is there a way to have both the emoji’s and the max length?

I look forward to any additional suggestions.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.