auto exporting data into forums

Post any questions you may have here

auto exporting data into forums

Postby wingnut110 on Thu May 08, 2008 7:35 pm

Hey guys,
I am kind of lost with how to go about this, any help would be greatly appreciated. I run a world of warcraft guild site.(joomla) I made a simple html form (guild recruitment application) with coffeecup and posted the data into chronoforms. Set it to email the info to two emails. It works great! What I want is for (on submit) it posts the information into a new thread in our forum. (we use Fireboard) I know this would have to be a fairly custom script. I have found an article on this at http://www.confuzzled.nl/?p=1018 (scrool dwon to the part about applications) it even has the code that he used. I am not quite sure how to set it up and if I would need to alter the code for my page.

Thank you again for any help:)

Luke
wingnut110
Fresh Boarder
 
Posts: 10
Joined: Thu May 08, 2008 1:08 am

Re:auto exporting data into forums

Postby wingnut110 on Fri May 09, 2008 7:14 pm

Anyone out there willing to take a look at this and give me any advice? Thank you in advance:)
wingnut110
Fresh Boarder
 
Posts: 10
Joined: Thu May 08, 2008 1:08 am

Re:auto exporting data into forums

Postby GreyHead on Fri May 09, 2008 7:26 pm

Hi Luke,

I took a quick look - that code or something similar should work OK in the 'OnSubmit after' box in ChronoForms.

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3253
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:auto exporting data into forums

Postby wingnut110 on Fri May 09, 2008 9:30 pm

Hey Bob,

Thank you for checking this out for me. I inserted that code into the "OnSubmit after" box, although it still doesn't work:( not sure if it is getting lost in fireboard or what. Is there something that i would need to insert into the form code to make these work together? I will keep throwing ideas at it until it works:) Thanks again:)

Luke
wingnut110
Fresh Boarder
 
Posts: 10
Joined: Thu May 08, 2008 1:08 am

Re:auto exporting data into forums

Postby GreyHead on Fri May 09, 2008 9:42 pm

Hi Luke,

I'm afraid that you get into debug mode. Check and see if anything is getting into the database; output the sql and see if that will work with PHPMyAdmin; . . . basically you work through the code one line at a time making sure that each line is doing what it's supposed to do.

Tedious but it works.

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3253
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:auto exporting data into forums

Postby wingnut110 on Fri May 09, 2008 10:16 pm

Hey Bob,

The form data is getting writ to the database. jos_chronoforms_4 not sure how to get it to send it to the fireboard table.
wingnut110
Fresh Boarder
 
Posts: 10
Joined: Thu May 08, 2008 1:08 am

Re:auto exporting data into forums

Postby GreyHead on Sat May 10, 2008 7:04 am

Hi wingnut110,

That's what the confuzzled.nl code is for . . .

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3253
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:auto exporting data into forums

Postby wingnut110 on Sat May 10, 2008 7:26 am

Hiya Bob,

Ya, I understand that. What i meant, and should have said rather is that i cannot get it to actually write to the fireboard tables. It's just not getting there. I can execute the sql queries from the code on my database and it writes the info to the fb tables. I'm thinking it may be not connecting to the database?

Here is the code that I have now..
Code: Select all
<?php
$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);

$author = "Appbot";
    $subject = $_POST['char_name']." - ".$_POST['class'];
    $date = strtotime("now");
    $_POST['armory']="[URL=".$_POST['armory']."]LINK[/URL]";

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

    //make the title bold
    $key = "[b]".$key."[/b]";

    //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 ...
    $msg=str_replace("
    “,”\n\n”,$msg);

    // Create the new topic
    $create_thread = "INSERT INTO `joomla`.`jos_fb_messages` SET id=NULL, parent=0, thread=0, catid=43, name='$author', userid=328, email=NULL, subject='$subject', time=$date, ip=NULL";
    mysql_query($create_thread) or die(mysql_error());

    // Figure out what the correct threadid is of that new topic
    $mesid=mysql_insert_id();

    // 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
    $set_thread="update jos_fb_messages set thread=id where id=$mesid";
    mysql_query($set_thread) or die(mysql_error());   

    // 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
    $set_forum="update jos_fb_categories set id_last_msg=$mesid where id=43";
    mysql_query($set_forum) or die(mysql_error());

    // Stick the $msg variable into the body of the topic
    $insert_msg="INSERT INTO `joomla`.`jos_fb_messages_text` SET mesid=$mesid, message='$msg'";
    mysql_query($insert_msg) or die(mysql_error());
    ?>
I did a little investigation and changed the catid, userid and such... like I said, works as individual sql queries, just not all together.. not sure if it's not connecting to the database, if chronoforms just dont like doing it this way, or maybe it's just put together incorrectly.
wingnut110
Fresh Boarder
 
