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.

JPDeni

Quoteany chance of an rc3 version of this

Not from me, I'm afraid. I started making changes to work with RC2 and then SMF made so many changes that all the work I'd done was completely useless. I don't want to waste more time, so I'm not going to work with SMF2 until the actual release.

If anybody else wants to work with it, be my guest.

ZarPrime

raxavier69,

I have a version of JPDeni's Form working with SMF 2.0 RC3 and the latest version of TinyPortal but it has some things in it that I would rather remove before posting it.  If you give me until this weekend or so, when I will have more time to look at it, I'll post it, with JPDeni's permission of course.

ZarPrime

JPDeni


raxavier69

Quote from: ZarPrime on June 03, 2010, 04:06:50 AM
raxavier69,

I have a version of JPDeni's Form working with SMF 2.0 RC3 and the latest version of TinyPortal but it has some things in it that I would rather remove before posting it.  If you give me until this weekend or so, when I will have more time to look at it, I'll post it, with JPDeni's permission of course.

ZarPrime

Sweet ty very, cant wait :) cheers m8

ZarPrime

raxavier69,

OK, the code below will work for SMF 2.0 RC3 and TinyPortal 1.0 beta 5 (all versions).  However, be aware that it isn't perfect right now.  There are some other things that could be done with it.  Also, the polls that were put in by JPDeni are not enabled in this version, mainly because I haven't had a chance to look to see how to do that in SMF 2.0.  Be sure to set the "$board_id=x;" for the correct board you want the new topic to be created in.

FWIW, prior to TP 1.0 beta 5 coming out, I had been working on a Support Form based on JPDeni's code for our use here in the event that we were swamped with support questions.  Because we never got swamped with these questions, I never finished the code but, with JPDeni's help, I did make some nice enhancements to it.  For instance, instead of the subject of the topic being automatically generated, I had put in a way for the Form user to type in a subject.  Also, I changed some of the formatting and removed slashes when the user types a word with apostrophe's in it.

Try this code out, and if it works for you, we will post a new topic in the new Block Code Snippets board, and I will include the code for the TinyPortal Support Form that I had been working on as an example.

ZarPrime


global $sourcedir, $context, $scripturl, $user_info;
///// ZP Edit - Globals below replaced by the above
//global $sourcedir, $ID_MEMBER, $context, $scripturl, $user_info, $db_prefix;
// Generic Application Form
// Originally created by JPDeni, TinyPortal Coding Goddess, reference the topic below:
// URL: http://www.tinyportal.net/index.php?topic=29670.msg236779#msg236779
// Date: 30 November 2009
//
// Edited on 6 June, 2010 by ZarPrime to work with SMF 2.0 RC3 and TinyPortal 1.0 beta 5 (Polls not enabled in this version)

// Guests can't fill out the form
if ($context['user']['id'] == 0)
    echo 'You must be logged in before you can apply.';
else {

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


// CONFIGURATION SECTION

   $intro_form = "Put whatever introduction you want to appear at the top of the form here. You can add html. Be careful with quotation marks.";
   $thanks_text = "This is what will appear after the form is submitted. You can use html. Be careful with quotation marks.";

// 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' =>      "Heading",
            'name' =>         "heading",
            'type' =>         "heading",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0
         ),
         array(
            'caption' =>      "Name",
            'name' =>         "realname",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            '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' =>     1
         ),     
         array(
            'caption' =>      "Do you like me?",
            'name' =>         "like",
            'type' =>         "checkbox",
            'options' =>      "Yes",
            'defaultvalue' => "Yes",
            'required' =>     0
         ),     
         array(
            'caption' =>      "Comments",
            'name' =>       "comments",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1
         ),
      );



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

// email address of recruitment staff member
   $email_address='';

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

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

// Poll options
///// ZP Edit - Poll options disabled in SMF 2.0 RC3/TP 1.0 beta 5 version
//$add_poll = 1; // 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
///// ZP Edit - Poll options disabled in SMF 2.0 RC3/TP 1.0 beta 5 version

//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

///// ZP Edit - Poll options disabled in SMF 2.0 RC3/TP 1.0 beta 5 version /////
// 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;
///// ZP Edit - Poll options disabled in SMF 2.0 RC3/TP 1.0 beta 5 version /////

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

            $msgOptions = array(
               'id' =>  0 ,
               'subject' => '[Pending] Application of ' . addslashes($_REQUEST['realname']),
               'body' => addslashes($postbody) ,
               'icon' => 'xx',
               'smileys_enabled' => true,
               'attachments' =>  array(),
            );

