Forums

Form Output --> Fireboard Topic

Azzy_p 27 Nov, 2008
Hi, I've had a good look around the internet and have found a couple of topics on these forums about making the output from ChronoForms create a paste into a topic in a certain category within a FireBoard Forum.

I have managed to get the form to create a topic (using the correct user) with the correct topic subject, but when I cannot get the message (which will show the data input into the form) to show up. Also fireboard doesn't recognise there being a new post, nor does it show the post as even existing on the main forum page. What I mean by that if i didn't make it clear is when you are on the main forum page, if you scroll down to "Applications" where the form places all of its submissions, fireboard shows there as being NO topics.. even though when you click it there are topics in there.

Here is my code which I copied and edited from another topic on this forum:

 <?php
    // :: Remove all this Joomla will handle it for you
    // $db_host = "knightsoftheroseguild.com";
    // $db_user = "xxxxxx";
    // $db_pwd = "xxxxxx";
    // $db_name = "joomla";
    // mysql_connect($db_host, $db_user, $db_pwd);
    // mysql_select_db($db_name);
    // :: here's now you call the database

   global $mainframe;
   $database =& JFactory::getDBO();

    // :: set some variables that may need to be changed
    $catid = 67;
    $userid = 71;
    $author = "Application Form";
    $fieldname = 'field_name';


    $subject = $_POST['char_name']." New Application Form! ".$_POST['class'];
    $date = strtotime("now");

    // $_POST['armory'] = "[URL=".$_POST['armory']."]LINK[/URL]";
    $_POST[$fieldname] = "[url=".$_POST[$fieldname]."]LINK[/url]";

    foreach($_POST as $key => $value) {
        // capitalize the first letter of each field
        $key = ucfirst($key);

        //make the title bold
        $key = "".$key."";

        //make it part of the msg string
        $msg = "$msg $key : $value";
    }

    // get rid of the submit button bit at the end
    $msg_array = explode("[b]Button", $msg);
    $msg = $msg_array[0];
    /* $msg = substr($msg, 0, -3); */

    // Because I'm lazy ...
    // :: I'm not sure this is correct - needs testing
    $msg = str_replace("\n","\n\n",$msg);

    // Create the new topic
    $sql = "
        INSERT
            INTO #__fb_messages
            SET id=NULL, parent=0, thread=0, catid=$catid,
            name='$author', userid=$userid, email=NULL,
            subject='$subject', time=$date, ip=NULL";
    $database->setQuery($sql);
    if ( !$database->query() ) {
        echo "<script> alert('".$database->getErrorMsg()."');
           window.history.go(-1); </script>";
    }

    // Figure out what the correct threadid is of that new topic
    $mesid = $database->insertid;

    // Set the thread id to the same as the message id,
    // as it's the first in the thread
    // Note: this solves the order problem in the forum
    $sql = "
        UPDATE #__fb_messages
            SET thread=id
            WHERE id=$mesid";
    $database->setQuery($sql);
    if ( !$database->query() ) {
        echo "<script> alert('".$database->getErrorMsg()."');
           window.history.go(-1); </script>";
    }   

    // Tell the forum that there's a new latest message
    // Note: this solves the problem where the new message
    // isn't showing up as the latest message in the forum
    // Note: it's the categories table because FB sees
    // categories and forums as the same thing
    $sql = "
        UPDATE #__fb_categories
            SET id_last_msg=$mesid
            WHERE id=$catid";
    $database->setQuery($sql);
    if ( !$database->query() ) {
        echo "<script> alert('".$database->getErrorMsg()."');
           window.history.go(-1); </script>";
    } 

    // Stick the $msg variable into the body of the topic
    $sql = "
        INSERT INTO #__fb_messages_text
            SET mesid=$mesid, message='This is a test, used to be dollarmsg.'";
    $database->setQuery($sql);
    if ( !$database->query() ) {
        echo "<script> alert('".$database->getErrorMsg()."');
           window.history.go(-1); </script>";
    }
    ?>


