HTML Form to phpBB forum as new topic

Discussion forum for MOD Writers regarding MOD Development.
Magnacarta
Registered User
Posts: 37
Joined: Mon Jul 12, 2010 12:04 am

HTML Form to phpBB forum as new topic

Post by Magnacarta » Tue Apr 19, 2011 12:50 am

I've seen a few posts and articles on these but I've not really understood them (bad english) or they were more so about using a form on phpBB itself.

What I would "like" to do, is create a form that creates a subject name such as Guild Application - Magnacarta.
The post body would then consist of all of the fields, formatted into one block of text, but obviously prettier and ordered. The form would also create a poll at the same time, with the question, "Accept applicant?" with a simple yes/no question. (so two buttons).

Also, I would like to create the script so that it creates the topic under the user ApplicationBot.

I've looked into a few suggestions that involves posting information into the database directly, but these were all for a phpBB form, rather than one based on a website and searching through the code was extremely confusing as I am, not new, but a "noob" at such things as this is merely a night time hobby.

I was looking at the MOD developed by Frans HERE to see if it could be adapted to such a request but I have no idea what to do. I've gotten fairly good at HTML/CSS/PHP over the past couple of weeks but this is stepping it up a notch, a bit beyond my level.

If you need further information, or I've been a little confusing, just let me know on here or in a PM and I'll gladly provide what is necessary.

My application form is on my test server at http://dannyp2.ifastnet.com/application.php

Magnacarta
Registered User
Posts: 37
Joined: Mon Jul 12, 2010 12:04 am

Re: HTML Form to phpBB forum as new topic

Post by Magnacarta » Wed Apr 20, 2011 12:36 pm

After days of combing through php and mysql manuals, I made a script that atleast posts the poster_id, forum_id, post_subject and post_text but I need to know how to generate a topic_id incremental to the previous one and insert to other tables. I will be taking my query to a mySQL forum as this section is getting to be more database than phpBB specific stuff but it would be helpful to know what on the phpBB database I need to enter information in to.

So far, I have:

Code: Select all

<?php
include 'dbcon.php';

$con = mysql_connect($server, $user_name, $password);

if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database, $con); //Replace with your MySQL DB Name
$username = 58;
$forum_id = 7;

$charname               = "Character Name:".$_POST['charname'];
$class                  = "Class:".$_POST['class'];
$role                  	= "Role:".$_POST['role'];
$playstyle              = "Play Style:".$_POST['playstyle'];
$mainoralt              = "Main or Alt:".$_POST['mainoralt'];
$swtorname              = "SWTOR forum name:".$_POST['swtorname'];
$age            		= "Age:".$_POST['age'];
$gender           		= "Gender:".$_POST['gender'];
$location               = "Location:".$_POST['location'];
$email          		= "Email:".$_POST['email'];
$teamspeak             	= "Do they have or will they use TS:".$_POST['teamspeak'];
$microphone             = "Do they have a working microphone:".$_POST['microphone'];
$comments               = "Their additional comments:".$_POST['comments'];
         
$postsubject = "Guild Application:".$_POST['charname'];
$posttextarray = array($charname,$class,$role,$playstyle,$mainoralt,$swtorname,$age,$gender,$location,$email,$teamspeak,$microphone,$comments);
$posttextformat = implode("\n",$posttextarray);
		 

$sql="INSERT INTO phpbb_posts (forum_id,poster_id,post_subject,post_text) VALUES ('$forum_id','$username','$postsubject','$posttextformat')"; /* inset into phpbb_posts */
if (mysql_query($sql,$con))
  {
  echo "Application was submitted successfully!";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }
mysql_close($con);
?>
Last edited by Magnacarta on Wed Apr 20, 2011 4:00 pm, edited 2 times in total.

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25227
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: HTML Form to phpBB forum as new topic

Post by Paul » Wed Apr 20, 2011 2:39 pm

You should not insert text directly into the database. You should use the submit_post function, that is defined in includes/functions_post.php instead.

