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)
    HTML:
    <form class="xenform AutoValidator" action="{xen:link 'threads/save-thread-limit'}">
                        <dl class="threadAlerts secondaryContent">
                            <dt>
                                <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>
                                <label>
                                Auto-lock thread after 
                                <input type="text" id="MaxPosts" title="Type the maximum number of posts allowed" class="textCtrl" value="" name="txtPostLimit" size="8"> 
                                posts
                                </label>
                                <input type="submit" value="Set" class="button primary">
                            </dt>
                        </dl>
                    </form>
    
    The current controller
    PHP:
    <?php
    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($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);
                        list(
    $thread$forum) = $ftpHelper->assertThreadValidAndViewable($threadId$threadFetchOptions$forumFetchOptions);
        
                        
    $threadWriter XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
                        
    $threadWriter->setExistingData($thread['thread_id']);
                        
    $threadWriter->set('discussion_open'0);
                        
    $threadWriter->save();
        
                        
    $this->_getThreadModel()->markThreadRead($thread$forumXenForo_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);
            
    //print_r($input);
            
            
    if ($input == 0)
            {
                return 
    $this->responseError(new XenForo_Phrase('ds_autolockthreads_invalid_limit'));
                return 
    false;
            } else {
                
                
    $ftpHelper $this->getHelper('ForumThreadPost');
                
    $thread $ftpHelper->getThreadOrError($threadId);
        
                
    print_r($thread);
            
                
    //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!
    [​IMG]

    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:
    HTML:
    <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 XenForo Moderator Staff Member

    HTML:
    <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