So I was wondering if anyone could help me make the message show up in the forum, and make the forum realise that there is new topics in there.

I am using Joomla 1.5.7, ChronoForms 3.0 (STABLE) and Fireboard 1.0.5RC2.

Thanks,

Arron
Max_admin 27 Nov, 2008
Hi Arron,

I think you need to run some synchronize process on posts in the forums admin area or somewhere, or make sure that you are updating ALL the necessary tables ? the same happens when you restore some posts to the phpBB!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Azzy_p 28 Nov, 2008
Thanks Max!

Okay, the forum now does update to tell people that there is a new topic etc, but I still cant get the contents of the form to show up in the post. It just creates an empty topic with nothing in the body.

Any ideas?

Thanks,

Arron
Max_admin 28 Nov, 2008
hmmm, i think something may be wrong here:

$sql = "
        INSERT INTO #__fb_messages_text
            SET mesid=$mesid, message='This is a test, used to be dollarmsg.'";
    $database->setQuery($sql);


don't use the
 echo "<script> alert('".$database->getErrorMsg()."');
           window.history.go(-1); </script>";
for showing errors in J1.5 too, sometimes it doesn't work, use the JERROR class instead:
JError::raiseWarning(100, $database->getErrorMsg());


Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Azzy_p 01 Dec, 2008
Thanks again forthe reply max!

Okay, now i have fixed that error reporting problem, when I submit the form this is the error joomla gives me:

[code]

* You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 SQL=UPDATE rapple_fb_messages SET thread=id WHERE id=
* You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id=67' at line 3 SQL=UPDATE rapple_fb_categories SET id_last_msg= WHERE id=67
* You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' message=' Text_2 : Arron Text_3 : Azzy Text_4 : azzyp [b]S' at line 2 SQL=INSERT INTO rapple_fb_messages_text SET mesid=, message=' [b]Text_2[/b] :test [b]Text_3[/b] : test [b]Text_4[/b] : test Select_7 : 18 Call_Of_Duty:_World_At_War : Call Of Duty: World At War Call_Of_Duty_4:_Modern_Warfare : Call Of Duty 4: Modern Warfare Crysis : Crysis Select_11 : Maybe Text_12 : test Text_14 : test Text_15 : test Undefined : Apply Now! D945ef2e85e36815b6fd71c1f4bbe443 : 1 Field_name : LINK'

[/code]
GreyHead 01 Dec, 2008
Hi Azzy_p,

This looks like a couple of prblems both connected with badly quoted SQL. Most likely id=67 should be id='67' or id=`67`

I'd suggest that you use the Joomla quoting function here:
$sql = "
    INSERT 
        INTO #__fb_messages_text
        SET mesid=".$database->Quote($mesid).", 
            message=".$database->Quote('This is a test, used to be dollarmsg.').";";
 $database->setQuery($sql);

Bob
Azzy_p 01 Dec, 2008
Hey, thanks!๐Ÿ™‚

Okay, that's reduced the amount of errors, I now only get these errors:



        * You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 SQL=UPDATE rapple_fb_messages SET thread=id WHERE id=
        * You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id=67' at line 3 SQL=UPDATE rapple_fb_categories SET id_last_msg= WHERE id=67
        * Duplicate entry '0' for key 1 SQL=INSERT INTO rapple_fb_messages_text SET mesid='', message='$msg';