If à new post is Created, à lot more as just the phpbb_Posts table is updated.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

Magnacarta
Registered User
Posts: 37
Joined: Mon Jul 12, 2010 12:04 am

Re: HTML Form to phpBB forum as new topic

Post by Magnacarta » Wed Apr 20, 2011 3:36 pm

Yeah, that's what I'm working on at the moment. I'll update the above code after this post is submitted but would you know how I would reference that submit_post() if it is a phpBB thing? Still a newbie with this stuff :P

I did manage to get information into post_text and displays properly from a DB point of view, but I need to know how to add an incremental topic ID, increasing by 1 compared to the last topic entered (by any means, not just my form). The post_id is already incrementing with each new post but the topic_id remains the same at 0 (I did no coding for post_id, it just does that automatically).

I also have post_subject, forum_id and poster_ID filling in properly.

A recent error is that it is updating the DB with two new rows with the same details (other than post_id).
EDIT: fixed the double post. Updating above code.

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25227
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: HTML Form to phpBB forum as new topic

Post by Paul » Wed Apr 20, 2011 4:28 pm

As I said, you should not insert it directly into the database ;).

There is, in the phpBB Code, already a function to submit a new post, called submit_post. You need to use that function. In the wiki (http://wiki.phpbb.com) you can find more information on how to use that function.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

Magnacarta
Registered User
Posts: 37
Joined: Mon Jul 12, 2010 12:04 am

Re: HTML Form to phpBB forum as new topic

Post by Magnacarta » Wed Apr 20, 2011 5:14 pm

I don't follow how the example on the wiki allows me to use this on a standard webpage form. Forgive me if it is easily understandable to you but I could do with an explanation of how to implement this and reference the file properly so I can actually use the function.

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25227
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: HTML Form to phpBB forum as new topic

Post by Paul » Wed Apr 20, 2011 5:32 pm

What do you not understand about it? Do you have any php knowledge? We are not going to write yoru code, you will need to do something yourself.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

manic2
Registered User
Posts: 435
Joined: Thu Jun 12, 2008 9:16 pm

Re: HTML Form to phpBB forum as new topic

Post by manic2 » Wed Apr 20, 2011 6:20 pm

This will start you off in the right direction:-

http://www.phpbb.com/community/viewtopi ... &t=1738385
manic

Magnacarta
Registered User
Posts: 37
Joined: Mon Jul 12, 2010 12:04 am

Re: HTML Form to phpBB forum as new topic

Post by Magnacarta » Wed Apr 20, 2011 6:37 pm

Just read through the example, making notes and breaking it down for myself to better understand.
How does the script in the wiki connect to the forums? I assume there is some other code that goes above it that defines locations of files etc so that the rest of the script knows what it is writing to?

Is it also possible to modify this so, in my case I have an ApplicationBot user account, a guest can fill out this application form, and the form is submitted to the forums by the bot?
I think that is why I tried the direct DB route, it just seemed easier at the time.

Yes, I am new to php etc. The last time I did any form of web design was HTML and CSS years ago, and have been studying medicine since that time so I haven't properly adjusted yet.

A little information about the form. The form is located on a standard HTML/CSS website with a few php bits in there to read and display the news thread. The form on this website will then gather necessary information in it's fields varying from text to radio inputs, all of that data will then be submitted as a new topic via a specifically created account, called "ApplicationBot". Just trying to be a bit more clear =]

At Manic2: Thanks. Checking through it to see how it is adapted to a standard webpage because, e.g, the root path definition for one is confusing xD and this form won't be in the root folder of the forums but on an upper level. Would this be merely changing :

Code: Select all

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
to

Code: Select all

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '/forums/';
?

Also as a guest would be submitting the form, but a premade account would be submitting the new topic so is there a way to modify that session management to do that?

Sorry if this seems simple to you two, I'm just not used to this kind of thinking.

Magnacarta
Registered User
Posts: 37
Joined: Mon Jul 12, 2010 12:04 am

Re: HTML Form to phpBB forum as new topic

Post by Magnacarta » Thu Apr 21, 2011 12:02 am

This code worked, but only posted Applicants comments which is probably due to the way $message is given it's values.

Code: Select all

<?php
$break_char = "\n";
$post_into_forum_id = 7;
$post_from_user = 58;

$poll_title		    = "Allow this applicant?";
$poll_length		= 0 ;
$poll_max_options	=  1;
$poll_vote_change	=  0;

$cur_poll_options[0] = 'Yes';
$cur_poll_options[1] = 'No';

$poll_option_text	= implode($break_char, $cur_poll_options);


define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('sotlapp');
//$submit = request_var('submit','');
$submit = request_var('submit','');
if($submit)
{
// get all vars en save to posting
$charname               = utf8_normalize_nfc(request_var('charname','',true));
$class                  = utf8_normalize_nfc(request_var('class','',true));
$role                  	= utf8_normalize_nfc(request_var('role','',true));
$playstyle              = utf8_normalize_nfc(request_var('playstyle','',true));
$mainoralt              = utf8_normalize_nfc(request_var('mainoralt','',true));
$swtorname              = utf8_normalize_nfc(request_var('swtorname','',true));
$age            		= utf8_normalize_nfc(request_var('age','',true));
$gender           		= utf8_normalize_nfc(request_var('gender','',true));
$location               = utf8_normalize_nfc(request_var('location','',true));
$email          		= utf8_normalize_nfc(request_var('email','',true));
$teamspeak             	= utf8_normalize_nfc(request_var('teamspeak','',true));
$microphone             = utf8_normalize_nfc(request_var('microphone','',true));
$comments               = utf8_normalize_nfc(request_var('comments','',true));

$message ='';
$message ='[b]Character Name[/b]:' . $charname . $break_char;
$message ='[b]Class[/b]:' . $class . $break_char;
$message ='[b]Role[/b]:' . $role . $break_char;
$message ='[b]Playstyle[/b]:' . $playstyle . $break_char;
$message ='[b]Main or alt[/b]?' . $mainoralt . $break_char;
$message ='[b]SWTOR forum name[/b]:' . $swtorname . $break_char;
$message ='[b]Age[/b]:' . $age . $break_char;
$message ='[b]Gender[/b]:' . $gender . $break_char;
$message ='[b]Location[/b]:' . $location . $break_char;
$message ='[b]E-mail[/b]:' . $email . $break_char;
$message ='[b]Teamspeak[/b]?' . $teamspeak . $break_char;
$message ='[b]Microphone[/b]?' . $microphone . $break_char;
$message ='[b]Applicants comments[/b]:' . $comments . $break_char;
         
$subject = "Guild Application:".$charname;

$sql = 'SELECT * FROM '.USERS_TABLE.' WHERE user_id='.$post_from_user;
$result = $db->sql_query($sql);
$post_from_user = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

    //Get huidige gebruikers_ip
    $sql = "SELECT session_ip FROM ".SESSIONS_TABLE." WHERE session_user_id = ".$user->data['user_id'];
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $user_ip = $row['session_ip'];

    $forum = $post_into_forum_id; //De kennisbank dus

	// Parse the text with the bbcode parser and write into $text
	$text		= utf8_normalize_nfc($message);

	$uid			= $bitfield			= $options	= '';	// will be modified by generate_text_for_storage
	$allow_bbcode	= $allow_smilies	=	$allow_urls	= true;

	$user->add_lang('ucp');

	// Switch array keys, with values in welcome pm.
	$welcome_vars = array(
		'{USERNAME}'		=> $user->data['username'],
		'{USER_ID}'			=> $user->data['user_id'],
		'{SITE_NAME}'		=> $config['sitename'],
		'{SITE_DESC}'		=> $config['site_desc'],
		'{ROOT_PATH}'		=> $phpbb_root_path);

	$sql_ary = array(
		'forum_id'	                => $post_into_forum_id,
		'topic_title'               => $subject,
		'topic_poster'              => $post_from_user['user_id'],
		'topic_time'	            => time(),
		'topic_first_poster_name'	=> $post_from_user['username'],
		'topic_first_poster_colour' => $post_from_user['user_colour'],
		'topic_last_poster_id'	    => $post_from_user['user_id'],
		'topic_last_poster_name'	=> $post_from_user['username'],
		'topic_last_poster_colour'  => $post_from_user['user_colour'],
		'topic_last_post_subject'	=> $subject,
		'topic_last_post_time'	    => time(),
		);

	//Insert the data into the topics table
	$sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
	$db->sql_query($sql);
    $topic_id = $db->sql_nextid();

    $sql_ary = array(
		'user_id'	                => $post_from_user['user_id'],
		'topic_id'                  => $topic_id,
		'topic_posted'              => 1,
		);

	//Insert the data into the topics posted table
	$sql = 'INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
	$db->sql_query($sql);
    $message_parser = new parse_message();
    $message_parser->message = $message;
    $message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies);

    $sql_ary = array(
		'topic_id'		            => $topic_id,
		'forum_id'	                => $forum,
		'poster_id'	                => $post_from_user['user_id'],
		'poster_ip'	                => $user_ip,
		'post_time'	                => time(),
		'post_approved'             => 1,
		'post_subject'	            => $subject,
		'post_text'	                => $message_parser->message,
		'bbcode_bitfield'	        => $message_parser->bbcode_bitfield,
		'bbcode_uid'		        => $message_parser->bbcode_uid,
        'post_checksum'             => md5($message_parser->message),
		);

	//Insert the data into the posts table
	$sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
	$db->sql_query($sql);

    $post_id = $db->sql_nextid();



	//Update the users topics table
    $poll = array(
		'poll_title'		=> $poll_title,
		'poll_length'		=> $poll_length,
		'poll_max_options'	=> $poll_max_options,
		'poll_option_text'	=> $poll_option_text,
		'poll_start'		=> time(),
		'poll_last_vote'	=> 0,
		'poll_vote_change'	=> 1,
		'enable_bbcode'		=> true,
		'enable_urls'		=> true,
		'enable_smilies'	=> true,
		'img_status'		=> 1
		);

    $parse_poll = new parse_message($poll['poll_title']);
	$parse_poll->bbcode_uid = $message_parser->bbcode_uid;
	$parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;

	$message_parser->parse_poll($poll);

    $sql_poll = array(
		'poll_title'		=> $poll['poll_title'],
		'poll_start'		=> time(),
		'poll_max_options'	=> $poll['poll_max_options'],
		'poll_length'		=> ($poll['poll_length'] * 86400),
		'poll_vote_change'	=> 0,
        'topic_first_post_id' => $post_id,
        'topic_last_post_id' => $post_id,
		);


   $sql = 'UPDATE ' . TOPICS_TABLE . " SET " . $db->sql_build_array('UPDATE', $sql_poll) . " WHERE topic_id =" . $topic_id;
   $db->sql_query($sql);

   $size = sizeof($cur_poll_options);
   $sql_insert_ary=Array();

   for($i=0; $i<$size;$i++)
   {
    $sql_insert_ary[] = array(
						'poll_option_id'	=> (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary),
						'topic_id'			=> $topic_id,
						'poll_option_text'	=> (string) $cur_poll_options[$i],
                        'poll_option_total' => 0
					);
   }
   $db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary);

	//Lets do the updating of the forums table
	$sql_ary = array(
							'forum_last_post_id' => $post_id,
							'forum_last_poster_id'	=> $post_from_user['user_id'],
							'forum_last_post_subject'	=> $subject,
							'forum_last_post_time' => time(),
							'forum_last_poster_name'	=> $post_from_user['username'],
							'forum_last_poster_colour' => $post_from_user['user_colour'],
							);

	$sql = 'UPDATE ' . FORUMS_TABLE . '
			SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
			WHERE forum_id = $forum";
	$db->sql_query($sql);



	$sql = 'UPDATE ' . FORUMS_TABLE . " SET forum_posts = forum_posts + 1 WHERE forum_id = $forum";
	$db->sql_query($sql);
	$sql = 'UPDATE ' . FORUMS_TABLE . " SET forum_topics = forum_topics + 1 WHERE forum_id = $forum";
	$db->sql_query($sql);
	$sql = 'UPDATE ' . FORUMS_TABLE . " SET forum_topics_real = forum_topics_real + 1 WHERE forum_id = $forum";
	$db->sql_query($sql);
	$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + 1 WHERE user_id = ".$post_from_user['user_id'];
	$db->sql_query($sql);

	$topic_count = $config['num_topics'] + 1;
	set_config('num_topics', $topic_count);

	$post_count = $config['num_posts'] + 1;
	set_config('num_posts', $post_count);




    trigger_error($user->lang['POST_ADDED_POSTFORM']);