///// ZP Edit - Poll options disabled in SMF 2.0 RC3/TP 1.0 beta 5 version /////
//          $topicOptions = array(
//             'id' => 0 ,
//             'board' => $board_id,
//             'poll' =>  $ID_POLL,
//             'lock_mode' =>  null,
//             'sticky_mode' =>  null,
//             'mark_as_read' => true,
//          );
///// ZP Edit - Poll options disabled in SMF 2.0 RC3/TP 1.0 beta 5 version /////
///// Above replaced by the following until polls done
            $topicOptions = array(
               'id' => 0 ,
               'board' => $board_id,
               'poll' =>  null,
               'lock_mode' =>  null,
               'sticky_mode' =>  null,
               'mark_as_read' => true,
            );
///// Above replaced by the above until polls done
            $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>';
   }
}

raxavier69

#175
TY ZP,
ill try out the code tomorrow, im not much of a coder so it might take be a bit to get it out the way i want it. General question, you think i can use dreamweaver to include images in it and align it? or is hard coded the way it is?

once again tyvm and will let you know how it works tomorrow.

Side note, any way of making the post outcome be posted in a place where that user usually cannot post? or it is limited to users permissions?



also is this what i need to stick in for a reply for users who are of member group x,y,z?

if ($context['user']['id'] == 0)
    echo 'You must be logged in before you can apply.';

elseif ($context['user']['id'] == x,y,z)
    echo 'You are already a member.';

else {

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

or i need elseif for each one?

also how can i insert image into the top of the form regardless of member group? i tried img src but big error


ZarPrime

#176
Quote from: raxavier69 on June 07, 2010, 01:12:21 AM
Side note, any way of making the post outcome be posted in a place where that user usually cannot post? or it is limited to users permissions?

Yes, you can set the Board for the post to go into that the member can't see so that only Members who can view that Board will see the post, permission based.  In other words, only members who have permission to see that Board will see the topic created.

Quote from: raxavier69 on June 07, 2010, 01:12:21 AM
also is this what i need to stick in for a reply for users who are of member group x,y,z?

if ($context['user']['id'] == 0)
    echo 'You must be logged in before you can apply.';

elseif ($context['user']['id'] == x,y,z)
    echo 'You are already a member.';

else {

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

or i need elseif for each one?

I'm not sure what you are trying to do there.  If you are trying to limit which MemberGroups can use the form, simply place this article into a Category by itself and then set what MemberGroups can see the Category.

Quote from: raxavier69 on June 07, 2010, 01:12:21 AM
also how can i insert image into the top of the form regardless of member group? i tried img src but big error

The Support Form I was working on actually has an image that I put into the code.  In essence, you'd place this in the code to be displayed  above the form.  Something like this should work ...

Find this ...

$intro_form = "Put whatever introduction you want to appear at the top of the form here. You can add html. Be careful with quotation marks.";


and change to this (or something similar) ...

$intro_form = "<div style=\"text-align: center;\"><img
style=\"width: 345px; height: 104px;\" alt=\"TinyPortal Support\"
title=\"TinyPortal Support Form\"
src=\"http://talesofthehavenexpanse.com/graphics/tp-logo-supp.png\"
align=\"middle\"><br>
<br>
<div style=\"text-align: center;\"><big
style=\"font-weight: bold; text-decoration: underline;\">Posting
Guidelines<br>
</big>
<div style=\"text-align: left;\"><small><br>
<big>If you have never read the  <span
style=\"font-weight: bold; text-decoration: underline;\">new</span>
Posting Guidelines for the TinyPortal Support Board, or if you need
additional information about how to fill out the Support Form below,
please click the following link.<br>
<br>
</big></small>
<div style=\"text-align: center;\">Link goes here<br>
<br>
<div style=\"text-align: left;\"><span
style=\"font-weight: bold; text-decoration: underline;\">IMPORTANT
NOTE</span>:  Topics posted to the Support Board that
haven't used this Support Form will be placed at the bottom of the
priority list for Support.  What that means is that you should
post as much detail as possble in the Form so that we do not have to
ask multiple questions to get to a point where we can assist you.
Fields marked with an asterisk (*) in the Form are required.<small></small></div>
</div>
</div>
</div>
</div>";


It's just standard html though you need to be careful of quotes (just escape them with a backslash ~ \).  Change the code to your own and the image link near the top to your own as well.  You'd do the same thing for the "$thanks_text" only with different code.

ZarPrime

JPDeni

You've learned very well, ZP.  :smitten:

ZarPrime

Thanks JPDeni. :smitten: :D My mentor has been an excellent instructor.  IMHO, I have learned from the best. ;)

ZarPrime

Ken.

Alright now... that's enough of that mushiness!  :2funny:






j/k JP & ZP, you both do great work.  O0
" If everything seems under control, you're not going fast enough." - Mario Andretti
Yesterday When I was Young.

This website is proudly hosted on Crocweb Cloud Website Hosting.