Implementing a PHP form, into PHPBB?

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Ideas Centre
Locked
Khyy
Registered User
Posts: 1
Joined: Wed Oct 31, 2007 8:36 pm

Implementing a PHP form, into PHPBB?

Post by Khyy » Wed Oct 31, 2007 8:44 pm

Hi, I'm curious about something. Basically what I want to do... is have a PHP form, that when submitted instead of being sent to an E-Mail or placed in an SQL database, have it submit it too a new thread in a hidden (only administrator viewable) forum. So my question is how... if at all possible could this be accomplished?
Last edited by dellsystem on Thu Nov 01, 2007 2:11 am, edited 1 time in total.
Reason: moved to mod requests, from discussion

ettelcar
Registered User
Posts: 13
Joined: Mon Jul 02, 2007 11:05 am
Location: France

Re: Implementing a PHP form, into PHPBB?

Post by ettelcar » Fri Nov 02, 2007 3:48 pm

That should be quite an easy thing. I do not say that I plan doing it, but I can give a few hints.

The first thing to know is whether you want it to be usable by everyone, just by your forum user's, or just by a group of users. (I suggest limiting at least to the forum users, but that is your choice)

The next step is creating a module, whether a new module category or a page in an existent module group. In this module, there shall be :
  • a verification of the user's permissions, if he can not, a redirection box
  • if the form is submitted, the submitting using the post functions, then announcing whether it fails, succeeds or need extra-information with an info box
  • a display of the form you want to submit
Then, simply add it in the administration panel.

For creating a new module category, just like acp or ucp or mcp, I can tell how to do. I've already done it for my never-to-be-finished-or-in-a-very-long-time mod.

As I said, I do not plan doing it as my time is a precious thing that I do not even have for my own mod requests. But this is quite a quick time and if I'm worried a day or have a few minutes available, I may change my mind.

MCPB
Registered User
Posts: 198
Joined: Wed Jan 14, 2004 3:07 am

Re: Implementing a PHP form, into PHPBB?

Post by MCPB » Sat Nov 03, 2007 12:08 am

i'm looking for the very same thing..

you sure you don't want to make this one?

ettelcar
Registered User
Posts: 13
Joined: Mon Jul 02, 2007 11:05 am
Location: France

Re: Implementing a PHP form, into PHPBB?

Post by ettelcar » Sat Nov 03, 2007 3:44 pm

Well, anyway, even if I tried to do ti, I do not have enough informations. As I said :
ettelcar wrote: The first thing to know is whether you want it to be usable by everyone, just by your forum user's, or just by a group of users. (I suggest limiting at least to the forum users, but that is your choice)

[...]

The next step is creating a module, whether a new module category or a page in an existent module group.
And the treatment of the form is very specific to itself and the fields it contains.

So if I were willing to do one with a specific control panel (as I do not see what it has to do with the ucp, the mcp nor the acp) I would do something like that :

Take care to all the commentaries beginning with "NOTE :"

Creating the file corresponding to the form control panel (fcp), at the forum root : root/fcp.php

Code: Select all

<?php
/** 
*
* @package fcp
* @version $Id: fcp.php,v 1.0 2007/11/03
* @copyright (c) 2007 Ettelcar
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
require($phpbb_root_path . 'includes/functions_user.' . $phpEx);
require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
require($phpbb_root_path . 'includes/functions_posting.' . $phpEx);

// Basic parameter data
$id 	= request_var('i', 'main');
$mode	= request_var('mode', 'main');

if ($mode == 'login' || $mode == 'logout' || $mode == 'confirm')
{
	define('IN_LOGIN', true);
}

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('fcp');

// Setting a variable to let the style designer know where he is...
$module = new p_master();

// Only registered users can go beyond this point
if (!$user->data['is_registered'])
{
	if ($user->data['is_bot'])
	{
		redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
	}

	//NOTE : you may change 'LOGIN_EXPLAIN_EDIT' one with a more appropriate if you wish.
	//Simply add yours in root/language/**/common.php and edit this string for corresponding.
	login_box('', $user->lang['LOGIN_EXPLAIN_EDIT']);
}

// Instantiate module system and generate list of available modules
$module->list_modules('fcp');