This is now how my code looks:

 <?php
    // :: Remove all this Joomla will handle it for you
    // $db_host = "knightsoftheroseguild.com";
    // $db_user = "xxxxxx";
    // $db_pwd = "xxxxxx";
    // $db_name = "joomla";
    // mysql_connect($db_host, $db_user, $db_pwd);
    // mysql_select_db($db_name);
    // :: here's now you call the database

   global $mainframe;
   $database =& JFactory::getDBO();

    // :: set some variables that may need to be changed
    $catid = '67';
    $userid = '71';
    $author = "Application Form";
    $fieldname = 'field_name';


    $subject = $_POST['char_name']." New Application Form! ".$_POST['class'];
    $date = strtotime("now");

    // $_POST['armory'] = "[URL=".$_POST['armory']."]LINK[/URL]";
    $_POST[$fieldname] = "[url=".$_POST[$fieldname]."]LINK[/url]";

    foreach($_POST as $key => $value) {
        // capitalize the first letter of each field
        $key = ucfirst($key);

        //make the title bold
        $key = "".$key."";

        //make it part of the msg string
        $msg = "$msg $key : $value";
    }

    // get rid of the submit button bit at the end
    $msg_array = explode("[b]Button", $msg);
    $msg = $msg_array[0];
    /* $msg = substr($msg, 0, -3); */

    // Because I'm lazy ...
    // :: I'm not sure this is correct - needs testing
    $msg = str_replace("\n","\n\n",$msg);

    // Create the new topic
    $sql = "
        INSERT
            INTO #__fb_messages
            SET id=NULL, parent=0, thread=0, catid=$catid,
            name='$author', userid=$userid, email=NULL,
            subject='$subject', time=$date, ip=NULL";
    $database->setQuery($sql);
    if ( !$database->query() ) {
  JError::raiseWarning(100, $database->getErrorMsg());
    }

    // Figure out what the correct threadid is of that new topic
    $mesid = $database->insertid;

    // Set the thread id to the same as the message id,
    // as it's the first in the thread
    // Note: this solves the order problem in the forum
    $sql = "
        UPDATE #__fb_messages
            SET thread=id
            WHERE id=$mesid";
    $database->setQuery($sql);
    if ( !$database->query() ) {
       JError::raiseWarning(100, $database->getErrorMsg());
    }   

    // Tell the forum that there's a new latest message
    // Note: this solves the problem where the new message
    // isn't showing up as the latest message in the forum
    // Note: it's the categories table because FB sees
    // categories and forums as the same thing
    $sql = "
        UPDATE #__fb_categories
            SET id_last_msg=$mesid
            WHERE id=$catid";
    $database->setQuery($sql);
    if ( !$database->query() ) {
        JError::raiseWarning(100, $database->getErrorMsg());
             } 

    // Stick the $msg variable into the body of the topic
    $sql = "
        INSERT
            INTO #__fb_messages_text
            SET mesid=".$database->Quote($mesid).",
                message=".$database->Quote('$msg').";";
    $database->setQuery($sql);
    if ( !$database->query() ) {
        JError::raiseWarning(100, $database->getErrorMsg());
    }
    ?>


Thanks for all your help everyone by the way, much appreciated! Just need to get this job finished off by next monday๐Ÿ˜‘

Thanks,

Arron
GreyHead 01 Dec, 2008
Hi Azzy_p,

Now go through and quote all the other variable values - and then check them For example
$database->Quote('$msg')
won't work with the quotes inside the brackets, shoudl be
$database->Quote($msg)