//==================================================================================
}
else
{
// Show the form
		                    $form_key = 'formcheck';
		                    add_form_key($form_key);

    $template->assign_vars(array(
            'U_ACTION' => append_sid($phpbb_root_path.'apptoforum.'.$phpEx),
            ));


}

// Output the page

$template->set_filenames(array(
	'body' => './application.php')
);


?>

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25227
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: HTML Form to phpBB forum as new topic

Post by Paul » Thu Apr 21, 2011 6:55 am

You should use .= instead of = after the first assigment of $messsage. Now you overwrite $message everytime.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

Magnacarta
Registered User
Posts: 37
Joined: Mon Jul 12, 2010 12:04 am

Re: HTML Form to phpBB forum as new topic

Post by Magnacarta » Thu Apr 21, 2011 9:39 am

Ah spot on paul. That did the trick ^^ Now I just need to redirect it to a page other than the forums confirmation page xD Will see if I can get the redirect function to work ^^

Thanks for the help ^^

User avatar
ardodd
Registered User
Posts: 3
Joined: Sun Aug 23, 2015 8:56 pm
Location: Louisiana
Name: Albert Dodd
Contact:

Re: HTML Form to phpBB forum as new topic

Post by ardodd » Sun Aug 23, 2015 9:10 pm

I was looking through this post and it soundsl like something I am trying to find help with.
And yes I do not know any type of code.
I am frustrated,lost and dont where to turn for help. I have posted in forums,support forums,outsource.
And have yet to find someone to help figure out what the heck I need to do.

