Submit Post Script

Discussion forum for MOD Writers regarding MOD Development.
User avatar
James78
Registered User
Posts: 811
Joined: Sat Jul 30, 2005 4:54 pm
Location: Washington, USA
Contact:

Submit Post Script

Post by James78 »

This took me about 3 hours to code up. I know there are probably a bunch of things wrong with the program already, that's why I'm posting it here. My program does not work according to the way I would like it to work of course... can anyone please point out my many errors, help me fix them, so I can polish this up? Thanks!!

In a very short summary explaining my program.. It works like.. you visit the page, if not logged in, you get sent to login page, login and get sent back to the form. You fill out form, press submit, values are captured by request_vars and set to where they should be (you'll see by looking at the program), and basically a new topic is made, they get a confirmation, and are redirected to the new topic. At least that's what I'm aiming for lol. It's obviously not working at all.

First 2 issues I've noticed are when you view the page and are not logged in, you don't get sent to the login page, and when you enter the data into the form and press submit, no new topic is made. This could be my failure to correctly capture the $_POST data through request_var().

Recruit.php - Location: /forum/recruit.php

Code: Select all

<?php
/**
*
* This program will create topics from forms filled
* out by a user.
* User: Recruit Robot
* Forum: Recruit forum
*
*/

define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx); 

// Lang...
$user->setup('mods/info_recruit');

// If user is not logged in, send them to login page
if ($user->data['user_type'] == ANONYMOUS)
{
    login_box('', $user->lang['LOGIN']);
}

/*
Submit_post is tricky, as it uses current
auth and user data. This is a workaround so
we can have our bot submit data instead.
*/

// Backup $auth and $user data
$backup = array(
   'user'   => $user,
   'auth'   => $auth,
);

$my_subject        = $user->data['username'] . "'s Application [NEW]";

// Restore original user auth data
// extract($backup);

// UserID = UserID of Recruit Bot
$user_id = '135';

// Overwrite with new data
$sql = 'SELECT *
   FROM ' . USERS_TABLE . '
      WHERE user_id = ' . $user_id;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

$user->data = array_merge($user->data, $row);
$auth->acl($user->data);

//Overwrite users IP
$user->ip = '0.0.0.0';

$submit = (isset($_POST['submit'])) ? true : false;