Bob
Azzy_p 01 Dec, 2008
Thanks bob, I've gone through and removed any quotes from anything within brackets:


    <?php
    // :: Remove all this Joomla will handle it for you
    // $db_host = "knightsoftheroseguild.com";
    // $db_user = "xxxxxx";
    // $db_pwd = "xxxxxx";
    // $db_name = "joomla";
    // mysql_connect($db_host, $db_user, $db_pwd);
    // mysql_select_db($db_name);
    // :: here's now you call the database

   global $mainframe;
   $database =& JFactory::getDBO();

    // :: set some variables that may need to be changed
    $catid = '67';
    $userid = '71';
    $author = "Application Form";
    $fieldname = 'field_name';


    $subject = $_POST['char_name']." New Application Form! ".$_POST['class'];
    $date = strtotime("now");

    // $_POST['armory'] = "[URL=".$_POST['armory']."]LINK[/URL]";
    $_POST[$fieldname] = "[url=".$_POST[$fieldname]."]LINK[/url]";

    foreach($_POST as $key => $value) {
        // capitalize the first letter of each field
        $key = ucfirst($key);

        //make the title bold
        $key = "".$key."";

        //make it part of the msg string
        $msg = "$msg $key : $value";
    }

    // get rid of the submit button bit at the end
    $msg_array = explode("[b]Button", $msg);
    $msg = $msg_array[0];
    /* $msg = substr($msg, 0, -3); */

    // Because I'm lazy ...
    // :: I'm not sure this is correct - needs testing
    $msg = str_replace("\n","\n\n",$msg);

    // Create the new topic
    $sql = "
        INSERT
            INTO #__fb_messages
            SET id=NULL, parent=0, thread=0, catid=$catid,
            name='$author', userid=$userid, email=NULL,
            subject='$subject', time=$date, ip=NULL";
    $database->setQuery($sql);
    if ( !$database->query() ) {
  JError::raiseWarning(100, $database->getErrorMsg());
    }

    // Figure out what the correct threadid is of that new topic
    $mesid = $database->insertid;

    // Set the thread id to the same as the message id,
    // as it's the first in the thread
    // Note: this solves the order problem in the forum
    $sql = "
        UPDATE #__fb_messages
            SET thread=id
            WHERE id=$mesid";
    $database->setQuery($sql);
    if ( !$database->query() ) {
       JError::raiseWarning(100, $database->getErrorMsg());
    }   

    // Tell the forum that there's a new latest message
    // Note: this solves the problem where the new message
    // isn't showing up as the latest message in the forum
    // Note: it's the categories table because FB sees
    // categories and forums as the same thing
    $sql = "
        UPDATE #__fb_categories
            SET id_last_msg=$mesid
            WHERE id=$catid";
    $database->setQuery($sql);
    if ( !$database->query() ) {
        JError::raiseWarning(100, $database->getErrorMsg());
             } 

    // Stick the $msg variable into the body of the topic
    $sql = "
        INSERT
            INTO #__fb_messages_text
            SET mesid=".$database->Quote($mesid).",
                message=".$database->Quote($msg).";";
    $database->setQuery($sql);
    if ( !$database->query() ) {
        JError::raiseWarning(100, $database->getErrorMsg());
    }
    ?>


However I still can't get the message to appear in the forum, these are the errors:



        * You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 SQL=UPDATE rapple_fb_messages SET thread=id WHERE id=
        * You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id=67' at line 3 SQL=UPDATE rapple_fb_categories SET id_last_msg= WHERE id=67
        * Duplicate entry '0' for key 1 SQL=INSERT INTO rapple_fb_messages_text SET mesid='', message=' Text_2 : Test Text_3 : test Text_4 : Test Select_7 : 16 Call_Of_Duty:_World_At_War : Call Of Duty: World At War Crysis : Crysis Select_11 : No Text_12 : tset Text_14 : test Text_15 : test Undefined : Apply Now! D945ef2e85e36815b6fd71c1f4bbe443 : 1 Field_name : LINK';



Again, thanks, I'm (as you can probably tell) new to all this. I have done coding previously (C++) but obviously everything is slightly different๐Ÿ™‚

Arron
GreyHead 01 Dec, 2008
Hi Azzy_p,

You don't appear to understand what you are doing here - randomly removing quotes will just get you into a bigger mess. Here's the SQL snippet that appears to be giving you one error:
    $sql = "
        UPDATE #__fb_messages
            SET thread=id
            WHERE id=$mesid";
None of this is correctly quoted. Please go back and look at my earlier posts.

Bob
Azzy_p 02 Dec, 2008
Okay, thanks. I've understood what you said and have managed to minimize everything to only one error,

