1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

AJAX post is not getting thread ID!

Discussion in 'XenForo Development Discussions' started by DarkSign, Aug 19, 2011.

  1. DarkSign

    DarkSign 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 
    //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($threadIdexplode(','$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);
    $thread$forum) = $ftpHelper->assertThreadValidAndViewable($threadId$threadFetchOptions$forumFetchOptions);
    $threadWriter XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
        public function 
    $this->_assertPostOnly(); //check if it is a POST response
    $threadId $this->_input->filterSingle('thread_id'XenForo_Input::UINT);
    //filtering, so we get an UINT
    $input $this->_input->filterSingle('txtPostLimit',XenForo_Input::UINT);
    if ($input == 0)
    $this->responseError(new XenForo_Phrase('ds_autolockthreads_invalid_limit'));
            } 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 :)
  2. Syndol

    Syndol Guest

    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}">
  3. DarkSign

    DarkSign Active Member

    Hehe, saving me again, Syndol :D

    But can you explain why the QuickReply works then?
  4. Jeremy

    Jeremy Well-Known Member

    <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.
  5. DarkSign

    DarkSign 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.

Share This Page