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

Help Developement

#1
Hello,

how to error ? I développed a add-ons. a formulaire post in the thread.

Code:
Server Error

A discussion insert was attempted without the required first message.

    XenForo_DataWriter_Discussion->_preSave() in XenForo/DataWriter.php at line 1460
    XenForo_DataWriter->preSave() in NextBrain/Formulaire/Model/Thread.php at line 17
    NextBrain_Formulaire_Model_Thread::formThread() in NextBrain/Formulaire/ControllerPublic/Form.php at line 30
    NextBrain_Formulaire_ControllerPublic_Form->actionIndex() in XenForo/FrontController.php at line 351
    XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
    XenForo_FrontController->run() in C:/wamp/www/XenForo.v1.5.6.Full/upload/index.php at line 13
sorry, I do not speak well english
 

wang

Well-known member
#2
It is difficult to know what is causing the error without seeing the code.
 
Last edited:
#3
Sorry,

Code ControllerPublic :

PHP:
<?php

class NextBrain_Formulaire_ControllerPublic_Form extends XenForo_ControllerPublic_Abstract
{
    public function actionIndex()
    {
        $visitor = XenForo_Visitor::getInstance();
        if(!$visitor->hasPermission('re_form', 'nb_view_formulaire'))
        {
            return $this->responseNoPermission();
        }

        if(!empty($_POST))
        {
            if(!empty($_POST['username'] && !empty($_POST['msg_compt']) && !empty($_POST['msg_moti']) && !empty($_POST['msg_pkv'])))
            {
                $user_id = $visitor->get('user_id');
                $username = $visitor->get('username');
                $options = XenForo_Application::get('options');
                $thread = $options->id_thread;
                $title = $options->title;
                $titles = str_replace('{name}', $username, $title);
                $data = $this->_input->filter(array(
                    'username' => XenForo_Input::STRING,
                    'msg_compt' => XenForo_Input::STRING,
                    'msg_moti' => XenForo_Input::STRING,
                    'msg_kvl' => XenForo_Input::STRING
                ));
               
                NextBrain_Formulaire_Model_Thread::formThread($username, $thread, $titles, $data, $user_id);
            }
            else
            {

            }


        }

        return $this->responseView('NextBrain_Formulaire_ViewPublic_Form', 'nb_formulaire');
    }
Code Datawriter :

PHP:
<?php

class NextBrain_Formulaire_Model_Thread {
   
    static function formThread($user,$forum, $subject, $msg, $user_id)
    {
        $threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');

        $msgs = 'test';
       
        $threadDw->set('user_id', $user_id);
        $threadDw->set('username', $user);
        $threadDw->set('title', $subject);
        $threadDw->set('message', $msgs);
        $threadDw->set('node_id', $forum);
       
        $threadDw->save();
       
        return $threadDw->getMergedData();
       
    }
}