// Check if the zebra module is set
if ($module->is_active('zebra', 'friends'))
{
	// Output listing of friends online
	$update_time = $config['load_online_time'] * 60;

	$sql = $db->sql_build_query('SELECT_DISTINCT', array(
		'SELECT'	=> 'u.user_id, u.username, u.username_clean, u.user_colour, MAX(s.session_time) as online_time, MIN(s.session_viewonline) AS viewonline',

		'FROM'		=> array(
			USERS_TABLE		=> 'u',
			ZEBRA_TABLE		=> 'z'
		),

		'LEFT_JOIN'	=> array(
			array(
				'FROM'	=> array(SESSIONS_TABLE => 's'),
				'ON'	=> 's.session_user_id = z.zebra_id'
			)
		),

		'WHERE'		=> 'z.user_id = ' . $user->data['user_id'] . '
			AND z.friend = 1
			AND u.user_id = z.zebra_id',

		'GROUP_BY'	=> 'z.zebra_id, u.user_id, u.username_clean, u.user_colour, u.username',

		'ORDER_BY'	=> 'u.username_clean ASC',
	));

	$result = $db->sql_query($sql);

	while ($row = $db->sql_fetchrow($result))
	{
		$which = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? 'online' : 'offline';

		$template->assign_block_vars("friends_{$which}", array(
			'USER_ID'		=> $row['user_id'],

			'U_PROFILE'		=> get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
			'USER_COLOUR'	=> get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
			'USERNAME'		=> get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
			'USERNAME_FULL'	=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']))
		);
	}
	$db->sql_freeresult($result);
}

// Select the active module
$module->set_active($id, $mode);

// Load and execute the relevant module
$module->load_active();

// Assign data to the template engine for the list of modules
$module->assign_tpl_vars(append_sid("{$phpbb_root_path}fcp.$phpEx"));

// Generate the page, do not display/query online list
$module->display($module->get_page_title(), false);

/**
* Function for assigning a template var if the zebra module got included
*/
function _module_zebra($mode, &$module_row)
{
	global $template;

	$template->assign_var('S_ZEBRA_ENABLED', true);

	if ($mode == 'friends')
	{
		$template->assign_var('S_ZEBRA_FRIENDS_ENABLED', true);
	}

	if ($mode == 'foes')
	{
		$template->assign_var('S_ZEBRA_FOES_ENABLED', true);
	}
}

?>
Then, the only (for now) module your panel will contain : root/includes/fcp/fcp_main.php

Code: Select all

<?php
/** 
*
* @package fcp
* @version $Id: fcp_main.php,v 1.0 2007/11/03
* @copyright (c) 2007 Ettelcar
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* fcp_main
* FCP Front Panel
* @package ecp
*/
class fcp_main
{
	var $p_master;
	var $u_action;
	
	function fcp_main(&$p_master)
	{
		$this->p_master = &$p_master;
	}

	function main($id, $mode)
	{
		global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;

		$error = array();
		$notify = array();
		
		switch ($mode)
		{
			case 'main':
			default :
				$submit = (isset($_POST['submit'])) ? true : false;
				if($submit) {//NOTE : this part is your work, so make it as you wish.
					$post = "";
					$subject = "";
					$poll = array()
					//NOTE : collect all the data you need with $var_name = request_var('var_name',default_var_name);
					// then, put the resulting post text in the $post var, the subject in $subject, the poll data in $poll if needed.
					
					if(all you need is there) {//NOTE : of course, edit this
						
						//NOTE : arrange the $data array to look like something like that... hitn : the $user->data will be usefull...
						$data = array(
							'topic_title'			=> (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
							'topic_first_post_id'	=> (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
							'topic_last_post_id'	=> (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
							'topic_time_limit'		=> (int) $post_data['topic_time_limit'],
							'topic_attachment'		=> (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
							'post_id'				=> (int) $post_id,
							'topic_id'				=> (int) $topic_id,
							'forum_id'				=> (int) $forum_id,
							'icon_id'				=> (int) $post_data['icon_id'],
							'poster_id'				=> (int) $post_data['poster_id'],
							'enable_sig'			=> (bool) $post_data['enable_sig'],
							'enable_bbcode'			=> (bool) $post_data['enable_bbcode'],
							'enable_smilies'		=> (bool) $post_data['enable_smilies'],
							'enable_urls'			=> (bool) $post_data['enable_urls'],
							'enable_indexing'		=> (bool) $post_data['enable_indexing'],
							'message_md5'			=> (string) $message_md5,
							'post_time'				=> (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
							'post_checksum'			=> (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
							'post_edit_reason'		=> $post_data['post_edit_reason'],
							'post_edit_user'		=> ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
							'forum_parents'			=> $post_data['forum_parents'],
							'forum_name'			=> $post_data['forum_name'],
							'notify'				=> $notify,
							'notify_set'			=> $post_data['notify_set'],
							'poster_ip'				=> (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
							'post_edit_locked'		=> (int) $post_data['post_edit_locked'],
							'bbcode_bitfield'		=> $message_parser->bbcode_bitfield,
							'bbcode_uid'			=> $message_parser->bbcode_uid,
							'message'				=> $message_parser->message,
							'attachment_data'		=> $message_parser->attachment_data,
							'filename_data'			=> $message_parser->filename_data,
			
							'topic_approved'		=> (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false,
							'post_approved'			=> (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false,
						);
						//NOTE : you may also use submit_post('reply',... if prefered
						$redirect_url = submit_post('post', $subject, $user->data['username'],  POST_NORMAL, &$poll, &$data);
						
						meta_refresh(3, $redirect_url);
						$message = $user->lang['POST_STORED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>');
						$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']) . '">', '</a>');
						trigger_error($message);
					}
					else {//missing elements
						$error[] = $user->lang['MY_FORM_MISSING_ELEMENTS'];
					}
					
					$template->assign_vars(array(
						'USERNAME'			=> $user->data['username'],
						'...'				=> sprintf($user->lang['MY_FORM_...'],$var1,$var2)//NOTE : arrange this and add this line
						// as many times as you need to build your form with the adequated vars.
						//I suggest you put back the correctly submitted values when the form is incomplete, so that we
						// do not have to rewrite everything.
						)
					);
					
				}
			break;

		$template->assign_vars(array( 
			'L_TITLE'			=> $user->lang['FCP_MAIN'],
			'L_EXPLAIN'			=> $user->lang['FCP_MAIN_EXPLAIN'],
			'U_ACTION'			=> append_sid($this->u_action),
			'U_ROOT'			=> $phpbb_root_path)
		);

		// Warning and notifying messages 
		if (sizeof($error))
		{
			$template->assign_vars(array(
				'S_WARNING'		=> true,
				'WARNING_MSG'	=> implode('<br />', $error))
			);
		}
		
		if (sizeof($notify))
		{
			$template->assign_vars(array(
				'S_NOTIFY'		=> true,
				'NOTIFY_MSG'	=> implode('<br />', $notify))
			);
		}

		// Set desired template
		$this->tpl_name = 'fcp_main';
		$this->page_title = 'FCP_MAIN';
	}
}

?>
The info file : root/includes/fcp/info/fcp_main.php

Code: Select all

<?php
/** 
*
* @package fcp
* @version $Id: fcp_main.php,v 1.0 2007/11/03
* @copyright (c) 2007 Ettelcar
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* @package module_install
*/
class fcp_main_info
{
	function module()
	{
		return array(
			'filename'	=> 'fcp_main',
			'title'		=> 'FCP_MAIN',
			'version'	=> '1.0',
			'modes'		=> array(
				'main'		=> array('title' => 'FCP_MAIN', 'auth' => '', 'cat' => array('FCP_MAIN'))
			),
		);
	}

	function install()
	{
	}

	function uninstall()
	{
	}
}

?>
So, now do the template page in root/styles/**/template/fcp_main.html
If you are not familiar with building templates, I suggest you take a look at the phpBB documentation about it. Basically, all you will need is using {VAR_NAME} for vars you have defined in your php file, {L_VAR_NAME} for those in the language file, and copying the includes from any other well chosen file in the same directory.

Then, writing the language file just like another one in the same directory.
root/language/**/fcp.php
Be sure to write the MY_FORM_MISSING_ELEMENTS , FCP_MAIN , FCP_MAIN_EXPLAIN and all the language vars you are using.

Now edit the root/language/**/common.php to add the 'FCP' entry with the text of your choice.


Next step is to add the fcp module category :
edit root/include/acp/acp_modules.php
find

Code: Select all

		else if ($this->module_class == 'mcp')
		{
			$user->add_lang('mcp');
		}
and add after

Code: Select all

		else if ($this->module_class == 'fcp') //fcp modules
		{
			$user->add_lang('fcp');
		}
edit root/include/acp/info/acp_modules.php
find

Code: Select all

				'mcp'		=> array('title' => 'MCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')),
and after add

Code: Select all

				'fcp'		=> array('title' => 'FCP', 'auth' => 'acl_a_modules', 'cat' => array('FCP_MODULE_MANAGEMENT')),//fcp modules

now, the module category should have magically appeared in you module managing in the acp.
Install the module you have created within this category.

For people can reach this module, add finally a link on you header :
edit root/styles/**/template/overall_header.html
find

Code: Select all

				<a href="{U_FAQ}"><img src="{T_THEME_PATH}/images/icon_mini_faq.gif" width="12" height="13" alt="*" /> {L_FAQ}</a>
or the line corresponding in another template, containing "{L_FAQ}"
and after add

Code: Select all

				<!-- IF S_USER_LOGGED_IN -->&nbsp; &nbsp;<a href="{U_FCP}"><img src="{T_THEME_PATH}/images/icon_mini_faq.gif" width="12" height="13" alt="*" /> {L_FCP}</a><!-- ENDIF -->
you may replace the image by another one.


OK. I'me done, after it, it depends upon you form, and any basic low-skilled modder should be able to help.


EDIT : PS : oop... forgot one last thing : Update your database : add fcp, just like mcp and ucp in the "modules" table.
The `module_id` should be the highest+1,
module_enabled module_display : 1,
module_basename : nothing (blank),
module_class : fcp,
parent_id : 0,
left_id : the highest right_id + 1,
right_id : left_id +1,
module_langname : FCP_MAIN

Do this before adding the module in the acp. Anyway, you can not do it the other way...

enix
Registered User
Posts: 20
Joined: Thu Oct 04, 2007 4:19 pm

Re: Implementing a PHP form, into PHPBB?

Post by enix » Thu Jun 19, 2008 3:14 am

Thank you ettelcar.
Very usefull ;)

Daptonic
Registered User
Posts: 12
Joined: Mon Oct 16, 2006 10:30 pm
Location: Los Angeles, CA
Name: Chris

Re: Implementing a PHP form, into PHPBB?

Post by Daptonic » Wed Aug 20, 2008 6:37 pm

I'm not really understanding the template part of this tutorial, I'm not very php or phpbb code savy. Any help would be greatly appreciated.

For testing purposes i'm using the default Pro Silver theme, when I take it "live" I'll be using the "wowred" theme. If that info helps.

User avatar
rajkumar
Registered User
Posts: 7
Joined: Sat Oct 04, 2008 6:58 pm

Re: Implementing a PHP form, into PHPBB?

Post by rajkumar » Sun Oct 19, 2008 7:30 pm

hey thnx
thats great .. i was searching for this

but its not working for me ... i dont know where i have made a mistake

i saved all the files as said
1)root/fcp.php
2)root/includes/fcp/fcp_main.php
3)root/includes/fcp/info/fcp_main.php
4)root/styles/**/template/fcp_main.html -> as of now i have just made a test page for this. i think this is the page in which the form will be shown to the users. am i right?
5)writing the language file
root/language/**/fcp.php

Code: Select all

$lang = array_merge($lang, array(
	'MY_FORM_MISSING_ELEMENTS'	=>	'One of the Data is missing',
	'FCP_MAIN'					=>	'main FCP',
	'FCP_EXPLAIN'				=>	'panel'));
6)root/language/**/common.php
have added following

Code: Select all

'FCP'					=> 'Form Control Panel',
	'FCP_SUBMIT'			=> 'Submit Form',
7)edited root/include/acp/acp_modules.php
8)edited root/include/acp/info/acp_modules.php
yes the module category has appeared :)
9)edit root/styles/**/template/overall_header.html
in this step i have added the following code in index_body.html of the template that im using (Submerged is the theme that im using)

Code: Select all

<!-- IF U_MCP --><a href="{U_MCP}">{L_MCP}</a><br />
								<!-- ENDIF -->
								<!-- IF S_USER_LOGGED_IN --></a><br /><a href="fcp_main.html">{L_FCP_SUBMIT}</a>
								<!-- ENDIF -->
now when a user wants to go to form page to submit details it will click on submit form. but the page doesnt open when i do so. what is the problem here ? can you help me ettelcar

then when these info is entered into the form i want it in the Form Control panel. In the ACP i can see a new tab on the top of FCP but on clicking there it doesnt show anything :( . i want the data entered in the form to be displaced in the form control panel

User avatar
rajkumar
Registered User
Posts: 7
Joined: Sat Oct 04, 2008 6:58 pm

Re: Implementing a PHP form, into PHPBB?

Post by rajkumar » Thu Oct 23, 2008 3:46 pm

is anybody interested in this MOD ?

i tried a lot and also have searched through the forum this is the only request made here to show a form page and get the submitted details in the form control panel

i want the submitted data to be shown in the moderator control panel. i hope MODDERs are interested in this small MOD :D

Locked

Return to “[3.0.x] MOD Requests”