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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,911
  • Total Topics: 21,307
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 359
  • Total: 360
  • tino

Generic Application Form

Started by JPDeni, May 23, 2009, 11:04:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ZarPrime

GreenEyed,

Could you please post the code you are using for the form in your next post here using the code tags so that we can take a look at it.

ZarPrime

GreenEyed

I went back to our base code, without the frills, to make sure it wasn't an issue there, still won't send an email.  Here is that code. 

global $sourcedir, $context, $scripturl, $user_info;
// Generic Application Form
// URL: http://www.tinyportal.net/index.php?topic=29670.msg236779#msg236779
// Date: 30 November 2009

// Guests can't fill out the form
if ($context['user']['id'] == 0)
    echo 'You must be logged in before you can apply.  Please register and try again.';
else {
   require_once($sourcedir . '/Subs.php');
   require_once($sourcedir .'/Subs-Post.php');


// CONFIGURATION SECTION

   $intro_form = "Think you have what it takes?  Fill out this application and a recruiter will email you soon. If a question does not apply, please enter 'NA'.";
   $thanks_text = "Thank you for applying with =VX9=.  You will be contacted shortly.";

// Define your fields. All of these values need to be defined, even if they are empty.
// The fields will be displayed in the order in which they are listed in the array.
// $fielddef =
//   array(
//     array(
//       'caption' =>      "", // caption to be displayed on the form. Can include symbols and spaces.
//       'name' =>         "", // a unique name for the field. No symbols or spaces
//       'type' =>         "", // text, radio, select, checkbox, textarea, heading
//       'options' =>      "", // for radio and select fields. List in order you wish them to appear, separated by commas; for checkboxes, it's the value to be saved and displayed next to the box
//       'defaultvalue' => "", // the default value for the field. Can be a variable or text. Be sure to enclose text in quotation marks
//       'required' =>     0   // 0 or 1 -- use 1 if the field must be filled out. use 0 if it's optional; never set a checkbox to be required
//     ),
//   );

   $fielddef =
      array(
         array(
            'caption' =>      "Recruit Application",
            'name' =>         "heading",
            'type' =>         "heading",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0
         ),
         array(
            'caption' =>      "Name",
            'name' =>         "realname",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
          array(
            'caption' =>      "Email address",
            'name' =>         "Email",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
          array(
            'caption' =>      "In Game Name",
            'name' =>         "Nickname",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
         array(
            'caption' =>      "How did you hear about =VX9=?",
            'name' =>         "Marketing",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
array(
            'caption' =>      "What game are you applying for?",
            'name' =>         "Game",
            'type' =>         "select",
            'options' =>      "Battlefield Series, Call of Duty Series, Valve Series, America's Army, Console Division(Xbox 360, etc), Planetside 2, World of Tanks, ",
            'defaultvalue' => "Battlefield Series",
            'required' =>     1
),

          array(
            'caption' =>      "Age",
            'name' =>         "age",
            'type' =>         "select",
            'options' =>      "13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40+",
            'defaultvalue' => "18",
            'required' =>     1
         ),     
         array(
            'caption' =>      "Sex",
            'name' =>         "sex",
            'type' =>         "radio",
            'options' =>      "M,F",
            'defaultvalue' => "",
            'required' =>     0
         ),
         array(
            'caption' =>      "Location",
            'name' =>         "Location",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
         array(
            'caption' =>      "Choose your gaming system",
            'name' =>         "system",
            'type' =>         "select",
            'options' =>      "PC, XBox, PS3",
            'defaultvalue' => "PC",
            'required' =>     1
         ),

  array(
            'caption' =>      "Registered with Battlelog?",
            'name' =>         "battlelog",
            'type' =>         "radio",
            'options' =>      "Yes, No",
            'defaultvalue' => "",
            'required' =>     0
         ),
          array(
            'caption' =>      "Battlelog Name",
            'name' =>         "BattlelogName",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),

         array(
            'caption' =>      "Registered with xFire?",
            'name' =>         "xfire",
            'type' =>         "radio",
            'options' =>      "Yes, No",
            'defaultvalue' => "",
            'required' =>     0
         ),
          array(
            'caption' =>      "xFire Name",
            'name' =>         "xFireName",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),
         array(
            'caption' =>      "Registered with Steam?",
            'name' =>         "Steam",
            'type' =>         "radio",
            'options' =>      "Yes, No",
            'defaultvalue' => "",
            'required' =>     0
         ),
          array(
            'caption' =>      "Steam ID - NOT Steam name!",
            'name' =>         "SteamID",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),
          array(
            'caption' =>      "XBox Gamertag",
            'name' =>         "Gamertag",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),
          array(
            'caption' =>      "PS3 Name",
            'name' =>         "PS3Name",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),
          array(
            'caption' =>      "Previous Clan(s)",
            'name' =>         "PreviousClans",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),
         array(
            'caption' =>      "Have you ever been VAC or PB banned?",
            'name' =>         "banning",
            'type' =>         "radio",
            'options' =>      "Yes, No",
            'defaultvalue' => "",
            'required' =>     0
         ),
          array(
            'caption' =>      "If so, please explain.",
            'name' =>         "Bullshit",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),
         array(
            'caption' =>      "Do you have voice communication ability? (Mic, Headset, Teamspeak)",
            'name' =>         "Teamspeak",
            'type' =>         "radio",
            'options' =>      "Yes, No",
            'defaultvalue' => "",
            'required' =>     0
         ),
         array(
            'caption' =>      "Would you be willing to donate to help pay for servers?",
            'name' =>         "Donate",
            'type' =>         "radio",
            'options' =>      "Yes, No, Occasionally",
            'defaultvalue' => "",
            'required' =>     0
         ),
         array(
            'caption' =>      "How often do you play?",
            'name' =>         "GamingHabits",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1
         ),
         array(
            'caption' =>      "Why do you want to join =VX9=?",
            'name' =>         "Why",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1
         ),
      );



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

// email address of recruitment staff member
   $email_address='recruitsapp@vx9.com';

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

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

// Poll options
$add_poll = 0; // 0 = No poll; 1 = add poll
$poll_question = "Accept this member?"; // This is the question for the poll
$expireTime = 0; // Change this to the number of days you want the poll to run
$hideResults = 0; // 0 = Results are always visible; 1 = Can see results only after voting; 2 = Can see results only after poll expires
$changeVote = 0; // 0 = Voters can not change their votes; 1 = Voters can change their votes
$poll_choices = array('Yes','No'); // The options listed for the poll

//END OF CONFIGURATION SECTION
////////////////////////////////////////////////////////////////////////////////////////////


   $show_form= 'true';
   if (isset($_REQUEST['submitted'])) {  // Handle the form
// Check required fields
      $errors = array(); //Initialize error array   

      foreach ($fielddef as $field)
         if (empty($_REQUEST[$field['name']]) && ($field['required'] == 1)){ $errors[] = $field['name']; }
   
// There's at least one field missing
      if (isset($errors[0])) {
         foreach ($_REQUEST as $key => $value)
         $fieldvalue[$key] = $value;
      }
      else { // all is well
 
         $show_form='false';

         if ($enable_email)   {  // email an application
            $subject = 'Application';
            $body = '';
            foreach ($fielddef as $field) {
               if ($field['type'] == 'heading')
                  $body .= $field['caption'] . '
               ';
               else
                  $body .= $field['caption'] . ': ' . $_REQUEST[$field['name']] . '
               ';
            }
            mail($email_address, $subject, $body,"From: " . $user_info['email']);
         }

         if ($enable_post) {  //create new forum post with application
if ($add_poll === 1) {
$posterName = $context['user']['name'];
if ($expireTime > 0)
$expireTime = time() + $expireTime * 3600 * 24;
db_query("
INSERT INTO {$db_prefix}polls
(question, hideResults, maxVotes, expireTime, ID_MEMBER, posterName, changeVote)
VALUES ('$question', '$hideResults', '1', '$expireTime', '$ID_MEMBER', '$posterName', '$changeVote')", __FILE__, __LINE__);
$ID_POLL = db_insert_id();

// Create each answer choice.
$i = 0;
$setString = '';
foreach ($poll_choices as $option)
{
$setString .= "
('$ID_POLL', '$i', SUBSTRING('$option', 1, 255)),";
$i++;
}

db_query("
INSERT INTO {$db_prefix}poll_choices
(ID_POLL, ID_CHOICE, label)
VALUES" . substr($setString, 0, -1), __FILE__, __LINE__);

}
else
$ID_POLL = null;

            $postbody = 'Recruitment application has been made by ' . $context['user']['name'] .'<br /><br/>';
foreach ($fielddef as $field) {
                                       if ($field['type'] == 'heading')
$postbody .= $field['caption'] . '<br />';
elseif ($field['caption'] == 'Comments')
$postbody .= '[b][color=red]' . $field['caption'] . '[/color][/b]: ' . $_REQUEST[$field['name']] . '<br />';
else
$postbody .= '[b]' . $field['caption'] . '[/b]: ' . $_REQUEST[$field['name']] . '<br />';
}

            $msgOptions = array(
               'id' =>  0 ,
               'subject' => '[Pending] Application of ' . addslashes($_REQUEST['Nickname']),
               'body' => addslashes($postbody) ,
               'icon' => 'xx',
               'smileys_enabled' => true,
               'attachments' =>  array(),
            );
            $topicOptions = array(
               'id' => 0 ,
               'board' => $board_id,
               'poll' =>  $ID_POLL,
               '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,
            );
            createPost($msgOptions, $topicOptions, $posterOptions);
         }
// Text for thank you page
         echo $thanks_text;
      }
   }
   else {
      foreach ($fielddef as $field) {
         $fieldvalue[$field['name']] = $field['defaultvalue'];
      }
   }

// Looks like you want the form,
   if ($show_form == 'true') {
      echo $intro_form . "<br>";
      if (isset($errors[0])) { echo '<div style="color: red;">Please fill in all fields with a *.</div>';  }

      echo '
   <form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
      <INPUT name="submitted" type="hidden" value="TRUE" />
        <table style="margin-left:auto; margin-right:auto;">';

      $bg = 'windowbg2';

      foreach ($fielddef as $field) {
// Headings have their own type of display
         if ($field['type'] == 'heading') {
            echo '
         <TR>
            <TD colspan="2" style="text-align: center; text-decoration: underline;">' .
               $field['caption'] . '
            </TD>
         </TR>';
         }

         else {

// How each field is displayed in the table
            echo '
         <TR class ="' . $bg . '">
            <TD align="right">';
              if ($field['required'] == 1) { echo '* '; }
              echo $field['caption'] . ':
            </TD>
            <TD align="left">';

// Go through each field type
            if ($field['type'] == 'text') {
               echo '<INPUT name="' . $field['name'] . '" type="text" value ="' . $fieldvalue[$field['name']] . '" />';
            }
            elseif ($field['type'] == 'radio') {
               $options = explode(',',$field['options']);
               foreach ($options as $option) {
                  echo '<INPUT TYPE="RADIO" NAME="' . $field['name'] . '" VALUE="'. $option . '"';
                  if ((isset($fieldvalue[$field['name']])) && ($option == $fieldvalue[$field['name']])) { echo ' CHECKED'; }
                  echo '>' . $option . ' ';
               }
            }
            elseif ($field['type'] == 'checkbox') {
               echo '<INPUT TYPE="CHECKBOX" NAME="' . $field['name'] . '" VALUE="'. $field['options'] . '"';
               if (isset($fieldvalue[$field['name']]) && ($fieldvalue[$field['name']]==$field['options'])) { echo ' CHECKED'; }
               echo '>' . $field['options']; 
            }
            elseif ($field['type'] == 'select') {
               echo '<SELECT name="' . $field['name'] . '" />';
               $options = explode(',',$field['options']);
               foreach ($options as $option) {
                  echo '<OPTION value="' . $option . '"';
                  if ((isset($fieldvalue[$field['name']])) && ($option == $fieldvalue[$field['name']])) { echo ' selected'; }
                  echo '>' . $option . '</OPTION>';
               }
               echo '</SELECT>';
            }   
            elseif ($field['type'] == 'textarea') {
               echo '<TEXTAREA name="' . $field['name'] . '" rows="4" cols="40">';
               echo $fieldvalue[$field['name']];
               echo '</' . 'TEXTAREA>';
            }

// Finish off the row
            echo '
            </TD>
         </TR>';
         }

// Set up the alternating colors for the next row
         ($bg == 'windowbg2') ? $bg = 'windowbg' : $bg = 'windowbg2';
      }

      echo '
         <TR class ="' . $bg . '">
            <TD colspan="2" align="center">
               <INPUT type="submit" value="Submit">
               <INPUT type="reset" value="Reset">
            </TD>
         </TR>
      </TABLE>
   </form>';
   }
}

IchBin

Run the attached file from the root of your SMF forum folder. Make sure you edit the file and change the email on the first line of code to be your own email. Then in your browser go to the file on your site (For example: www.yoursite.com/forum/testMail.php). It should attempt to send 3 different emails to your email. If you do not receive all of them, you may have a host configuration problem with your PHP mail.

If you get all of the emails there is probably a problem in the code.

GreenEyed

No go for the test mails.  I will dig into the PHPmail issue then.

Thanks much, all!

GreenEyed

Okay guys, I have it working now!  :D  It was an issue on cpanel and we have emails going out.  Much obliged, Ich!

IchBin

woohoo. Glad you got it working.

GreenEyed

Okay, next question.

Is it possible with that Form to be able to post to different boards based on the answer to one of the questions?

ZarPrime

Hi GreenEyed,

The code is not really designed to do that.  It is written so that the application can be saved to a single board.

For instance, from the code you posted, in your "Game" array, you have a choice of 7 selections.  I assume that you are wanting to have the application saved to a particular board based on the answer to that question, or maybe it's another array you are talking about.  Anyway, this would be problematic and is just not possible with the code as written.  Additional coding could possibly be done to allow this but it would take quite a bit of additional code to be able to do that.  You'd have to have additional board_id's defined so that additional boards could be specified and then each array would have to have another field  added, etc.  This is a lot more work than I am willing to get into and would require quite a bit of testing to make sure that it works correctly.  If there was a problem with the code as written, I might consider it but the code works well as it is now.

An easier option for something like this would be, as an Admin, to just move the posted applications to the correct boards on a daily basis.  Or, you could assign one of your helpers to move the applications to the appropriate board after you give them permission to move topics.  Editing this code is just not something that I really care to get into at this point, and I doubt that anyone else would want to get into this either.  Sorry. :o

ZarPrime

GreenEyed

Yes, I've been moving them manually, which isn't so bad.  You answered my main question though, so I know it's possible.  I wouldn't expect you fine folks to go into that much work, but this gives me something to do in my spare time as I'm learning this.  I keep an updated copy of our site running on my local machine so I can change, screwup, blow up, or fix this without it being live.

As I delve into this I may have more specific questions, but I really appreciate how helpful you all are.  It's made me want to learn this if for nothing more than the challenge. 

Thank you, Zar and Ich, you two are pretty darn awesome in my book!  O0

leroymcqy

Link to my forum: http://www. animenewsinc. net/
SMF version: 2.0.4
TP version: 1.107
Default Forum Language: english
Theme name and version: bad company 3
Browser Name and Version: firefox latest version
Mods installed: trying to use the application block
Related Error messages: TPSubs.php(1739) : eval()'d code
Line: 152

when i use the code given i am given this error :
TPSubs.php(1739) : eval()'d code
Line: 152


its when i try to post to a forum that exists. i am not sure how to fix it. i have looked it over and can't seem to find a fix for it. it will work if i use email but i would whether use either post or both. i don't want email really.

This website is proudly hosted on Crocweb Cloud Website Hosting.