Duplicate entry '0' for key 1 SQL=INSERT INTO rapple_fb_messages_text SET mesid='', message=' Text_2 : Az Text_3 : azaz Text_4 : azazaz Select_7 : 18 Call_Of_Duty:_World_At_War : Call Of Duty: World At War Crysis : Crysis Select_11 : No Text_12 : asfasda Text_14 : asdasd Text_15 : asdasd Undefined : Apply Now! 2e5cb7642ff06209ab864f4ce274faeb : 1 Field_name : LINK';


This one i really don't know what its about. And yeah I don't know what i'm doing here really, but i appreciate the help.

Thanks again, and sorry to take up so much of your time๐Ÿ˜Ÿ

Arron
GreyHead 02 Dec, 2008
Hi Azzy_p,

That makes sense - though there's still something wrong! The SQL here:
SQL=INSERT INTO rapple_fb_messages_text SET mesid=''
is trying to insert a message with *no* mesid, my guess is that the mesid then defaults to '0' but there's already a record with a mesid of 0.

If the mesid is a unique identifier then you wouldn't usually SET it, what happens if you just omit that and put [code]INSERT INTO rapple_fb_messages_text SET message=' Text_2 : Az Text_3 : azaz Text_4 : azazaz [b . . .[/code]

Bob
Azzy_p 02 Dec, 2008
Okay, this is interesting.. I removed the mesid and instead just put SET message='[b]Text_2[.....

Now I don't get an errors, but the form doesn't even create a topic in the forum anymore :/

This is confusing, lol!

Thanks again,

Arron

EDIT: just re-checked my code and i had a typo in thereface-meh-blank

corrected it now and i get the same error message about duplicate entries ๐Ÿ˜Ÿ
GreyHead 02 Dec, 2008
Hi Azzy_p,

Hmmm . . . It looks as though some other setting needs to be updated with the new message id. I'd have to go digging in FireBoard to find out what though.

Bob
Azzy_p 02 Dec, 2008
Ah okay, no problem. Thanks for all your help!๐Ÿ™‚
GreyHead 02 Dec, 2008
Hi Azzy_p,

The FireBoard code in template/default/post.php is pretty complex but it looks as if they get the post id first with $database->insertId();
. . .
$database->setQuery("INSERT INTO #__fb_messages 
    (parent,thread,catid,name,userid,email,subject,time,ip,topic_emoticon,hold)
    VALUES('$parent','$thread','$catid','$fb_authorname','{$my->id}', '$email','$subject','$posttime','$ip','$topic_emoticon','$holdPost')");
if ($database->query()) {
    $pid = $database->insertId();
    // now increase the #s in categories only case approved
    if($holdPost==0) {
        FBTools::modifyCategoryStats($pid, $parent, $posttime, $catid);
     }

    $database->setQuery("INSERT INTO #__fb_messages_text (mesid,message) 
        VALUES('$pid','$message')");
    $database->query();
    if ($thread == 0)  {
        //if thread was zero, we now know to which id it belongs, so we can determine the thread and update it
        $database->setQuery("UPDATE #__fb_messages SET thread='$pid' WHERE id='$pid'");
        $database->query();
    }

    //update the user posts count
    if ($my->id)  {
        $database->setQuery("UPDATE #__fb_users SET posts=posts+1 WHERE userid={$my->id}");
       $database->query();
    }
. . .

Bob
Azzy_p 03 Dec, 2008
Thanks Bob!๐Ÿ™‚

I have no idea where to pop this in though :/ I've tried a few places but none worked.

Thanks,

Arron
GreyHead 03 Dec, 2008
Hi Azzy_p,

Nor me, sorry, I don't have the time to work all through this at the moment. Maybe when things get quieter.

Bob
Azzy_p 04 Dec, 2008
Hey Bob,

That's no problem I understand! Thanks for all the help so far though!

Arron
Max_admin 04 Dec, 2008
I think this code need to go in the onsubmit after email box and define the $database of course and also remove or find some code to do what the FBtools class does!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger