AJAX post is not getting thread ID!


Active member
Hello, it's me again, with my Auto Locker Threads add-on problems :whistle:

I had progressed really nice so far, with the help I found here. Thank you!

But now, while I am learning things, I can not find a way to get the thread ID using the methods I already know :(

Here is all my things so far:

The Template (ds_thread_limit_edit)
<form class="xenform AutoValidator" action="{xen:link 'threads/save-thread-limit'}">
                    <dl class="threadAlerts secondaryContent">
                            <span class="locked_icon" style="background: url(@imagePath/xenforo/icons/locked.png) no-repeat center; width:16px; height:16px; margin: 3px 3px 0 0; display:block; float:left;"></span>
                            Auto-lock thread after 
                            <input type="text" id="MaxPosts" title="Type the maximum number of posts allowed" class="textCtrl" value="" name="txtPostLimit" size="8"> 
                            <input type="submit" value="Set" class="button primary">
The current controller
class DS_AutoLockThreads_ControllerPublic_AutoLockThreads extends XFCP_DS_AutoLockThreads_ControllerPublic_AutoLockThreads
    public function actionAddReply()
        //Rewritten by Syndol
        $redirect = parent::actionAddReply();
            $threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);
            $options = XenForo_Application::get('options');
            //getting an array of thread IDs to look for
            if (in_array($threadId, explode(',', $options->threadId)));
                $postModel = $this->_getPostModel();
                $numPosts = $postModel->countVisiblePostsInThread($threadId);
                if ($numPosts >= $options->maxPosts)
                    $visitorId = XenForo_Visitor::getUserId();
                    $ftpHelper = $this->getHelper('ForumThreadPost');
                    $threadFetchOptions = array('readUserId' => $visitorId);
                    $forumFetchOptions = array('readUserId' => $visitorId);
                    list($thread, $forum) = $ftpHelper->assertThreadValidAndViewable($threadId, $threadFetchOptions, $forumFetchOptions);
                    $threadWriter = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
                    $threadWriter->set('discussion_open', 0);
                    $this->_getThreadModel()->markThreadRead($thread, $forum, XenForo_Application::$time, $visitorId);
            return $redirect;
    public function actionSaveThreadLimit(){
        $this->_assertPostOnly(); //check if it is a POST response
        $threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);
        echo $threadId;
        //filtering, so we get an UINT
        $input = $this->_input->filterSingle('txtPostLimit',XenForo_Input::UINT);
        if ($input == 0)
            return $this->responseError(new XenForo_Phrase('ds_autolockthreads_invalid_limit'));
            return false;
        } else {
            $ftpHelper = $this->getHelper('ForumThreadPost');
            $thread = $ftpHelper->getThreadOrError($threadId);
            //we have a limit, so let's set that field on the Thread table
//            $threadWriter = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
//            $threadWriter->setExistingData($thread['thread_id']);
//            $threadWriter->set('post_limit', $input);
//            $threadWriter->save();
//            return $this->responseMessage(new XenForo_Phrase('ds_autolockthreads_limit_success'));

the actionAddReply() gets the ID, even though it uses AJAX too on the QuickReply, while my custom method, actionSaveThreadLimit() doesn't get it, and I am using the same call!

Oh, that is how the template renders. It's neat!

So, please help me :)


Hi again,

You need to include the thread id in your template as a hidden value for the form:
<input type="hidden" name="thread_id" value="{$thread.thread_id}">


Well-known member
Hehe, saving me again, Syndol :D

But can you explain why the QuickReply works then?
<span class="HiddenInput" data-name="content_data[thread_id]" data-value="19020"></span>
Not sure why <input type="hidden" wasn't used, but that is within the form.


Active member
Oh, thank you for telling me. Probably some JS pops that on the posted content. Well, that is working now, so thank you for the help for now.