Posts: 10
Joined: Thu May 08, 2008 1:08 am

Re:auto exporting data into forums

Postby GreyHead on Sat May 10, 2008 9:45 am

Hi wingnut110,

Ok, we'll clean this up a bit and turn it into Joomla-style code on the way. Which version of Joomla are you using? (1.0.x and 1.5 have different code syntaxes.)

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3253
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:auto exporting data into forums

Postby wingnut110 on Sat May 10, 2008 4:54 pm

Hi Bob,

I am using joomla 1.0.12 Thank you for your patience and help:) I know just enough about this stuff to be dangerous..lol but I guess this is how one learns:)


Luke
wingnut110
Fresh Boarder
 
Posts: 10
Joined: Thu May 08, 2008 1:08 am

Re:auto exporting data into forums

Postby GreyHead on Sun May 11, 2008 8:40 am

Hi Luke,

Here's a re-written version for Joomla 1.0.x. I've added a few comments prefixed '::'.
Code: Select all
<?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 $database;

// :: set some variables that may need to be changed
$catid = 43;
$userid = 328;
$author = "Appbot";
$fieldname = 'field_name';


$subject = $_POST['char_name']." - ".$_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 = "[b]".$key."[/b]";

    //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='$msg'";
$database->setQuery($sql);
if ( !$database->query() ) {
    echo "<script> alert('".$database->getErrorMsg()."');
       window.history.go(-1); </script>";
}
?>
I've pulled some variables into a config block at the beginning and have changed all the database code to use Joomla syntax.

I have one query with the line
Code: Select all
$msg = str_replace("\n","\n\n",$msg);
which is doing some newline cleanup. It was broken in confuzzled's example because it included a newline character of some kind. This may need tweaking to give a tidy result.

Not tested so may need some debugging.

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3253
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:auto exporting data into forums

Postby wingnut110 on Sun May 11, 2008 6:34 pm

Hiya Bob,

Thank you for your rework:)
It is now creating a thread in the correct place, and the topic is correct, although the message body is not getting there. The forum post shows this error in the message body:

Warning: Invalid argument supplied for foreach() in /home/.randie/jasmindria/knightsoftheroseguild.com/components/com_fireboard/template/default/view.php on line 1871

the code is writing to the jos_fb_messages, it is updating the jos_fb_categories, but its not writing to the jos_fb_messages_text .

I am assuming the problem lies in

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


also, not exactly sure why you changed

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

to

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

armory is the field name.. just curious:)

thank you for your help:) it's getting there!
wingnut110
Fresh Boarder
 
Posts: 10
Joined: Thu May 08, 2008 1:08 am

Re:auto exporting data into forums

Postby wingnut110 on Sun May 11, 2008 6:48 pm

Hey Bob,

Also here are lines 1871-1873 from /home/.randie/jasmindria/knightsoftheroseguild.com/components/com_fireboard/template/default/view.php

Code: Select all
//restore the \n (were replaced with _CTRL_) occurences
// inside code tags, but only after we have stripslashes;
// otherwise they will be stripped again

$msg_text =str_replace("_CRLF_", "\\n", stripslashes($fb_message_txt));
thought it might be helpful:)

Luke
wingnut110
Fresh Boarder
 
Posts: 10
Joined: Thu May 08, 2008 1:08 am

Re:auto exporting data into forums

Postby ThijsD on Mon May 12, 2008 6:03 am

Hi Karma,

Not an answer to your problem, but I see that you managed to get Coffeecup Form Builder forms into ChronoForms. I have problems to do so. Can you explain what to do. I have put the php code into the HTML-field and the javascript into the correspondig field, but all I get is some text instead of a form when I click on the link. Help appreciated! :(
ThijsD
Fresh Boarder
 
Posts: 4
Joined: Mon May 12, 2008 5:53 am

Re:auto exporting data into forums

Postby GreyHead on Mon May 12, 2008 7:25 am

Hi wingnut110,

The 'armory' to $fieldname change was just to help other people who may want to use this later.

What I forgot to do was to put 'armory' back in the line
Code: Select all
$fieldname = 'armory';
near the beginning.

To test the message bit please comment out the line:
Code: Select all
$msg = str_replace("\n","\n\n",$msg);
as
Code: Select all
// $msg = str_replace("\n","\n\n",$msg);
and see if that makes a difference - the code you quoted also deals with that . . . but there's no 'foreach' there ?-)

Which version of FireBoard are you running? I'll install a copy so that i can run a test here.

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3253
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Next

Return to ChronoForms Questions & Answers

Who is online

Users browsing this forum: MSN [Bot] and 3 guests