I seen this on a search engine and thought hopefully it will lead me in the right direction.
As I have a forum on a free forum hosting server and it get exactly what I pay for.
FREE=NO SUPPORT

I have tried their plug-ins and posted about needing help in developing the code or help with modifing the existing code to make it do what I need or should I say want it to do.

Is there anyway I could of ask of help in seeing what you have made be adaptable to what I need to make it do?

As of the last post you had this working and I was wodering how you made it work?
And if I could use it to adapt or alter my code to make it do what I would want it to?

I am not a complete Idiot just a little Nutz. And I am a Dummy at this stuff.

If explained to me in Dummie terms and technical code terms I might be able to figure it out myself.

I would like to post my Forum address but dont think I can.

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51758
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: HTML Form to phpBB forum as new topic

Post by Brf » Sun Aug 23, 2015 10:34 pm

This board is support for phpBB. We cannot help you with a proboards board here.
Also, the author of this four-year-old topic has not visited here in over a year.

User avatar
Lumpy Burgertushie
Registered User
Posts: 66471
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: HTML Form to phpBB forum as new topic

Post by Lumpy Burgertushie » Sun Aug 23, 2015 11:31 pm

the first thing you would need is at least some understanding of php and mysql and phpbb.
then, you will need ftp access to the files and database access. I seriously doubt that you have any of that access when using proboards of any of the "free phpbb" sites like it.

no offense, but this type of project is a little ambitious for someone with basically no knowledge of the coding involved.


robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

If a tree falls in the forest and nobody is there, does it make a sound?

Locked

Return to “[3.0.x] MOD Writers Discussion”