if ($submit)
{
    // subject and message
    $my_message        = "[b]Your soldier name:[/b] " . request_var('s_name', '', true);
    $my_message        .= "[b]Your age. (Lying will exclude you from membership):[/b] " . request_var('age', '', true);
    $my_message        .= "[b]Have you have been in a clan before? If so, what clans, and why did you leave?[/b] " . request_var('clans', '', true);
    $my_message        .= "[b]How did you find us?[/b] " . request_var('how_find', '', true);
    $my_message        .= "[b]Why do you want to join us?[/b] " . request_var('join_us', '', true);
    $my_message        .= "[b]Were you invited to join us? If so, by whom?[/b] " . request_var('invite', 'No I was not invited.', true);

    $my_subject        = utf8_normalize_nfc($my_subject);
    $my_message        = utf8_normalize_nfc($my_message);

    // variables to hold the parameters for submit_post
    $poll = $uid = $bitfield = $options = ''; 

    generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
    generate_text_for_storage($my_text, $uid, $bitfield, $options, true, true, true);

    // Data array
    $data = array( 
        'forum_id'        => 6,
        'icon_id'        => false,

        'enable_bbcode'        => true,
        'enable_smilies'    => true,
        'enable_urls'        => true,
        'enable_sig'        => true,

        'message'        => $my_message,
        'message_md5'    => md5($my_message),
                
        'bbcode_bitfield'    => $bitfield,
        'bbcode_uid'        => $uid,

        'post_edit_locked'    => 0,
        'topic_title'        => $my_subject,
        'notify_set'        => false,
        'notify'            => false,
        'post_time'         => 0,
        'forum_name'        => 'Recruiting',
        'enable_indexing'    => true,
        'topic_time_limit' => 0,
        'topic_approved' => true,
        'post_time' => 0,
    );

    // Mode - Subject - username (only if guest poster) - topic type - poll - post data - update message
    // We are creating a new topic
    submit_post('post', $my_subject, '', POST_NORMAL, $poll, $data);
    
    $meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx?t=" . $data['post_id']);
    $message = $user->lang['FORM_SENT'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
    meta_refresh(3, $meta_info);
    trigger_error($message);
}
// Output the page
page_header($page_title);

$template->assign_vars(array(
    'R_APP'                        => $user->lang['R_APP'],
    'S_NAME'                    => $user->lang['S_NAME'],
    'AGE'                            => $user->lang['AGE'],
    'AGREE_TERMS'            => $user->lang['AGREE_TERMS'],
    'CLANS'                        => $user->lang['CLANS'],
    'HOW_FIND'                => $user->lang['HOW_FIND'],
    'JOIN_US'                    => $user->lang['JOIN_US'],
    'INVITE'                    => $user->lang['INVITE'],
    'END_DESC'                => $user->lang['END_DESC'],
    'DESC'                        => $user->lang['DESC'],
    'S_SEND_ACTION'        => build_url('confirm_key'),
    )
);

$template->set_filenames(array(
    'body' => 'recruit.html')
);

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

page_footer();

?>
info_recruit.php - Location: /forum/language/en/mods/info_recruit.php

Code: Select all

<?php
/** 
*
* example [English]
*
* @package language
* @version $Id: v3_api.xml 52 2007-12-09 19:45:45Z jelly_doughnut $
* @copyright (c) 2007 phpBB Group 
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* DO NOT CHANGE
*/
if (empty($lang) || !is_array($lang))
{
    $lang = array();
}

// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine

$lang = array_merge($lang, array(
    'PAGE_TITLE'            => 'Recruit Form &bull; Ultimate Military Alliance',
    'FORM_SENT'                => 'Your recruit application has been entered into the system. Thank you for applying!',
    'RETURN_TOPIC'        => '%sGo to your topic%s',
    'DESC'                        => 'We currently are open recruiting (recruiting anyone).<br> If you would like to join us please read the following conditions, and the clan rules.<br><a href="http://www.umaclan.com/rules/bf2142-rules.html">BF2142 Rules</a><br><br><ul><li>We prefer a guidline age of 18+. (Be honest about your age)<br><li>Play online when available.<br><li>Mature personality (I.e. We do not want people who openly abuse people on public servers or chats)<br><li>Always Squad up and work as a Squad.<br><li>Willingness to always wear the Clan Tag.<br><li>We have a 0 tolerance policy against cheats, hacks, or stat padding! You do it, you are out!<br><li>Always play respectfully on whatever server you are on, so as not to bring shame on the clan tags.<br><li>You must have a mic. This is essential to be able to evaluate you and for in game communication and coordination of both squad and team strategies. (Mics are available from many stores for as little as $20-25)<br><li>There are no dues for regular members, but we appreciate donations. Dues for admins are $10 per month and dues for a reserved slot on a server is $5 per month.</ul><br>If you agree to these rules, including our clan rules, please fill out the form below:',
    'END_DESC'                => 'Wait for an admin or the Recruit Team to answer your post. Once the admin or Recruit Team gives you the go, add our clan recruit/pre-recruit tags to your name: =UMA(pr)=, or =UMA(r)=. After you have done this, we need to see you play regularly on our servers. Squad up with our full members, talk to them, and have a good game. You need a minimum of 3 recommendations by our members to be accepted as a full member; this can take on average a few weeks, or may be over very quickly. When you are a recruit, you are being evaluated by all our full members, Recruit Team, and the admins to make sure you follow the rules, and are a good player. If you break our rules, we will quickly revoke your recruit tags!',
    'R_APP'                        => 'Recruit Application',
    'S_NAME'                    => 'Your soldier name:',
    'AGE'                            => 'Your age. (Lying will exclude you from membership):',
    'AGREE_TERMS'            => 'I agree to follow the Clan Rules.',
    'CLANS'                        => 'Have you have been in a clan before? If so, what clans, and why did you leave?',
    'HOW_FIND'                => 'How did you find us?',
    'JOIN_US'                    => 'Why do you want to join us?',
    'INVITE'                    => 'Were you invited to join us? If so, by whom?',
));
?>
recruit.html - Location: /forum/styles/DVGFX/template/recruit.html
(P.S. DVGFX is my forum style)

Code: Select all

<!-- INCLUDE overall_header.html -->

<form name="send" action="{S_SEND_ACTION}" method="post">

<div class="panel">
	<div class="inner"><span class="corners-top"><span></span></span>
<h3>{R_APP}</h3>
	<fieldset class="fields2">
	<p>{DESC}</p><br>
	<table width="100%" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td>{S_NAME}</td>
    <td><input name="s_name" type="text"></td>
  </tr>
  <tr>
    <td>{AGE}</td>
    <td><input type="text" maxlength="2" name="age"></td>
  </tr>
  <tr>
    <td>{CLANS}</td>
    <td><textarea name="clans"></textarea></td>
  </tr>
  <tr>
    <td>{HOW_FIND}</td>
    <td><textarea name="how_find"></textarea></td>
  </tr>
  <tr>
    <td>{JOIN_US}</td>
    <td><textarea name="join_us"></textarea></td>
  </tr>
  <tr>
    <td>{INVITE}</td>
    <td><input type="text" name="invite"></td>
  </tr>
    <tr>
    <td><input type="checkbox">{AGREE_TERMS}</td>
  </tr>
</table>


    </fieldset>

	<span class="corners-bottom"><span></span></span></div>
</div>

<div class="panel">
	<div class="inner"><span class="corners-top"><span></span></span>

	<fieldset class="submit-buttons">
		<input type="reset" value="{L_RESET}" />&nbsp;
		<input type="submit" name="submit" value="{L_SUBMIT}" />
	</fieldset>
	<span class="corners-bottom"><span></span></span></div>
</div>
<br clear="all" />

<!-- INCLUDE breadcrumbs.html -->

<br clear="all" />

<div align="{S_CONTENT_FLOW_END}"><!-- INCLUDE jumpbox.html --></div>

<!-- INCLUDE overall_footer.html -->
</form>

<!-- INCLUDE overall_footer.html -->
Can anyone point out what I've done wrong and help me fix this problem? Thanks!!
If you encounter what is/or you think is a bug, please report it to the phpBB Bug Tracker
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52219
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Submit Post Script

Post by Brf »

Code: Select all

if ($user->data['user_type'] == ANONYMOUS)
is not correct. it should be:

Code: Select all

if ($user->data['user_id'] == ANONYMOUS)
User avatar
James78
Registered User
Posts: 811
Joined: Sat Jul 30, 2005 4:54 pm
Location: Washington, USA
Contact:

Re: Submit Post Script

Post by James78 »

Thanks for that suggestion. :D I knew that part wasn't correct.

From looking in the wiki, if you take a look at the first code example, it says ['user_type']. Anyone want to fix it? That's where I copied it from, probably why I got it wrong.

http://wiki.phpbb.com/Login_box

It turns out there were a lot of problems because I didn't do this at the top of the php:

Code: Select all

// Set up user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();
 
If you encounter what is/or you think is a bug, please report it to the phpBB Bug Tracker
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52219
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Submit Post Script

Post by Brf »

You are already doing a $user->setup for your own language file. That will do the default stuff too.
User avatar
James78
Registered User
Posts: 811
Joined: Sat Jul 30, 2005 4:54 pm
Location: Washington, USA
Contact:

Re: Submit Post Script

Post by James78 »

Ok, so I assume that means that the last line was un-needed. I'll remove that bit.

My program is working wonderfully now though, after 2 more hours of polishing it up. :D
If you encounter what is/or you think is a bug, please report it to the phpBB Bug Tracker
Wookie1664
Registered User
Posts: 65
Joined: Mon Jul 07, 2008 12:19 pm

Re: Submit Post Script

Post by Wookie1664 »

James78, is there any chance you could post the code that eventually worked for you?

The three files you posted earlier work as in they auto post to a new topic...but the template page where you add the info does not appear, For example, type in recruit.php and the next thing you see is the completed topic.

I've spent a good few hours on this now and seem to be getting nowhere fast, can you help me out?

Regards

Wookie
User avatar
James78
Registered User
Posts: 811
Joined: Sat Jul 30, 2005 4:54 pm
Location: Washington, USA
Contact:

Re: Submit Post Script

Post by James78 »

That's how I initially wrote my program for testing purposes, to make sure the posting part of it worked. It has, since then, been compiled into a fully working, and great program. Feel free to make any modifications, edits, etc to this. You will need to make quite a few..

recruit.php

Code: Select all

<?php
/**
*
* This program will create topics from forms filled
* out by a user.
* User: Recruit Robot
* Forum: Recruit forum
* Copyright 2008 James78
*
*/

define('IN_PHPBB', true);
$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/functions_posting.' . $phpEx);

// Set up user session
$user->session_begin();
$auth->acl($user->data);

// Lang...
$user->setup('mods/info_recruit');

// If user is not logged in, send them to login page
if ($user->data['user_id'] == ANONYMOUS)
{
    login_box('', $user->lang['LOGIN']);
}

$submit = (isset($_POST['submit'])) ? true : false;

if ($submit)
{
	// They need to fill out the entire application for it to be entered into the system
	if ((request_var('s_name', '', true) && request_var('r_name', '', true) && request_var('mic', '', true) && request_var('donate', '', true) && request_var('hours', '', true) && request_var('gender', '', true) && request_var('talents', '', true) && request_var('age', '', true) && request_var('how_find', '', true) && request_var('join_us', '', true) && request_var('games', '', true) && request_var('clans', '', true) && request_var('invite', '', true) && request_var('tell_us', '', true)) == '')
	{
		$meta_info = 'recruit.php';
		$message = $user->lang['NOT_FILLED_APP'] . '<br /><br />' . sprintf($user->lang['RETURN_APPLICATION'], '<a href="' . $meta_info . '">', '</a>');
		meta_refresh(4, $meta_info);
		trigger_error($message);
	}

	// If user doesn't enter number, trigger error message
	if (!is_numeric(request_var('age', '', true)))
	{
		$meta_info = 'recruit.php';
		$message = $user->lang['NUMBERS_ONLY_AGE'] . '<br /><br />' . sprintf($user->lang['RETURN_APPLICATION'], '<a href="' . $meta_info . '">', '</a>');
		meta_refresh(4, $meta_info);
		trigger_error($message);
	}

	// If user doesn't enter number, trigger error message
	if (!is_numeric(request_var('hours', '', true)))
	{
		$meta_info = 'recruit.php';
		$message = $user->lang['NUMBERS_ONLY_HOURS'] . '<br /><br />' . sprintf($user->lang['RETURN_APPLICATION'], '<a href="' . $meta_info . '">', '</a>');
		meta_refresh(4, $meta_info);
		trigger_error($message);
	}

	// You can't play a game more than 168 hours per week. This is defined by the laws of physics themself
	if (request_var('hours', '', true) > '168')
	{
		$meta_info = 'recruit.php';
		$message = $user->lang['HOURS_WRONG'] . '<br /><br />' . sprintf($user->lang['RETURN_APPLICATION'], '<a href="' . $meta_info . '">', '</a>');
		meta_refresh(4, $meta_info);
		trigger_error($message);
	}

	// If they didn't agree to our terms...
	if (!$_POST['agree_terms'])
	{
		$meta_info = 'recruit.php';
		$message = $user->lang['NEED_TO_AGREE'] . '<br /><br />' . sprintf($user->lang['RETURN_APPLICATION'], '<a href="' . $meta_info . '">', '</a>');
		meta_refresh(4, $meta_info);
		trigger_error($message);
	}

	$username_url = $user->lang['URL'] . $user->data['username_clean'] ."-u" . $user->data['user_id'] . ".html";
	$username = $user->data['username'];
	$o_user_id = $user->data['user_id'];
	$o_user_ip = $user->ip;

	$my_subject = $username . $user->lang['TOPIC'];
	
	// UserID = UserID of Recruit Bot
	$user_id = '135';

	// Overwrite with new data
	$sql = 'SELECT *
		FROM ' . USERS_TABLE . '
				WHERE user_id = ' . $user_id;
	$result = $db->sql_query($sql);
	$row = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

	$user->data = array_merge($user->data, $row);
	$auth->acl($user->data);

	//Overwrite users IP
	$user->ip = '0.0.0.0';

	// subject and message
	$my_message		= $user->lang['BB_BEGIN'] . $user->lang['USER'] . $user->lang['BB_END'] . "\n[url=" . $username_url . "]" . $username . "[/url]\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['R_NAME'] . $user->lang['BB_END'] . "\n" . request_var('r_name', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['S_NAME'] . $user->lang['BB_END'] . "\n" . request_var('s_name', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['AGE'] . $user->lang['BB_END'] . "\n" . request_var('age', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['GENDER'] . $user->lang['BB_END'] . "\n" . request_var('gender', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['HOURS'] . $user->lang['BB_END'] . "\n" . request_var('hours', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['DONATE'] . $user->lang['BB_END'] . "\n" . request_var('donate', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['MIC'] . $user->lang['BB_END'] . "\n" . request_var('mic', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['CLANS'] . $user->lang['BB_END'] . "\n" . request_var('clans', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['GAMES_NAME'] . $user->lang['BB_END'] . "\n" . request_var('games', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['HOW_FIND'] . $user->lang['BB_END'] . "\n" . request_var('how_find', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['JOIN_US'] . $user->lang['BB_END'] . "\n" . request_var('join_us', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['TELL_US'] . $user->lang['BB_END'] . "\n" . request_var('tell_us', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['TALENTS'] . $user->lang['BB_END'] . "\n" . request_var('talents', '', true) . "\n\n";
	$my_message		.= $user->lang['BB_BEGIN'] . $user->lang['INVITE'] . $user->lang['BB_END'] . "\n" . request_var('invite', '', true);

	$my_subject		= utf8_normalize_nfc($my_subject);
	$my_message		= utf8_normalize_nfc($my_message);

	// variables to hold the parameters for submit_post
	$poll = $uid = $bitfield = $options = ''; 

	generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
	generate_text_for_storage($my_message, $uid, $bitfield, $options, true, true, true);

	// Data array
	$data = array( 
		'forum_id'		=> 6,
		'icon_id'		=> false,

		'enable_bbcode'		=> true,
		'enable_smilies'	=> true,
		'enable_urls'		=> true,
		'enable_sig'		=> true,

		'message'		=> $my_message,
		'message_md5'	=> md5($my_message),
				
		'bbcode_bitfield'	=> $bitfield,
		'bbcode_uid'		=> $uid,

		'post_edit_locked'	=> 0,
		'topic_title'		=> $my_subject,
		'notify_set'		=> false,
		'notify'			=> false,
		'post_time' 		=> 0,
		'forum_name'		=> 'Recruiting',
		'enable_indexing'	=> true,
		'topic_time_limit' => 0,
		'topic_approved' => true,
		'post_time' => 0,
	);

	// Mode - Subject - username (only if guest poster) - topic type - poll - post data - update message
	// We are creating a new topic
	submit_post('post', $my_subject, '', POST_NORMAL, $poll, $data);

	// set original user back!
	$sql = 'SELECT *
		FROM ' . USERS_TABLE . '
				WHERE user_id = ' . $o_user_id;
	$result = $db->sql_query($sql);
	$row = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

	$user->data = array_merge($user->data, $row);
	$auth->acl($user->data);

	//Overwrite users IP to normal
	$user->ip = $o_user_ip;

	// Trigger success message
	$meta_info = append_sid("{$phpbb_root_path}viewtopic." . $phpEx ."?t=" . $data['topic_id']);
	$message = $user->lang['FORM_SENT'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
	meta_refresh(4, $meta_info);
	trigger_error($message);
}

// Page title
page_header($user->lang['PAGE_TITLE']);

$template->assign_vars(array(
	'R_APP'						=> $user->lang['R_APP'],
	'S_NAME'					=> $user->lang['S_NAME'],
	'AGE'							=> $user->lang['AGE'],
	'AGREE_TERMS'			=> $user->lang['AGREE_TERMS'],
	'CLANS'						=> $user->lang['CLANS'],
	'HOW_FIND'				=> $user->lang['HOW_FIND'],
	'JOIN_US'					=> $user->lang['JOIN_US'],
	'INVITE'					=> $user->lang['INVITE'],
	'END_DESC'				=> $user->lang['END_DESC'],
	'DESC'						=> $user->lang['DESC'],
	'AGREE_TERMS'			=> $user->lang['AGREE_TERMS'],
	'GAMES'						=> $user->lang['GAMES_NAME'],
	'MIC'							=> $user->lang['MIC'],
	'DONATE'					=> $user->lang['DONATE'],
	'HOURS'						=> $user->lang['HOURS'],
	'GENDER'					=> $user->lang['GENDER'],
	'TALENTS'					=> $user->lang['TALENTS'],
	'YES'							=> $user->lang['YES'],
	'NO'							=> $user->lang['NO'],
	'MALE'						=> $user->lang['MALE'],
	'FEMALE'					=> $user->lang['FEMALE'],
	'R_NAME'					=> $user->lang['R_NAME'],
	'TELL_US'					=> $user->lang['TELL_US'],
	)
);

$template->set_filenames(array(
	'body' => 'bots/recruit.html')
);

page_footer();
?>
info_recruit.php

Code: Select all

<?php
/** 
*
* example [English]
*
* @package language
* @version $Id: v3_api.xml 52 2007-12-09 19:45:45Z jelly_doughnut $
* @copyright (c) 2007 phpBB Group 
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* DO NOT CHANGE
*/
if (empty($lang) || !is_array($lang))
{
    $lang = array();
}

// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine

$lang = array_merge($lang, array(
    'PAGE_TITLE'            => '=UMA= Recruit Application',
    'FORM_SENT'                => 'Your recruit application has been entered into the system. Thank you for applying!<br />Feel free to make a reply post in your topic.',
    'RETURN_TOPIC'        => '%sGo to your topic%s',
    'R_APP'                        => 'Recruit Application',
    'R_NAME'                    => 'Your real name:',
    'S_NAME'                    => 'Your gamer name:',
    'GAMES_NAME'                    => 'Games you currently play:',
    'AGE'                            => 'Your age. (Lying will exclude you from membership):',
    'AGREE_TERMS'            => 'I agree to follow the clan rules, privacy policy, and terms of use.',
    'CLANS'                        => 'Have you have been in a clan before? If so, what clans, and why did you leave?',
    'HOW_FIND'                => 'How did you find us?',
    'JOIN_US'                    => 'Why do you want to join us?',
    'INVITE'                    => 'Were you invited to join us? If so, by whom?',
    'RETURN_APPLICATION' => '%sReturn to Recruit Application%s',
    'NOT_FILLED_APP'    => 'Please fill out the entire application.',
    'URL'                            => 'http://www.umaclan.com/forum/',
    'NUMBERS_ONLY_AGE'        => 'Only numbers are allowed in the age field.',
    'NUMBERS_ONLY_HOURS'        => 'Only numbers are allowed in the hours field.',
    'BB_BEGIN'                => '[color=#FFBF00][b]',
    'BB_END'                    => '[/b][/color]',
    'USER'                        => 'User:',
    'MIC'                    => 'Do you have a Microphone?',
    'DONATE'            => 'Will you donate to =UMA=? (Game servers cost, website, etc.)',
    'HOURS'                => 'Approximate hours spent online per week?',
    'GENDER'            => 'What\'s your gender?',
    'TALENTS'            => 'Do you have any computer skills? (Web design, Graphics, Hardware, etc.)',
    'YES'                    => 'Yes',
    'NO'                    => 'No',
    'MALE'                => 'Male',
    'FEMALE'            => 'Female',
    'HOURS_WRONG'        => 'You cannot play a game more than 168 hours per week.',
    'NEED_TO_AGREE'            => 'You must agree to follow our terms in order to proceed.',
    'TELL_US'                => 'Tell us a little more about yourself.',

    // Topic title = Username + text below
    'TOPIC'                        => '\'s Application [NEW]',

    // Descriptions
    'DESC'                        => 'We currently are open recruiting (recruiting anyone).<br> If you would like to join us please read the following conditions, and the clan rules.<br><a href="http://www.umaclan.com/rules/bf2142-rules.html">BF2142 Rules</a><br><br><ul><li>We prefer a guidline age of 18+. (Be honest about your age)<br><li>Play online when available.<br><li>Mature personality (I.e. We do not want people who openly abuse people on public servers or chats)<br><li>Always Squad up and work as a Squad.<br><li>Willingness to always wear the Clan Tag.<br><li>We have a 0 tolerance policy against cheats, hacks, or stat padding! You do it, you are out!<br><li>Always play respectfully on whatever server you are on, so as not to bring shame on the clan tags.<br><li>You must have a mic. This is essential to be able to evaluate you and for in game communication and coordination of both squad and team strategies. (Mics are available from many stores for as little as $20-25)<br><li>There are no dues for regular members, but we appreciate donations. Dues for admins are $10 per month and dues for a reserved slot on a server is $5 per month.</ul>',
    'END_DESC'                => 'Wait for an admin or the Recruit Team to answer your post. Once the admin or Recruit Team gives you the go, add our clan recruit/pre-recruit tags to your name: =UMA(pr)=, or =UMA(r)=. After you have done this, we need to see you play regularly on our servers. Squad up with our full members, talk to them, and have a good game. You need a minimum of 3 recommendations by our members to be accepted as a full member; this can take on average a few weeks, or may be over very quickly. When you are a recruit, you are being evaluated by all our full members, Recruit Team, and the admins to make sure you follow the rules, and are a good player. If you break our rules, we will quickly revoke your recruit tags!',
));
?>
recruit.html

Code: Select all

<!-- INCLUDE overall_header.html -->
<form name="send" action="recruit.php" method="post">
<div class="panel">
	<div class="inner"><span class="corners-top"><span></span></span>

	<h2>{R_APP}</h2>

	<fieldset class="fields1">
			<dl><dd><strong>{DESC}</strong></dd></dl>

	<dl>
		<dt><label for="r_name">{R_NAME}</label></dt>
		<dd><input tabindex="1" name="r_name" id="r_name" size="25" class="inputbox autowidth" type="text"></dd>
	</dl>
	<dl>
		<dt><label for="s_name">{S_NAME}</label></dt>
		<dd><input tabindex="1" name="s_name" id="s_name" size="25" class="inputbox autowidth" type="text"></dd>
	</dl>
	<dl>
		<dt><label for="age">{AGE}</label></dt>
		<dd><input type="text" maxlength="2" name="age" id="age" tabindex="2" size="2" class="inputbox autowidth"></dd>
	</dl>
	<dl>
		<dt><label for="gender">{GENDER}</label></dt>
		<dd>
<select name="gender" id="gender" class="inputbox autowidth">
<option value="" SELECTED></option>
<option value="{MALE}">{MALE}</option>
<option value="{FEMALE}">{FEMALE}</option>
</select></dd>
	</dl>
	<dl>
		<dt><label for="hours">{HOURS}</label></dt>
		<dd><input type="text" maxlength="3" name="hours" id="hours" tabindex="2" size="3" class="inputbox autowidth"></dd>
	</dl>
	<dl>
		<dt><label for="donate">{DONATE}</label></dt>
		<dd>
<select name="donate" id="donate" class="inputbox autowidth">
<option value="" SELECTED></option>
<option value="{YES}">{YES}</option>
<option value="{NO}">{NO}</option>
</select></dd>
	</dl>
	<dl>
		<dt><label for="mic">{MIC}</label></dt>
		<dd>
<select name="mic" id="mic" class="inputbox autowidth">
<option value="" SELECTED></option>
<option value="{YES}">{YES}</option>
<option value="{NO}">{NO}</option>
</select></dd>
	</dl>
	<dl>
		<dt><label for="clans">{CLANS}</label></dt>
		<dd><textarea name="clans" id="clans" tabindex="3" rows="4" class="inputbox autowidth"></textarea></dd>
	</dl>
	<dl>
		<dt><label for="games">{GAMES}</label></dt>
		<dd><textarea name="games" id="games" tabindex="4" rows="4" class="inputbox autowidth"></textarea></dd>
	</dl>
	<dl>
		<dt><label for="how_find">{HOW_FIND}</label></dt>
		<dd><textarea name="how_find" id="how_find" tabindex="5" rows="4" class="inputbox autowidth"></textarea></dd>
	</dl>
	<dl>
		<dt><label for="join_us">{JOIN_US}</label></dt>
		<dd><textarea name="join_us" id="join_us" tabindex="6" rows="4" class="inputbox autowidth"></textarea></dd>
	</dl>
	<dl>
		<dt><label for="tell_us">{TELL_US}</label></dt>
		<dd><textarea name="tell_us" id="tell_us" tabindex="6" rows="4" class="inputbox autowidth"></textarea></dd>
	</dl>
	<dl>
		<dt><label for="talents">{TALENTS}</label></dt>
		<dd><textarea name="talents" id="talents" tabindex="6" rows="4" class="inputbox autowidth"></textarea></dd>
	</dl>
	<dl>
		<dt><label for="invite">{INVITE}</label></dt>
		<dd><input type="text" name="invite" id="invite" tabindex="7" size="25" class="inputbox autowidth"></dd>
	</dl>
	<dl>
		<input type="checkbox" name="agree_terms"><label>{AGREE_TERMS}</label>
	</dl>
	</fieldset>

	<span class="corners-bottom"><span></span></span></div>
</div>

<div class="panel">
	<div class="inner"><span class="corners-top"><span></span></span>

	<fieldset class="submit-buttons">
		<input type="reset" class="button1" value="{L_RESET}" />&nbsp;
		<input type="submit" name="submit" class="button1" value="{L_SUBMIT}" />
	</fieldset>

	<span class="corners-bottom"><span></span></span></div>
</div>
</form>
<!-- INCLUDE overall_footer.html -->
For some additional help to understand how these work, take a look at..
phpBB3's Basic Functions
phpBB3's Wiki
If you encounter what is/or you think is a bug, please report it to the phpBB Bug Tracker
Wookie1664
Registered User
Posts: 65
Joined: Mon Jul 07, 2008 12:19 pm

Re: Submit Post Script

Post by Wookie1664 »

Many thanks James, I'm just on my way to bed but will crack on with it first thing in the morning and post back here when done.

Thanks again!

Wookie
Goztow
Registered User
Posts: 365
Joined: Fri Aug 17, 2007 10:31 am
Location: Belgium
Contact:

Re: Submit Post Script

Post by Goztow »

Just wanted to inform you I'll also be having a look on this. It would suit my needs perfectly, from reading the description. Thanks in advance!
Drakken
Registered User
Posts: 144
Joined: Thu Jun 12, 2003 6:59 pm
Contact:

Re: Submit Post Script

Post by Drakken »

This would be perfect for clan applications.
Goztow
Registered User
Posts: 365
Joined: Fri Aug 17, 2007 10:31 am
Location: Belgium
Contact:

Re: Submit Post Script

Post by Goztow »

That's what I use it for :). And works like a charm. Thanks a lot!
User avatar
James78
Registered User
Posts: 811
Joined: Sat Jul 30, 2005 4:54 pm
Location: Washington, USA
Contact:

Re: Submit Post Script

Post by James78 »

Please note that among the many things you'll need to modify in the script to make it suit your needs, the link to the user will NOT work unless you change $username_url, as it creates a link to users when your forum has SEO MOD installed.
If you encounter what is/or you think is a bug, please report it to the phpBB Bug Tracker
Drakken
Registered User
Posts: 144
Joined: Thu Jun 12, 2003 6:59 pm
Contact:

Re: Submit Post Script

Post by Drakken »

Everything seems to be working except when i click submit. I'm getting this error:
[phpBB Debug] PHP Notice: in file /recruit.php on line 99: array_merge() [function.array-merge]: Argument #2 is not an array
User avatar
James78
Registered User
Posts: 811
Joined: Sat Jul 30, 2005 4:54 pm
Location: Washington, USA
Contact:

Re: Submit Post Script

Post by James78 »

Post the code you have for recruit.php
If you encounter what is/or you think is a bug, please report it to the phpBB Bug Tracker
Drakken
Registered User
Posts: 144
Joined: Thu Jun 12, 2003 6:59 pm
Contact:

Re: Submit Post Script

Post by Drakken »

Thanks for the reply.

Code: Select all

<?php
    /**
    *
    * This program will create topics from forms filled
    * out by a user.
    * User: Recruit Robot
    * Forum: Recruit forum
    * Copyright 2008 James78
    *
    */

    define('IN_PHPBB', true);
    $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/functions_posting.' . $phpEx);

    // Set up user session
    $user->session_begin();
    $auth->acl($user->data);

    // Lang...
    $user->setup('mods/info_recruit');

    // If user is not logged in, send them to login page
    if ($user->data['user_id'] == ANONYMOUS)
    {
        login_box('', $user->lang['LOGIN']);
    }

    $submit = (isset($_POST['submit'])) ? true : false;

    if ($submit)
    {
       // They need to fill out the entire application for it to be entered into the system
       if ((request_var('s_name', '', true) && request_var('r_name', '', true) && request_var('mic', '', true) && request_var('donate', '', true) && request_var('hours', '', true) && request_var('gender', '', true) && request_var('talents', '', true) && request_var('age', '', true) && request_var('how_find', '', true) && request_var('join_us', '', true) && request_var('games', '', true) && request_var('clans', '', true) && request_var('invite', '', true) && request_var('tell_us', '', true)) == '')
       {
          $meta_info = 'recruit.php';
          $message = $user->lang['NOT_FILLED_APP'] . '<br /><br />' . sprintf($user->lang['RETURN_APPLICATION'], '<a href="' . $meta_info . '">', '</a>');
          meta_refresh(4, $meta_info);
          trigger_error($message);
       }

       // If user doesn't enter number, trigger error message
       if (!is_numeric(request_var('age', '', true)))
       {
          $meta_info = 'recruit.php';
          $message = $user->lang['NUMBERS_ONLY_AGE'] . '<br /><br />' . sprintf($user->lang['RETURN_APPLICATION'], '<a href="' . $meta_info . '">', '</a>');
          meta_refresh(4, $meta_info);
          trigger_error($message);
       }

       // If user doesn't enter number, trigger error message
       if (!is_numeric(request_var('hours', '', true)))
       {
          $meta_info = 'recruit.php';
          $message = $user->lang['NUMBERS_ONLY_HOURS'] . '<br /><br />' . sprintf($user->lang['RETURN_APPLICATION'], '<a href="' . $meta_info . '">', '</a>');
          meta_refresh(4, $meta_info);
          trigger_error($message);
       }

       // You can't play a game more than 168 hours per week. This is defined by the laws of physics themself
       if (request_var('hours', '', true) > '168')
       {
          $meta_info = 'recruit.php';
          $message = $user->lang['HOURS_WRONG'] . '<br /><br />' . sprintf($user->lang['RETURN_APPLICATION'], '<a href="' . $meta_info . '">', '</a>');
          meta_refresh(4, $meta_info);
          trigger_error($message);
       }

       // If they didn't agree to our terms...
       if (!$_POST['agree_terms'])
       {
          $meta_info = 'recruit.php';
          $message = $user->lang['NEED_TO_AGREE'] . '<br /><br />' . sprintf($user->lang['RETURN_APPLICATION'], '<a href="' . $meta_info . '">', '</a>');
          meta_refresh(4, $meta_info);
          trigger_error($message);
       }

       $username_url = $user->lang['URL'] . $user->data['username_clean'] ."-u" . $user->data['user_id'] . ".html";
       $username = $user->data['username'];
       $o_user_id = $user->data['user_id'];
       $o_user_ip = $user->ip;

       $my_subject = $username . $user->lang['TOPIC'];

       // UserID = UserID of Recruit Bot
       $user_id = '135';

       // Overwrite with new data
       $sql = 'SELECT *
          FROM ' . USERS_TABLE . '
                WHERE user_id = ' . $user_id;
       $result = $db->sql_query($sql);
       $row = $db->sql_fetchrow($result);
       $db->sql_freeresult($result);

       $user->data = array_merge($user->data, $row);
       $auth->acl($user->data);

       //Overwrite users IP
       $user->ip = '0.0.0.0';

       // subject and message
       $my_message      = $user->lang['BB_BEGIN'] . $user->lang['USER'] . $user->lang['BB_END'] . "\n[url=" . $username_url . "]" . $username . "[/url]\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['R_NAME'] . $user->lang['BB_END'] . "\n" . request_var('r_name', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['S_NAME'] . $user->lang['BB_END'] . "\n" . request_var('s_name', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['AGE'] . $user->lang['BB_END'] . "\n" . request_var('age', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['GENDER'] . $user->lang['BB_END'] . "\n" . request_var('gender', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['HOURS'] . $user->lang['BB_END'] . "\n" . request_var('hours', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['DONATE'] . $user->lang['BB_END'] . "\n" . request_var('donate', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['MIC'] . $user->lang['BB_END'] . "\n" . request_var('mic', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['CLANS'] . $user->lang['BB_END'] . "\n" . request_var('clans', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['GAMES_NAME'] . $user->lang['BB_END'] . "\n" . request_var('games', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['HOW_FIND'] . $user->lang['BB_END'] . "\n" . request_var('how_find', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['JOIN_US'] . $user->lang['BB_END'] . "\n" . request_var('join_us', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['TELL_US'] . $user->lang['BB_END'] . "\n" . request_var('tell_us', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['TALENTS'] . $user->lang['BB_END'] . "\n" . request_var('talents', '', true) . "\n\n";
       $my_message      .= $user->lang['BB_BEGIN'] . $user->lang['INVITE'] . $user->lang['BB_END'] . "\n" . request_var('invite', '', true);

       $my_subject      = utf8_normalize_nfc($my_subject);
       $my_message      = utf8_normalize_nfc($my_message);

       // variables to hold the parameters for submit_post
       $poll = $uid = $bitfield = $options = '';

       generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
       generate_text_for_storage($my_message, $uid, $bitfield, $options, true, true, true);

       // Data array
       $data = array(
          'forum_id'      => 6,
          'icon_id'      => false,

          'enable_bbcode'      => true,
          'enable_smilies'   => true,
          'enable_urls'      => true,
          'enable_sig'      => true,

          'message'      => $my_message,
          'message_md5'   => md5($my_message),

          'bbcode_bitfield'   => $bitfield,
          'bbcode_uid'      => $uid,

          'post_edit_locked'   => 0,
          'topic_title'      => $my_subject,
          'notify_set'      => false,
          'notify'         => false,
          'post_time'       => 0,
          'forum_name'      => 'Recruiting',
          'enable_indexing'   => true,
          'topic_time_limit' => 0,
          'topic_approved' => true,
          'post_time' => 0,
       );

       // Mode - Subject - username (only if guest poster) - topic type - poll - post data - update message
       // We are creating a new topic
       submit_post('post', $my_subject, '', POST_NORMAL, $poll, $data);

       // set original user back!
       $sql = 'SELECT *
          FROM ' . USERS_TABLE . '
                WHERE user_id = ' . $o_user_id;
       $result = $db->sql_query($sql);
       $row = $db->sql_fetchrow($result);
       $db->sql_freeresult($result);

       $user->data = array_merge($user->data, $row);
       $auth->acl($user->data);

       //Overwrite users IP to normal
       $user->ip = $o_user_ip;

       // Trigger success message
       $meta_info = append_sid("{$phpbb_root_path}viewtopic." . $phpEx ."?t=" . $data['topic_id']);
       $message = $user->lang['FORM_SENT'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
       meta_refresh(4, $meta_info);
       trigger_error($message);
    }

    // Page title
    page_header($user->lang['PAGE_TITLE']);

    $template->assign_vars(array(
       'R_APP'                  => $user->lang['R_APP'],
       'S_NAME'               => $user->lang['S_NAME'],
       'AGE'                     => $user->lang['AGE'],
       'AGREE_TERMS'         => $user->lang['AGREE_TERMS'],
       'CLANS'                  => $user->lang['CLANS'],
       'HOW_FIND'            => $user->lang['HOW_FIND'],
       'JOIN_US'               => $user->lang['JOIN_US'],
       'INVITE'               => $user->lang['INVITE'],
       'END_DESC'            => $user->lang['END_DESC'],
       'DESC'                  => $user->lang['DESC'],
       'AGREE_TERMS'         => $user->lang['AGREE_TERMS'],
       'GAMES'                  => $user->lang['GAMES_NAME'],
       'MIC'                     => $user->lang['MIC'],
       'DONATE'               => $user->lang['DONATE'],
       'HOURS'                  => $user->lang['HOURS'],
       'GENDER'               => $user->lang['GENDER'],
       'TALENTS'               => $user->lang['TALENTS'],
       'YES'                     => $user->lang['YES'],
       'NO'                     => $user->lang['NO'],
       'MALE'                  => $user->lang['MALE'],
       'FEMALE'               => $user->lang['FEMALE'],
       'R_NAME'               => $user->lang['R_NAME'],
       'TELL_US'               => $user->lang['TELL_US'],
       )
    );

    $template->set_filenames(array(
       'body' => 'bots/recruit.html')
    );

    page_footer();
?>
Locked

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