auto exporting data into forums

wingnut110 08 May, 2008
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 09 May, 2008
Anyone out there willing to take a look at this and give me any advice? Thank you in advance:)
GreyHead 09 May, 2008
Hi Luke,

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

Bob
wingnut110 09 May, 2008
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
GreyHead 09 May, 2008
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
wingnut110 09 May, 2008
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.
GreyHead 10 May, 2008
Hi wingnut110,

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

Bob
wingnut110 10 May, 2008
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..
<?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 = "".$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 ...
    $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.
GreyHead 10 May, 2008
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
wingnut110 10 May, 2008
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
GreyHead 11 May, 2008
Hi Luke,

Here's a re-written version for Joomla 1.0.x. I've added a few comments prefixed '::'.
<?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 = "".$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='$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
$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
wingnut110 11 May, 2008
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 11 May, 2008
Hey Bob,

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

//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
ThijsD 12 May, 2008
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!😟
GreyHead 12 May, 2008
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
$fieldname = 'armory';
near the beginning.

To test the message bit please comment out the line:
$msg = str_replace("\n","\n\n",$msg);
as
// $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
GreyHead 12 May, 2008
Hi ThijsD,

What text do you get?

We need some clues to help work out what is happening?

Bob
wingnut110 12 May, 2008
Hey Bob,

I am using Fireboard 1.0.0

The bit about the "armory" makes sense now:)

Also.. I already tried deleting that line - didn't seem to make a difference, at least to me.

as for the coffecup forms, I just installed coffecup and made a form, posted the html into the html section of chronoforms.. Only thing out of the ordianry is that chronoforms creates their own *form* tags.. so I had to delete them from my coffeecup code.. other than that, I dunno:(


Luke
ThijsD 12 May, 2008
Hi Bob,

I hope I am not interfering with the original topic of this thread.

Coffeecup We Form Builder generates 5 files (PHP, Shockwave Flash Object, XML, JScript Script File and a HTML-previewdocument.

I pasted the XML in the Chronoform Form HTML-field and the JScript Script File (named swfobject) in the Form JavaScript-field.
When I save and click on the link I get an error message

Parse error: parse error, unexpected T_STRING in /home/virtual/site207/fst/var/www/html/components/com_chronocontact/chronocontact.html.php(83) : eval()'d code on line 1

I am releatively new to Joomla and very new to ChronoForms, so I will undoubtly make a stupid error somewhere, but where?🙂

Thijs
GreyHead 12 May, 2008
Hi ThisjD,

We are a bit at cross purposes here but I don't think these forums allow thread splitting.

The error message is because there's something unexpected in the first line of whatever you pated into the Form HTML box - what is there?

Bob
ThijsD 12 May, 2008
Hi Bob,

The first few lines read
<?xml version="1.0" encoding="UTF-8"?>

<form url="inschrijfformulierbso.php"
 window="_self"
 method="POST"
 fontname="MS Sans Serif"
 width="350"
 height="1611"
 bkcolor="0xFFFFFF"
 transparent="f"
 fontcolor="0x000000"
 outlinecolor="0xFFFFFF"
 themecolor="0xFFFF99"
 fontcolor2="#000000"
 bkcolor2="#FFFFFF"
 includeresults="false"
 emailuser="true"
 verifymessage="Het Emailadres is niet juist!"
 reqmessage="Een of meer verplichte velden niet ingevuld!"
 transition="0"
 autoresponseincluderesults="t"
 autoresponseaddtotop="f"
 usephp="true"
 disableclicktoactiveprompt="true"
 extensions="*.txt;*.gif;*.jpg;*.jpeg;*.zip;*.doc;*.png;*.pdf;*.rtf"
>


Thijs
GreyHead 12 May, 2008
Hi Thijs,

OK - that's an XML file that describes a form. ChronoForms is expecting html in there, with maybe some PHP tags in it.

Copy the HTML from the preview document and that will probably work.

Bob
ThijsD 12 May, 2008
Thanks a lot Bob, that did the trick! 🙂🙂

Thijs
thexrated 15 May, 2008
Hi everyone,

Firstly, I have to say that Chronoforms has been a great addition to my little gaming guild website. Also using it to create an application form.

However, I am also looking for a way to make it so that the form would automatically be send to our forum. We have fireboard also. It is probably the same that was asked the OP in this thread?

Any chance to share that data with me? I am really not that experienced with Joomla or HTML, so would greatly appreciate it.

There seems to be Appbot which sends the message. How is this handled exactly? And how do you define the format in which the sent data appears in the forum?

Thanks for your help.
wingnut110 20 May, 2008
Hi Thexrated,

I never got it fully working:( I got the form to make a new post in the forum with the correct topic, but couldn't get it to write the data to the correct table to make the message. I did create an account on the website as "appbot".

Hope to get it figured out soon, if so ,I will gladly post the code here for ya:)


Luke
GreyHead 20 May, 2008
Hi Luke,

Still on my 'to-do' list - it's been a busy week or two I'm afraid.

Bob
This topic is locked and no more replies can be posted.