TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,004
  • Total Topics: 21,330
  • Online today: 247
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 176
  • Total: 176

fill out application -- only if registered user?

Started by jbotto, January 10, 2009, 05:45:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jbotto

Hey folks!

On my site, I have an application (seen here: http://www.det-1.com/index.php?page=12) which automatically posts into a section of my forum upon completion.

I have received to applications, posted as 'Guest' in my forum.

I would like to make the application so that you must be a registered user in order to submit.

Here is the code:
global $sourcedir, $user_info, $context ;

require_once($sourcedir . '/Subs.php');
require_once($sourcedir .'/Subs-Post.php');



// CONFIGURATION SECTION

//send the application by email?
$enable_email=false;

// email address of reqruitment staf member
$email_address='red-mike@det-1.com';

//post the application on forum?
$enable_post=true;

//board id to which the application should be posted
$board_id= '19.0';

//the id of the this article
$this_article_id = 'application';

//article to be redirected when form is submitted
$thank_you_article_id = '14';


//END OF CONFIGURATION SECTION

$show_form= 'true';
if (isset($_POST['submitted'])) {
// Handle the form

// Check required fields
$enroll_errors = array(); //Initialize error array

// Check for a name
if (empty($_POST['real_name']) ){
$enroll_errors[] = 'You forgot to enter your name.';
}
// Check for an email
if (empty($_POST['email']) ){
$enroll_errors[] = 'You forgot to enter your email address.';
}
// Check for a PSN id
if (empty($_POST['psn_id']) ){
$enroll_errors[] = 'You forgot to enter your Playstation Netword ID.';
}
// Check for an age
if (empty($_POST['age']) ){
$enroll_errors[] = 'You forgot to enter your age.';
}

if (empty($enroll_errors)) { //Everything seems to be OK

        $show_form='false';



// email an application

$subject = 'Enrollment Application';
$body = 'Enrollment application has been made by ' . $context['user']['name'] .
' from IP Address ' . $user_info['ip'] . '
Name (LastInitial, First Name):  ' . $_POST['real_name'] . '
Email address:  ' . $_POST['email'] . '
Playstation Network ID:  ' . $_POST['psn_id'] . '
Age:  ' . $_POST['age'] . '
Gender: ' . $_POST['gender'] . '
Location:  ' . $_POST['location'] . '
Current Level:  ' . $_POST['honor'] . '
Previous Clan(s):  ' . $_POST['prev_clans'] . '
So you have any clan leadership experience?:  ' . $_POST['lead'] . '
How much gaming experience do you have?:  ' . $_POST['experience'] . '
How much experience do you have with the SOCOM franchise specifically?:  ' . $_POST['socom_experience'] . '
Describe you playing style:  ' . $_POST['style'] . '
How often do you play?:  ' . $_POST['often'] . '
Are you competative? To what extent?:  ' . $_POST['compete'] . '
Do you have a microphone/headset:  ' . $_POST['mic'] . '
Have you read our Code of Conduct: ' . $_POST['coc'] . '
Why do you want to join our Clan?:  ' . $_POST['why'] . '
Do you know anyone in Det 1?:   ' . $_POST['know'] . '
Is there any other information which you think may help us make our decision?:  ' . $_POST['other'];

$postbody = 'Enrollment application has been made by ' . $context['user']['name'] .'
[table]
[tr][td]Name (LastInitial, First Name):[/td][td] ' . $_POST['real_name'] . '[/td][/tr]
[tr][td]Email address:[/td][td] ' . $_POST['email'] . '[/td][/tr]
[tr][td]Playstation Network ID:[/td][td] ' . $_POST['psn_id'] . '[/td][/tr]
[tr][td]Age:[/td][td] ' . $_POST['age'] . '[/td][/tr]
[tr][td]Gender:[/td][td] ' . $_POST['gender'] . '[/td][/tr]
[tr][td]Location:[/td][td] ' . $_POST['location'] . '[/td][/tr]
[tr][td]Current Level:[/td][td] ' . $_POST['honor'] . '[/td][/tr]
[tr][td]Previous Clan(s):[/td][td] ' . $_POST['prev_clans'] . '[/td][/tr]
[tr][td]So you have any clan leadership experience?[/td][td] ' . $_POST['lead'] . '[/td][/tr]
[tr][td]How much gaming experience do you have?[/td][td] ' . $_POST['experience'] . '[/td][/tr]
[tr][td]How much experience do you have with the SOCOM franchise specifically?[/td][td] ' . $_POST['socom_experience'] . '[/td][/tr]
[tr][td]Describe you playing style:[/td][td] ' . $_POST['style'] . '[/td][/tr]
[tr][td]How often do you play?[/td][td] ' . $_POST['often'] . '[/td][/tr]
[tr][td]Are you competative? To what extent?[/td][td] ' . $_POST['compete'] . '[/td][/tr]
[tr][td]Do you have a microphone/headset:[/td][td] ' . $_POST['mic'] . '[/td][/tr]
[tr][td]Have you read our Code of Conduct:[/td][td] ' . $_POST['coc'] . '[/td][/tr]
[tr][td]Why do you want to join our Clan?[/td][td] ' . $_POST['why'] . '[/td][/tr]
[tr][td]Do you know anyone in Det 1?[/td][td] ' . $_POST['know'] . '[/td][/tr]
[tr][td]Is there any other information which you think may help us make our decision?[/td][td] ' . $_POST['other']. '[/td][/tr]
[/table]';



            if ($enable_email)
mail($email_address, $subject, $body,"From: " . $_POST['email']);



//create new forum post with application

$msgOptions = array(
'id' =>  0 ,
'subject' => '[Pending] Application of ' . $context['user']['name'],
'body' => $postbody ,
'icon' => 'xx',
'smileys_enabled' => true,
'attachments' =>  array(),
);
$topicOptions = array(
'id' => 0 ,
'board' => $board_id,
'poll' =>  null,
'lock_mode' =>  null,
'sticky_mode' =>  null,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => $context['user']['id'],
'name' => $context['user']['name'],
'email' => $user_info['email'],
'update_post_count' => true,
);

if ($enable_post)
            createPost($msgOptions, $topicOptions, $posterOptions);

// Redirect to thank you page
header('Location: http://www.det-1.com/index.php?page=thankyou' );

} else {
// Redirect to error page
//header('Location: http://' . $_SERVER['HTTP_HOST'] . '/index.php?page=' . $enroll_error_article_id );
echo '<h2 class="error">Error!</h2>';
echo '<p class="error">The following error(s) occured:<br />';

foreach ($enroll_errors as $msg) {
echo " - $msg<br />";
}
   echo "<p>Please, correct all errors and try again.</p>" ;



}
}
//else { // Display the form

echo '
<form action="index.php?page='  . $this_article_id  . '" method="post">
        <INPUT id="submitted" name="submitted" type="hidden" value="TRUE" />
<TABLE class = "bordercolor" cellSpacing="1" cellPadding="1" width="95%" border="0">
<TR class ="windowbg">
<TD width = "200px"><b>Please only fill out and submit this form if you have read the <a href="http://www.det-1.com/index.php?topic=7.0">Application Process!</a></b></TD>
</TR>
              <TABLE class = "bordercolor" cellSpacing="1" cellPadding="1" width="95%" border="0">
<TR class ="windowbg">
<TD width = "200px">* Name (LastInitial, First Name):</TD>
<TD><INPUT id="real_name" name="real_name" type="text" value ="';
if (isset($_POST['real_name'])) echo $_POST['real_name'];
echo '" /></TD>
</TR>
<TR class ="windowbg2">
<TD width = "200px">* Email address:</TD>
<TD><INPUT id="email" name="email" type="text" value ="';
if (isset($_POST['email'])) echo $_POST['email']; else echo $user_info['email'];
echo '" /></TD>
</TR>
<TR class ="windowbg">
<TD width = "200px">* Playstation Network ID:</TD>
<TD><INPUT id="psn_id" name="psn_id" type="text" value ="';
if (isset($_POST['psn_id'])) echo $_POST['psn_id'];
echo '" /></TD>
</TR>
<TR class ="windowbg2">
<TD width = "200px">* Age:</TD>
<TD><INPUT id="age" name="age" type="text" value ="';
if (isset($_POST['age'])) echo $_POST['age'];
echo '" /></TD>
</TR>
<TR class ="windowbg">
<TD width = "200px">Gender:
</TD>
<TD><SELECT id = "gender" name = "gender" style="WIDTH: 152px" value ="';
if (isset($_POST['gender'])) echo $_POST['gender'];
echo '" />
<OPTION value="No Answer" selected>--------------------------</OPTION>
<OPTION value="M">Male</OPTION>
<OPTION value="F">Female</OPTION>
</SELECT></TD>
</TR>
<TR class ="windowbg2">
<TD width = "200px">Location:</TD>
<TD><INPUT id="location" name="location" type="text" value ="';
if (isset($_POST['location'])) echo $_POST['location'];
echo '" /></TD>
</TR>
<TR class ="windowbg">
<TD width = "200px">Current Level:</TD>
<TD><INPUT id="honor" name="honor" type="text" value ="';
if (isset($_POST['honor'])) echo $_POST['honor'];
echo '" /></TD>
</TR>
<TR class ="windowbg2">
<TD width = "200px">Previous Clan(s) and reasons for leaving:</TD>
<TD><TEXTAREA id="prev_clans" name="prev_clans" rows="4" cols="40" value ="';
if (isset($_POST['prev_clans'])) echo $_POST['prev_clans'];
echo '" ></' . 'TEXTAREA></TD>
</TR>
<TR class ="windowbg">
<TD width = "200px">So you have any clan leadership experience?:</TD>
<TD><TEXTAREA id ="lead" name ="lead" rows="4" cols="40"  value ="';
if (isset($_POST['lead'])) echo $_POST['lead'];
echo '" ></' . 'TEXTAREA></TD>
</TR>
<TR class ="windowbg2">
<TD width = "200px">How much gaming experience do you have?</TD>
<TD><TEXTAREA id="experience" name="experience" rows="4" cols="40" value ="';
if (isset($_POST['experience'])) echo $_POST['experience'];
echo '" ></' . 'TEXTAREA></TD>
</TR>
<TR class ="windowbg">
<TD width = "200px">How much experience do you have with the SOCOM franchise specifically?</TD>
<TD><INPUT id="socom experience" name="socom experience" type="text" value ="';
if (isset($_POST['socom_experience'])) echo $_POST['socom_experience'];
echo '" /></TD>
</TR>
<TR class ="windowbg2">
<TD width = "200px">Describe you playing style:</TD>
<TD><TEXTAREA id="style" name="style" rows="4" cols="40" value ="';
if (isset($_POST['style'])) echo $_POST['style'];
echo '" ></' . 'TEXTAREA></TD>
</TR>
<TR class ="windowbg">
<TD width = "200px">How often do you play?</TD>
<TD><INPUT id="often" name="often" type="text" value ="';
if (isset($_POST['often'])) echo $_POST['often'];
echo '" /></TD>
</TR>
<TR class ="windowbg">
<TD width = "200px">Are you competative? To what extent?</TD>
<TD><TEXTAREA id="compete" name ="compete" rows="4" cols="40" value ="';
if (isset($_POST['compete'])) echo $_POST['compete'];
echo '" ></' . 'TEXTAREA></TD>
</TR>
<TR class ="windowbg">
<TD width = "200px">Do you have a microphone/headset?</TD>
<TD><SELECT id="mic" name="mic" style="WIDTH: 160px" value ="';
if (isset($_POST['mic'])) echo $_POST['mic'];
echo '" />
<OPTION value="No answer" selected>--------------------------</OPTION>
<OPTION value="YES">Yes</OPTION>
<OPTION value="NO">No</OPTION>
</SELECT></TD>
</TR>
<TR class ="windowbg2">
<TD width = "200px">Have you read our Code of Conduct?</TD>
<TD><SELECT id="coc" name="coc" style="WIDTH: 160px" value ="';
if (isset($_POST['coc'])) echo $_POST['coc'];
echo '" />
<OPTION value="no answer" selected>--------------------------</OPTION>
<OPTION value="recently">Yes, just recently.</OPTION>
<OPTION value="will">No, but I will now.</OPTION>
<OPTION value="no">No, I have not seen it.</OPTION>
</SELECT></TD>
</TR>
<TR class ="windowbg">
<TD width = "200px">Why do you want to join Det 1?</TD>
<TD><TEXTAREA id="why" name ="why" rows="4" cols="40" value ="';
if (isset($_POST['why'])) echo $_POST['why'];
echo '" ></' . 'TEXTAREA></TD>
</TR>
<TR class ="windowbg2">
<TD width = "200px">Do you know anyone in Det 1?</TD>
<TD><TEXTAREA id="know" name="know" rows="4" cols="40" value ="';
if (isset($_POST['know'])) echo $_POST['know'];
echo '" ></' . 'TEXTAREA></TD>
</TR>
<TR class ="windowbg">
<TD width = "200px">Is there any other information which you think may help us make our decision?</TD>
<TD><TEXTAREA id="other" name = "other" rows="4" cols="40" value ="';
if (isset($_POST['other'])) echo $_POST['other'];
echo '" ></' . 'TEXTAREA></TD>
</TR>
<TR class ="windowbg2">
<TD colspan="2" align="center">
<INPUT type="submit" value="Submit">
<INPUT type="reset" value="Reset"></TD>
</TR>
</TABLE>
</form>

';

I would love it if I could modify the code so that if you are a registered user, it allows you to submit, but if not, it will not let you.

Thank you!

JPDeni

After your "global" line, add


if ($user_info['is_guest'])
  exit;


If you want to give the guest a message about why they can't fill out the form, you can use


if ($user_info['is_guest']) {
  echo "Only registered users can access the form.";
  exit;
}


Of course, you can change the text to whatever you want.

Omniverse

Or perhaps you could just disallow guests from posting?  Through the normal SMF admin.

You could also do something like...

Add this:

if ($context['user']['is_logged'])
{
echo '
your stuff here
'
}
else
{
echo '
You must be logged in to do that... or whatever ya want.
'
}

IchBin

Or you could simple turn the block off for guests so they can't even see it.

JPDeni

Omniverse, the code that I posted does the same thing, but is simpler because all of the code for members doesn't have to be in an "if" statement.

IchBin, this is not a block, but an article. And he's using TP .98, so he can't turn off articles for guests.

This website is proudly hosted on Crocweb Cloud Website Hosting.