TinyPortal

Development => Block Codes => Topic started by: JPDeni on May 23, 2009, 11:04:28 PM

Title: Generic Application Form
Post by: JPDeni on May 23, 2009, 11:04:28 PM
This is designed for those who wish to make an application form for their site.


type:php article
author:JPDeni
name:Application Form
version:.1
date:16 Apr 2009
discussion topic:http://www.tinyportal.net/index.php/topic,9840.0.html (sort of)
description:
  • Creates a form to be filled out by prospective members
  • Form fields are defined within the text, to include text, textarea, select, radio and checkbox fields
  • Results can be emailed to an admin, posted to a specified board or both


global $sourcedir, $ID_MEMBER, $context, $scripturl, $user_info, $db_prefix;

// 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 ($ID_MEMBER == 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
$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

//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 />';
               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(),
            );
            $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>';
   }
}


23 Sep 2009 -- Minor alteration to make the script work in blocks as well as articles.
30 Nov 2009 -- Added function to add a poll
Title: Re: Generic Application Form
Post by: Renegd98 on May 23, 2009, 11:22:03 PM
Thanks for sharing JP
Title: Re: Generic Application Form
Post by: JPDeni on May 23, 2009, 11:37:06 PM
This is the same thing that I posted in the "Join us form" topic. I just created my own topic for it so people could figure out what code to use if they want to use mine.
Title: Re: Generic Application Form
Post by: ZarPrime on May 24, 2009, 12:10:34 AM
Jp Deni,

Thanks for sorting this out for me.  I'm going to try it now.

Should we put this in the Block Code Snippets Board as a [Block]?

ZarPrime
Title: Re: Generic Application Form
Post by: Skhilled on May 24, 2009, 12:31:30 AM
Thanks, JPDeni! It is pretty easy to follow and commented well. Great job! I am going to try this.
Title: Re: Generic Application Form
Post by: Ken. on May 24, 2009, 01:44:45 AM
Already tried it and it works great.
Now I've just gotta find a use for it.  :coolsmiley:

http://www.ourfamilyforum.org/FamilyForum/index.php?page=197
Title: Re: Generic Application Form
Post by: Skhilled on May 24, 2009, 03:26:09 AM
I'm surprised you didn't put "yes" or "no" as options for "sex"! LMAO
Title: Re: Generic Application Form
Post by: JPDeni on May 24, 2009, 03:30:46 AM
QuoteI'm surprised you didn't put "yes" or "no" as options for "sex"! LMAO

:2funny:

QuoteShould we put this in the Block Code Snippets Board as a [Block]?

That's where I thought I had it.  :uglystupid2:
Title: Re: Generic Application Form
Post by: FUBAR on May 26, 2009, 05:00:17 AM
Thanks for posting the code here JPDeni.  :)

I had one question for you though, I noticed when submitting the application the thread title reads.."[Pending] Application of " but doesn't include the name of the user submitting the form.  Is it supposed to work this way? 

It would be confusing having the same title over and over in a board.   ;)
Title: Re: Generic Application Form
Post by: JPDeni on May 26, 2009, 05:27:12 AM
I had taken that code from where someone had altered it for themselves. I guess I didn't look at it really closely. The person had set the post title to correspond with his own field names. You can alter the line to match your own field names. Just do a search for "[Pending]" and then put the field name in the brackets. Like:


'subject' => '[Pending] Application of ' . $_REQUEST['realname'],


I just changed it to match one of the sample fields that I have in my code. Put your own field name instead of realname.
Title: Re: Generic Application Form
Post by: FUBAR on May 26, 2009, 05:41:54 AM
That fixed it, thanks for the help!  :)
Title: Re: Generic Application Form
Post by: FUBAR on May 26, 2009, 11:28:44 PM
I've noticed that when going to the application form page it generates a few errors and this is before submitting the form. 

Here are the errors and respective lines:

8: Undefined variable: scripturl
File: /home/xxx/public_html/forum/Themes/default/languages/TPShout.english.php (eval?)
Line: 256


<form action="' . $scripturl . '?page='  . $_GET['page'] . '" method="post">


8: Undefined variable: fieldvalue
File: /home/xxx/public_html/forum/Themes/default/languages/TPShout.english.php (eval?)
Line: 286


echo '<INPUT name="' . $field['name'] . '" type="text" value ="' . $fieldvalue[$field['name']] . '" />';


8: Undefined variable: fieldvalue
File: /home/xxx/public_html/forum/Themes/default/languages/TPShout.english.php (eval?)
Line: 313


echo $fieldvalue[$field['name']];


These errors only come up when viewing the application form. 

After submitting I get different errors in the log.

8: Undefined index: heading
File: /home/xxx/public_html/forum/Themes/default/languages/TPShout.english.php (eval?)
Line: 216


$postbody .= '[color=red][u][b]' . $field['caption'] . '[/b][/u][/color]  ' . $_REQUEST[$field['name']] . '<br />';


8: Undefined index: charclass
File: /home/xxx/public_html/forum/Themes/default/languages/TPShout.english.php (eval?)
Line: 223


'subject' => '[Pending] Application of ' . $_REQUEST['realname'] . ' ' . $_REQUEST['charclass'],


8: Undefined variable: user_info
File: /home/xxx/public_html/forum/Themes/default/languages/TPShout.english.php (eval?)
Line: 240


'email' => $user_info['email'],


I apologize for the long post but I'm trying to be as detailed as possible.

Also, BTW the form seems to work properly when viewing and submitting. 

Any help would be appreciated, thanks in advance!  :)


Title: Re: Generic Application Form
Post by: JPDeni on May 26, 2009, 11:41:25 PM
Maybe I'll just shut this down until I can get it to go. I thought it was ready. It appears I was wrong.
Title: Re: Generic Application Form
Post by: FUBAR on May 26, 2009, 11:48:43 PM
It does work properly though, just creates the errors. 

Sorry to be the bearer of bad news JPDeni.  :( 
Title: Re: Generic Application Form
Post by: JPDeni on May 26, 2009, 11:53:48 PM
It's all right. I just didn't realize that when I tried to clean up someone's usage of my code that they had altered it so much. I appreciate your telling me, even if it is embarrassing.

I've fixed all of the issues you mention (some were fixed yesterday). If you find anything else, let me know. :)
Title: Re: Generic Application Form
Post by: FUBAR on May 27, 2009, 02:54:46 AM
I tried your new code and copied everything below "END OF CONFIG...." and got an error.  I then copied the new code entirely and unfortunately received the same error.

Parse error: syntax error, unexpected '.' in /home/xxx/public_html/forum/Sources/Load.php(1753) : eval()'d code(586) : eval()'d code on line 124

Not really sure what's up, looks like it's going to be one of those nights.  ;)
Title: Re: Generic Application Form
Post by: JPDeni on May 27, 2009, 03:37:03 AM
Oh, dea. I should have pasted it into my test page. I found two errors. Corrected code is in place.
Title: Re: Generic Application Form
Post by: ColdCoffee on June 02, 2009, 11:58:28 AM
Could I get any assistant in using this same code to work with the CustomAction mod?
Title: Re: Generic Application Form
Post by: JPDeni on June 02, 2009, 01:21:50 PM
I don't know how the Custom Action mod works, so I wouldn't be able to help you.
Title: Re: Generic Application Form
Post by: FUBAR on June 07, 2009, 08:40:24 PM
We are almost there JPDeni!  :)

I'm still getting this error when posting...

8: Undefined variable: user_info
File: /home/xxx/public_html/forum/Themes/default/languages/TPShout.english.php (eval?)
Line: 243


I've also got a question, any idea how to bold each subject heading in the post? 

Thanks for all the help, great block/article.  ;)
Title: Re: Generic Application Form
Post by: JPDeni on June 07, 2009, 11:24:31 PM
I've added the variable to the "global" line.


if ($enable_post) {  //create new forum post with application

$postbody = 'Recruitment application has been made by ' . $context['user']['name'] .'<br /><br/>';
foreach ($fielddef as $field) {
if ($field['type'] == 'heading')
$postbody .=  '[b]'. $field['caption'] . '[/b]<br />';
else
$postbody .= $field['caption'] . ': ' . $_REQUEST[$field['name']] . '<br />';
}
Title: Re: Generic Application Form
Post by: Dramber on June 14, 2009, 04:57:43 PM
Thank you so much for this. It is exactly what I have been looking for. I'm only having one issue.
If someone uses this form an adds an ' in any of the textboxes the forums show it as a hacking attempt and throws up an error page. I know there is an easy way to fix this but I'll be darned if I can think of it this early in the morning. :P

I'm running TP v1.0 beta 4 with SMF 1.1.9 I've attached my code for the article if you would like to take a peek.
orderoftwilight.com
Thanks for your time!
Title: Re: Generic Application Form
Post by: JPDeni on June 14, 2009, 07:36:38 PM
Change


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


to


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


Let me know how it works. If that's the fix, I'll alter the original code.
Title: Re: Generic Application Form
Post by: Dramber on June 14, 2009, 07:42:24 PM
That did it! Thanks a bunch. I knew it was something simple. :P

Title: Re: Generic Application Form
Post by: JPDeni on June 14, 2009, 07:51:29 PM
I just forgot about it. I'm glad you mentioned it. Off to fix the original code.

Thank you!
Title: Re: Generic Application Form
Post by: Dramber on June 14, 2009, 07:52:07 PM
I also added "addslashes" to the 'subject' line. Some of my forum members have very strange names. Seems to be working great.
Thank you again for looking into this.
Title: Re: Generic Application Form
Post by: wilsy on June 16, 2009, 12:40:26 PM
Hi,

Love the form!! Would it be possible to have this open to guests to complete as I wish to invite them to provide information/feedback to the site (registration is disabled).

Regards,

Wilsy.
Title: Re: Generic Application Form
Post by: JPDeni on June 16, 2009, 01:49:55 PM
I'm not going to put this in the main code because I think it's a bad idea, but I'll give you the code here.

Change

if ($ID_MEMBER == 0)


to


// If you want guests to be able to fill this out, set it to 1.
// Note that you will not be able to have an email sent with the information.

$allow_guests = 0;


if ($ID_MEMBER == 0 && $allow_guests == 0)


and change


if ($enable_email)


to


if ($enable_email && $ID_MEMBER > 0)


The reason that you can't have an email sent if it's a guest that's doing it is that the email function uses the user's email address as the "From" on the email. With a guest, there is no "From."

The reason this is a really bad idea is that there are such things as spammers and 'bots who just lu-u-u-u-uve to find open forms for them to fill out. I did not put any security measures in this because they're not necessary when you have registered users using the form. If you want to add security, you'll need to do that yourself.
Title: Re: Generic Application Form
Post by: Zetan on June 16, 2009, 02:57:42 PM
Quote from: JPDeni on June 16, 2009, 01:49:55 PM
The reason this is a really bad idea is that there are such things as spammers and 'bots who just lu-u-u-u-uve to find open forms for them to fill out. I did not put any security measures in this because they're not necessary when you have registered users using the form. If you want to add security, you'll need to do that yourself.

ahahaha.... yeah, I have an open form on my site, it gets quite a bit of spam. I want to add reCaptcha to it. It's a form that come packaged with the hosting plan of my site.
Title: Re: Generic Application Form
Post by: wilsy on June 16, 2009, 03:03:35 PM
Thanks JP and Zetan, really appreciated. I might add another level of membership based off guests and reopen registration which should do the trick ;)
Title: Re: Generic Application Form
Post by: sysd0wn on July 03, 2009, 02:16:35 AM
Are there any known issues with this on TPv1.0 beta 4? I've been trying to get this to work. I pasted this code into a .php and called for it in an article, but it always says 'you need to be logged in' regardless of whether or not you are logged in. I have also attempted to put this straight into a PHP article, but then it won't even save. It returns a 500 Internal Server Error.

Any ideas?
Title: Re: Generic Application Form
Post by: JPDeni on July 03, 2009, 02:29:07 AM
QuoteI pasted this code into a .php and called for it in an article
QuoteI have also attempted to put this straight into a PHP article

I don't know what either one of those things means. You need to create a php article from within TP, paste the code into the article and save it.

No one has brought up any issues with beta 4. Are you able to save any other php file?
Title: Re: Generic Application Form
Post by: sysd0wn on July 03, 2009, 03:28:44 AM
What I meant was, I saved the code in a file called "application.php" and changed my article type to External Article. This method always says "You must be logged in before you can apply".

For the second, I did exactly what you said - Create a php article, paste, save. And it gives me an internal server error.

I am able to save just plain text in a php article, but it seems to give me an error whenever I add code.
Title: Re: Generic Application Form
Post by: JPDeni on July 03, 2009, 04:29:07 AM
QuoteI saved the code in a file called "application.php" and changed my article type to External Article.

It wasn't designed for that. It was designed to go into a php article.

QuoteI am able to save just plain text in a php article, but it seems to give me an error whenever I add code.

Then your problem isn't with my code. The best thing to do is to start a topic for support with your php article problem.
Title: Re: Generic Application Form
Post by: Uthn on July 03, 2009, 07:56:33 AM
Thanks the code JPDeni, works fine except for one little thing mainly due to the fact that i don't use English language in it.

French language uses 'special' characaters that cause some issues, here's an exemple

"c'est l'heure" becomes "c\'est l\'heure"

any clue ? :)

thanks
Title: Re: Generic Application Form
Post by: JPDeni on July 05, 2009, 07:30:41 AM
I'm sorry. I don't.
Title: Re: Generic Application Form
Post by: tragidy on July 06, 2009, 08:55:54 PM
Hi,

First I would like to say thanks for the code, it works really well, however ive found one issue with this, however it should be fixable.

Here is an example of an array i used.

array(
'caption' =>      "<FONT COLOR=red>Age</font>",
'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


If you note the color html or any html for that matter, ie; bold text

This all looks great on the form and looks great in the forum post however, if I go to modify the post exg; change topic from pending to accepted the body of the post becomes full of html that is out putted into html in the form of a php ' echo ' instead of keeping its coding.

I have attempted a solution with this line of your code.


if ($enable_post) {  //create new forum post with application

$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 = '[html]' . $field['caption'] . ': ' . $_REQUEST[$field['name']] . '[/html]<br />';


This would solve the issue upon editing however after the alteration of adding [html] brackets after the application is posted it will only display the comments section.

I am using a stock copy of your code unaltered except for the alterations posted above obtained from the first page on this thread.

Any help or solutions you could provide would be great.

Thanks
Title: Re: Generic Application Form
Post by: JPDeni on July 06, 2009, 09:31:09 PM
QuoteThis all looks great on the form and looks great in the forum post however, if I go to modify the post exg; change topic from pending to accepted the body of the post becomes full of html that is out putted into html in the form of a php ' echo ' instead of keeping its coding./quote]

That's because the code wasn't written to do that. If you want to change the outputted formatting, you should change it in the output part of the code, not the field definitions.
Title: Re: Generic Application Form
Post by: tragidy on July 06, 2009, 09:37:04 PM
What exactly wasn't the code written to do?

You have in the php comments that html/color is allowed, but when posted it appears fine but to modify the post will display the pure html with no remorse or line breaks upon saving.

$postbody = '[html]' . $field['caption'] . ': ' . $_REQUEST[$field['name']] . '[/html]<br />';

Should resolve the issue however, the code will only echo the last array when modified.
Title: Re: Generic Application Form
Post by: JPDeni on July 06, 2009, 10:36:01 PM
The code was not written to have html code included in the names of the fields.

My comments say the following:

$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.";


Those comments apply to those variables only. The note about the caption says


Can include symbols and spaces.


Nothing about html. It's too complicated for a generic form, as you seem to have found out.

If you can find a way to resolve it, that's great, but it's not the way the code was intended.
Title: Re: Generic Application Form
Post by: ZarPrime on August 03, 2009, 10:28:57 PM
JPDeni,

I have a question.  The "heading" field type appears to be centered as it should be.  However, for the other field types, it looks like there is a TD in the code to align the other fields to the left, but none of them seem to be aligned left except the one with the checkbox.

The code for align left that I'm talking about starts with ...
<TD align="left">';

// Go through each field type


What can I do to make sure that the other fields (not the heading fields) align left in the form?  See Pic below.

ZarPrime
Title: Re: Generic Application Form
Post by: JPDeni on August 03, 2009, 10:40:58 PM
They look like they're aligned to the left to me. The left column (the labels) is aligned to the right and the right column (the fields) is aligned to the left. That way they meet more or less in the middle. Not really the middle because of the varying sizes of the labels and the fields and there's really nothing I can do about that.

But maybe I'm not understanding what you mean.

ETA: Are you talking about the labels lining up to the left? If that's what you want, you'll need to change


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


to


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

// Go through each field type


The reason that the label connected with the checkbox appears to be aligned to the left is that it's the longest label, so it fills the entire width of the column.
Title: Re: Generic Application Form
Post by: ZarPrime on August 03, 2009, 10:59:21 PM
Ah, OK I see what you mean.  The fields themselves are aligned left in the right TD.  What I was trying to do was align the labels so that that would be aligned left in the left TD like this ...


*Name:
*Age:
*Sex:
Do you like me?:


rather than like this ...

         * Name:
          * Age:
          * Sex:
Do you like me?:


However, that may not look right either if I have a long label because it would probably push the right TD to far to the right.  OK, I'll have to think about that some more.

Thanx,
ZP 
Title: Re: Generic Application Form
Post by: JPDeni on August 03, 2009, 11:03:03 PM
I edited my post to show you how to align them to the left, if you want to give it a try and see how it looks.
Title: Re: Generic Application Form
Post by: ZarPrime on August 03, 2009, 11:10:05 PM
OK, that is definitely what I was looking for, but I'm undecided if that's the look I want when the label is long.  That answers the question though. :up:

TYVM,
ZP

Edit:  Well, it doesn't look so good with the comments field (the longest one) is set for cols="40" but when I changed it to 80 it looks pretty good.  I may do one other thing.  I might change the font for the labels to a fixed width font like courier or something.  That would let me add content to fill in the labels so that they end closer to the fields.  It looks pretty good this way.
Title: Re: Generic Application Form
Post by: JPDeni on August 03, 2009, 11:16:29 PM
YWVM,
JPD

;)
Title: Re: Generic Application Form
Post by: ZarPrime on August 03, 2009, 11:23:20 PM
Check my edit above.  I changed the cols on the comments field to 80 and it looks pretty good.
Title: Re: Generic Application Form
Post by: JPDeni on August 03, 2009, 11:33:41 PM
That's great! There's a lot of things that people can do to make it look like they want it to, which is why I kept the formatting at a minimal level in the basic code.

It's gratifying to see someone work with the code and bend it to their will. :D
Title: Re: Generic Application Form
Post by: maviel on August 13, 2009, 03:29:03 PM
Question about the heading

Is it possible to get the heading like this in the code:

Heading < bolded
question 1
question 2
question 3

Heading 2 < bolded
question 1
question 2
question 3

Since my php skills is poor i have no idea how to do this in the code.
Title: Re: Generic Application Form
Post by: JPDeni on August 13, 2009, 03:32:51 PM
Look for


// 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>';
}


In the line


<TD colspan="2" style="text-align: center; text-decoration: underline;">


put whatever you want as inline css. The default has it centered and underlined, but you can put whatever you want in there. No php involved. :-)
Title: Re: Generic Application Form
Post by: maviel on August 13, 2009, 03:38:50 PM
i tried that i want this to be shown as a post on the forums when an application been made not in the default "question" thing.
Title: Re: Generic Application Form
Post by: maviel on August 19, 2009, 02:48:07 PM
it seems not work for me. i get some stuff working but all Text is not being posted on the forums. Anyone know why?
                                                                global $sourcedir, $ID_MEMBER, $context, $scripturl, $user_info;

// Guests can't fill out the form
if ($ID_MEMBER == 0)
    echo 'Fel! Du mÃ¥ste vara inloggad innan du kan göra en ansökan till Valhalla Legion.';
else {

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


// CONFIGURATION SECTION

$intro_form = "Även om detta applikations system inte är som alla andras gillens så vet vi på Valhalla Legion att DU tar din tid och skriver ner nogranna svar på de frågor som kommer upp eftersom detta kommer vara vårat första intryck på dig som person.";
$thanks_text = "Tack för din ansökan till Valhalla Legion. Din ansökan har nu skickats till alla officerare i guildet via E-Mail samt så har denna ansökan kommit upp på forumet och kommer granskas innom 24 timmar. Har du inte fått ett svar innom 48 timmar så får du kontakta någon av officerarna i guildet som är Knax eller Nahiag.";

// 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' =>      "Personlig Information",
'name' =>         "Personlig Informaition",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Namn",
'name' =>         "Namn",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0   
),
array(
'caption' =>      "Ã…lder",
'name' =>         "Ã…lder",
'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' =>     0
), 
array(
'caption' =>      "Kille/Tjej",
'name' =>         "Gen",
'type' =>         "radio",
'options' =>      "Kille,Tjej",
'defaultvalue' => "",
'required' =>     0
), 
array(
'caption' =>      "Berätta Lite om dig själv",
'name' =>        "Lite om mig själv",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Karraktärs Information",
'name' =>         "Karraktärs Information",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
                ),
                array(
'caption' =>      "Karraktärs namn",
'name' =>         "charname",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0   
),
            array(
'caption' =>      "Level",
'name' =>         "charlvl",
'type' =>         "select",
'options' =>      "80,79,78,77,76",
'defaultvalue' => "80",
'required' =>     0
), 
              array(
'caption' =>      "Ras",
'name' =>         "charrace",
'type' =>         "select",
'options' =>      "Dranei,Dwarf,Human,Night Elf,Gnome",
'defaultvalue' => "Dranei",
'required' =>     0
), 
              array(
'caption' =>      "Klass",
'name' =>         "charclass",
'type' =>         "select",
'options' =>      "Death Knight,Druid,Hunter,Mage,Paladin,Priest,Rogue,Shama,Warlock,Warrior",
'defaultvalue' => "Death Knight",
'required' =>     0
),
              array(
'caption' =>      "Primär Spec",
'name' =>         "charspec",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0   
),
                array(
'caption' =>      "Secondär Spec",
'name' =>         "Secondär Spec",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0   
                ),
                                         array(
'caption' =>      "Respecar du din klass om vi ber om det?",
'name' =>         "Respecar du din klass om vi ber om det?",
'type' =>         "radio",
'options' =>      "Ja,Nej",
'defaultvalue' => "",
'required' =>     0
), 
                array(
'caption' =>      "/Played",
'name' =>         "/Played",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0   
),
                array(
'caption' =>      "Armory Länk",
'name' =>         "Armory Länk",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0   
),
           
            array(
'caption' =>      "Är det du själv som har levlat upp din character?",
'name' =>         "Levlat upp gubben själv",
'type' =>         "radio",
'options' =>      "Ja,Nej",
'defaultvalue' => "",
'required' =>     0
), 
 
            array(
'caption' =>      "Vilka dagar/tider kan du raida pÃ¥ (Va specifik)",
'name' =>         "Vilka dagar/tider kan du raida pÃ¥ (Va specifik)",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
                ),
                array(
'caption' =>      "Raid FrÃ¥gor",
'name' =>         "Raid FrÃ¥gor",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
                  array(
'caption' =>      "Raidade du Classic? Hur lÃ¥ngt kom du?",
'name' =>         "Raidade du Classic? Hur lÃ¥ngt kom du?",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
                ),
                      array(
'caption' =>      "Raidade du TBC? Hur lÃ¥ngt kom du?",
'name' =>         "Raidade du TBC? Hur lÃ¥ngt kom du?",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
                ),
                      array(
'caption' =>      "Vad är din nuvarande RAID progress i WOTLK? (Va specifik)",
'name' =>         "Vad är din nuvarande RAID progress i WOTLK? (Va specifik)",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
                ),
                        array(
'caption' =>      "Vad gör dig till en bra medspelare i raids?",
'name' =>         "Vad gör dig till en bra medspelare i raids?",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
                ),
                array(
'caption' =>      "Är du en klicker?",
'name' =>         "Är du en klicker?",
'type' =>         "radio",
'options' =>      "Ja,Nej,Lite av bÃ¥da",
'defaultvalue' => "",
'required' =>     0
), 
                array(
'caption' =>      "Har du en FUNGERANDE mic?",
'name' =>         "Har du en FUNGERANDE mic?",
'type' =>         "radio",
'options' =>      "Ja,Nej",
'defaultvalue' => "",
'required' =>     0
), 
                            array(
'caption' =>      "Guild Relaterade FrÃ¥gor",
'name' =>         "Guild Relaterade FrÃ¥gor",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
                            array(
'caption' =>      "Är du med i ett guild? isf vilket?",
'name' =>         "Är du med i ett guild? isf vilket?",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
                                      array(
'caption' =>      "Om JA pÃ¥ frÃ¥gan över varför vill du lämna guildet?",
'name' =>         "Om JA pÃ¥ frÃ¥gan över varför vill du lämna guildet?",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
                                        array(
'caption' =>      "Om NEJ pÃ¥ frÃ¥gan varför har du lämnat/blivit kickad frÃ¥n guildet?",
'name' =>         "Om NEJ pÃ¥ frÃ¥gan varför har du lämnat/blivit kickad frÃ¥n guildet?",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
                                                                array(
'caption' =>      "Vad kan DU erbjuda Valhalla Legion som spelare?",
'name' =>         "Vad kan DU erbjuda Valhalla Legion som spelare?",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
                                                    array(
'caption' =>      "Vad kan Valhalla Legion erbjuda DIG som spelare?",
'name' =>         "Vad kan Valhalla Legion erbjuda DIG som spelare?",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
                                                                array(
'caption' =>      "Finns det nÃ¥gon som kan Rekomendera dig i Valhalla Legion?",
'name' =>         "Finns det nÃ¥gon som kan Rekomendera dig i Valhalla Legion?",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
                                        array(
'caption' =>      "Ãâ€"vrigt",
'name' =>         "Ãâ€"vrigt",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
               
           
            array(
'caption' =>      "Kan du nÃ¥got roligt skämt?",
'name' =>         "Kan du nÃ¥got roligt skämt?",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
                ),
           
               
);
       



//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=13.0;


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

$postbody = 'Ansökningen har gjorts av ' . $context['user']['name'] .'<br /><br/>';
foreach ($fielddef as $field) {
if ($field['type'] == 'heading')
$postbody .= $field['caption'] .  '<br /><br />';
else
$postbody .=  $field['caption'] . ': ' . $_REQUEST[$field['name']] . '<br />';
}

$msgOptions = array(
'id' =>  0 ,
'subject' => '[OAVSLUTAT] ' . $_REQUEST['charlvl'] . ' ' . $_REQUEST['charspec'] . ' ' . $_REQUEST['charclass'] . ' ' . $_REQUEST['charname']  ,
'body' => addslashes($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,
);
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;">Du har inte fyllt i alla fält med en stjärna *.</div>';  }

echo '
<form action="' . $scripturl . '?page='  . $_GET['page'] . '" 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;"><b>' .
$field['caption'] . '</b>
</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>';
}
}

Title: Re: Generic Application Form
Post by: JPDeni on August 19, 2009, 03:00:42 PM
Quoteall Text is not being posted on the forums.

Can you be more specific? What is and what is not being posted? An example would help to narrow things down.
Title: Re: Generic Application Form
Post by: maviel on August 19, 2009, 03:16:10 PM
it is only the class, name, played, that is posted i think there is a leak somewer i get this error:

8: Undefined index: Kan du något roligt skämt?
File: /hsphere/local/home/kenta81/valhallalegion.se/Themes/default/TPortal.template.php (main sub template - eval?)
Line: 363

And befor i did get an error from tpshout and disabled it and got this one above instead.

Title: Re: Generic Application Form
Post by: JPDeni on August 19, 2009, 03:54:04 PM
I don't know if this is the problem or not, but the "name" for each item should be just one word and it would probably be best if you used only letters that are in English. As the instructions say

Quote//       'name' =>         "", // a unique name for the field. No symbols or spaces

The "name" doesn't show on your form or on the forum entry. It's just something so the script can tell the different fields apart. It can literally be anything, except that you can't use spaces or symbols.
Title: Re: Generic Application Form
Post by: maviel on August 19, 2009, 04:21:27 PM
i got it working now, my bad  :idiot2:.

I never got an answer if i could fix the code so i could get the:
'type' =>         "heading",

Bolded on the forums after so it looks like this:

Header Name
question 1
question 2
question 3

Header Name2
question 1
question 2
question 3

i believe it is this code i should change somewere:
$postbody = 'Ansökningen har gjorts av ' . $context['user']['name'] .'<br /><br/>';
foreach ($fielddef as $field) {
if ($field['type'] == 'heading')
$postbody .= $field['caption'] .  '<br /><br />';
else
$postbody .=  $field['caption'] . ': ' . $_REQUEST[$field['name']] . '<br />';
}

$msgOptions = array(
'id' =>  0 ,
'subject' => '[OAVSLUTAT] ' . $_REQUEST['charlvl'] . ' ' . $_REQUEST['charspec'] . ' ' . $_REQUEST['charclass'] . ' ' . $_REQUEST['charname']  ,
'body' => addslashes($postbody) ,
'icon' => 'xx',
'smileys_enabled' => true,
'attachments' =>  array(),
);

Title: Re: Generic Application Form
Post by: Hairy on August 30, 2009, 02:35:10 PM
Wow this is a really good form, will have to play with it asap.

Thanks JPDeni  8)

Title: Re: Generic Application Form
Post by: JPDeni on August 30, 2009, 02:45:38 PM
Looks like I had missed the question that maviel asked.

Yes, that's the place you would alter it. Change


if ($field['type'] == 'heading')
$postbody .= $field['caption'] .  '<br /><br />';


to


if ($field['type'] == 'heading')
$postbody .= '[b]' . $field['caption'] .  '[/b]<br /><br />';

Title: Re: Generic Application Form
Post by: EasyRider on September 22, 2009, 11:19:13 PM
ÃŽâ€"i JPDeni..!   :)

Very useful  script!

Is possible to add  an option in specific board/topics  so my members can they add an review and posted in the same topic..?

I mean somthing like button in post reply area.

Is that very difficult ..?  ???

Title: Re: Generic Application Form
Post by: JPDeni on September 22, 2009, 11:24:52 PM
QuoteIs possible to add  an option in specific board/topics  so my members can they add an review and posted in the same topic..?

I'm not sure what you mean.

Are you asking if this form can be part of a topic on the forum? If that's what you're asking, I would say that it is conceivably possible, but I wouldn't have any idea of how to do it. You could probably be able to adapt it so that the responses are saved in another database table and then displayed with the article. Or possibly you could put it in a block to appear above a board and then have the reviews below it. But I don't know of a way to add programming to a post in a topic.

But possibly you mean something else. :) If so, I'll need you to try to reword your question.
Title: Re: Generic Application Form
Post by: EasyRider on September 22, 2009, 11:41:33 PM
Thank you for your reply JPDeni, and sorry  for my English ..  :-\

I ask if is possible to add option in post reply area (Attach photo)  like link , menu,  and you going to your php article script , write review  and the review posted back in the same  topic just like continud post but with review layout and infos..

I hope im more clear now..   :)
Title: Re: Generic Application Form
Post by: EasyRider on September 22, 2009, 11:51:02 PM
And something more/else that i thing should help you.

I don't want to create any time new topic for new reviews, but i want an option to my members choose in what topic in specific board the review  going as continud post let's say .

I hope that help..  :-X
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 12:30:59 AM
QuoteI ask if is possible to add option in post reply area (Attach photo)  like link , menu,  and you going to your php article script , write review  and the review posted back in the same  topic just like continud post but with review layout and infos..

I don't think so.

Here's what you could do...

Create a board (or child board) for reviews. Create topics in that board for different types of reviews, however you want to divide them up. (Maybe you have a movie review site and there's a separate topic for each movie, for example.)

Create a php block to display on the top of only that board and put your form in that block. Include a drop-down field with the different topic titles for the user to select which topic the review would be posted in. Call that field topic.

Look for the following section in the code:


                                 $topicOptions = array(
'id' => 0 ,
'board' => $board_id,
'poll' =>  null,
'lock_mode' =>  null,
'sticky_mode' =>  null,
'mark_as_read' => true,
);


Change the 'id' line to


'id' => $_REQUEST['topic'] ,


Does this make sense?
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 01:02:39 AM
Yes, good idea,  thank you..! i try to do that, and i tell you if it is work.. ! :) :) :)

But the final code must look like this?


               $topicOptions = array(
'id' => $_REQUEST['topic'] ,
'board' => $board_id,
'poll' =>  null,
'lock_mode' =>  null,
'sticky_mode' =>  null,
'mark_as_read' => true,
);



I do 1 test now and is not work..  :-\

which place i must put this code..?

And the drop-down field..?  you mean somthing like this?

                       array(
'caption' =>      "ΕκÏÆ'Ïâ,¬ÃŽÂµÃÂÃŽÂ¼ÃŽÂ¬Ãâ€žÃâ€°ÃÆ'η",
'name' =>         "feedback4",
'type' =>         "select",
'options' =>      "select,Στο ÏÆ'ωμα,Στο Ïâ,¬ÃÂÃŽÂ¿ÃÆ'ωÏâ,¬ÃŽÂ¿,Στο ÏÆ'τομα (τα φτυνει),Στο ÏÆ'τομα (τα καταÏâ,¬ÃŽÂ¹ÃŽÂ½ÃŽÂµÃŽÂ¹)",
'defaultvalue' => "1",
'required' =>     1
),



       
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 01:07:10 AM
Hmmmm. Maybe it won't work. The select field doesn't give what I was thinking it would. Hmmmm. Give me a day or two and I'll see if I can work it out. I may have to create a different kind of select field.
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 01:13:42 AM
Quote from: JPDeni on September 23, 2009, 12:30:59 AM

Create a php block to display on the top of only that board and put your form in that block. Include a drop-down field with the different topic titles for the user to select which topic the review would be posted in. Call that field topic.

Look for the following section in the code:


                                 $topicOptions = array(
'id' => 0 ,
'board' => $board_id,
'poll' =>  null,
'lock_mode' =>  null,
'sticky_mode' =>  null,
'mark_as_read' => true,
);


Change the 'id' line to


'id' => $_REQUEST['topic'] ,


Does this make sense?



The idea is perfect, the "problem" for my now, is to  make the drop-down field to work with topics.. :-X

because i allready have an board with about 700 different topics, and there i want to  put option for reviews.
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 01:25:07 AM
Quote from: JPDeni on September 23, 2009, 01:07:10 AM
Hmmmm. Maybe it won't work. The select field doesn't give what I was thinking it would. Hmmmm. Give me a day or two and I'll see if I can work it out. I may have to create a different kind of select field.



Thank you JPDeni ..!

What i thing..  is possible in 'id' => $_REQUEST['topic']  to add option to select from spesific board all  the topics with the url number id? like:

index.php/topic,3984.0.html
index.php/topic,3985.0.html
index.php/topic,3986.0.html
index.php/topic,3987.0.html

And showing the title like  "example movie " in drop-down field for  3984 topic.
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 01:29:46 AM
700?!?!!?  :o

I was going to suggest a drop-down list, but that's too many for a drop-down.

Hmmmmm.

Let me think some more. What I came up with won't work for that many items. I have another idea that might work, but I have to think about it a bit. (And I have to make dinner.  ;) )

I just saw your latest post. Yes, that's what I was thinking, except that I'm not sure how the URL will work because of the format. I just have to let it work in my brain for a little while.
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 02:44:12 AM
I can't use the "Search engine friendly URLs", so I can't test it out, but I think that you should be able to just use


'id' => $_GET['topic'] ,


without having to create a field for the topic. Could you check that on your site and see if it works?

Likely you will not want the form to appear on the board index, where all the topic titles are listed. I can give you the code for that, but first I would like to be sure that the code above works.
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 02:42:04 PM
quote author=JPDeni link=topic=29670.msg247259#msg247259 date=1253670252]
I can't use the "Search engine friendly URLs", so I can't test it out, but I think that you should be able to just use


'id' => $_GET['topic'] ,


without having to create a field for the topic. Could you check that on your site and see if it works?

Likely you will not want the form to appear on the board index, where all the topic titles are listed. I can give you the code for that, but first I would like to be sure that the code above works.
[/quote]


ÃŽâ€"ι JPDeni..!  :)

I try with that code
$topicOptions = array(
'id' => $_GET['topic'] ,
'board' => $board_id,
'poll' =>  null,
'lock_mode' =>  null,
'sticky_mode' =>  null,
'mark_as_read' => true,
);


but nothing happen..  same action like before..
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 03:31:01 PM
I just got up :) . I'll try testing it out in a bit.
Title: Re: Generic Application Form
Post by: ed_m2 on September 23, 2009, 04:08:27 PM
hmmmm.. nicely bumped thread.

wonder if i could use this as the basis for my custom events fields entry.... :)
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 04:13:57 PM
Quote from: JPDeni on September 23, 2009, 03:31:01 PM
I just got up :) . I'll try testing it out in a bit.



Ok JPDeni.. :) :)  i wait.. :)


Also this is my test  forum , take a look if you have time  :) and tell my..

http://adultforumgr.freehostia.com
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 04:32:26 PM
Okay. I think I've got it.

At the beginning of the code, just after


global $sourcedir, $ID_MEMBER, $context, $scripturl, $user_info;


add


if (isset($_GET['topic'])) {


and at the very end of the code, add


}


(This will prevent the form from showing unless the person is viewing a topic.)

Find


echo '
<form action="' . $scripturl . '?page='  . $_GET['page'] . '" method="post">


Replace it with


$place = $_SERVER['REQUEST_URI'];
echo '
<form action="' . $place . '" method="post">


I've just tested it out and it works fine. :) However (there's always a "however", isn't there?), the user will have to go back to the index and then back to the topic in order to see their post.

I've set up an account for you on my test site so you can see how it works. I'll send you login details by PM so you can test it out.
Title: Re: Generic Application Form
Post by: ZarPrime on September 23, 2009, 04:48:29 PM
JP, could you PM those login details as well.  I'd like to see what you guys are doing.

ZP
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 05:01:36 PM
Ok  JPDeni..!  i already  post there.. check it out..  :) :)
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 05:09:38 PM
ZP, you've got an account already.

http://tester.jpdeni.com/index.php

There's just one board. You can access the form from any topic in the board. You have to go back to the index and then back to the topic in order to see your new post.

EasyRider, I saw your post. You select which topic from the board index. If you only had 30 -- or even 50 -- different topics, I would be able to use a select field with the topics. But with 700 possible topics, that's too many to put into a select list. This is the best way to do it.
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 05:41:17 PM
Ok..!  :)  i thing this is the best way to work in all topics..

I go to check it out now and i tell you what happen ..  :up:
Title: Re: Generic Application Form
Post by: ZarPrime on September 23, 2009, 05:45:30 PM
Quote from: JPDeni on September 23, 2009, 05:09:38 PM
There's just one board. You can access the form from any topic in the board. You have to go back to the index and then back to the topic in order to see your new post.

OK, I see what you are doing.  I tried hitting refresh instead of going back to the board index and it just posted the same form again.  OK, I can see what you did with this now.

Thanks,
ZP
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 05:50:06 PM
QuoteI tried hitting refresh instead of going back to the board index and it just posted the same form again.

That's a potential problem and I'm not sure how to get around it. Probably the only thing you can do is to put something in the "thank you" part that displays after the form is submitted. And if there are duplicates, the admin will just have to delete them.
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 06:49:57 PM
Hey JPDeni finally works great..!    :up: :up: :up:

But 1 question.. is there way to not change the post title with the new custom..?

I mean to leave the topic title as was it in any new review post.

And i have a block  in portal front page with recent topics (rss) , and i try  test preview post, but is not appear  the review in latest (recent) topics in front page block.

Maybe is some conflict with  the custom title (see first paragraph^^) in topic..?   :-X :-X
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 07:06:33 PM
You can change the post title. Just look at the code.

In the original code, there's a line


'subject' => '[Pending] Application of ' . addslashes($_REQUEST['realname']),


Put whatever you want in there, using the field name in the place of realname and you can delete or change the text that's in there. So, if you had a field name called subject, you would use


'subject' => addslashes($_REQUEST['subject']),


I don't know anything about rss, and, since I don't know what code you're using for the recent topics, I can't tell you how to adjust it for this.
Title: Re: Generic Application Form
Post by: Ken. on September 23, 2009, 07:25:27 PM
Quote from: JPDeni on September 23, 2009, 05:50:06 PM
QuoteI tried hitting refresh instead of going back to the board index and it just posted the same form again.

That's a potential problem and I'm not sure how to get around it. Probably the only thing you can do is to put something in the "thank you" part that displays after the form is submitted. And if there are duplicates, the admin will just have to delete them.

Would it be possible to make it so that the Submit button causes the page to refresh along with posting the form content? After submitting my entry I refreshed the page and it worked OK for showing the new post.

EDIT: Whoops! Seems to have posted it twice?
http://tester.jpdeni.com/index.php?topic=4.msg19#msg19
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 07:27:19 PM
JPDeni,  If i don't want change the post title..? for example  i mean to be like this title:

"Re: Generic Application Form"  and not the custom option..
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 07:33:10 PM
Yeah, Ken. That's the problem. Refreshing shows the post, but also adds another post. If you go to the board index and then back to the topic, then you'll see the post without adding another one.

EasyRider, it looks like I'll have to add some more code. Hang on.
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 07:49:44 PM
Okay. :)

Change the first line of your code to


global $sourcedir, $ID_MEMBER, $context, $scripturl, $user_info, $db_prefix;


After


if ($enable_post) {  //create new forum post with application


Add


$topic = $_GET['topic'];
$result = db_query("SELECT m.subject
FROM {$db_prefix}messages as m, {$db_prefix}topics as t
WHERE m.ID_TOPIC = $topic
AND t.ID_FIRST_MSG = m.ID_MSG", __FILE__, __LINE__);

$row = mysql_fetch_assoc($result);
$subject = $row['subject'];
mysql_free_result($result);


and then set your subject line to


'subject' => 'Re: ' . $subject,

Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 08:12:06 PM
Great..!! Work..!!! (https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg186.imageshack.us%2Fimg186%2F7610%2Fthumbs.gif&hash=8c6baa93f707fb2f9a7a20a6012b6b57f7f28137) (https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg186.imageshack.us%2Fimg186%2F7610%2Fthumbs.gif&hash=8c6baa93f707fb2f9a7a20a6012b6b57f7f28137) (https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg186.imageshack.us%2Fimg186%2F7610%2Fthumbs.gif&hash=8c6baa93f707fb2f9a7a20a6012b6b57f7f28137)  Thank you  JPDeni..!!!!
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 08:16:12 PM
:) There's lots of different stuff you can do with this form. I like try new things and it's interesting to see what different things people come up with that I can figure out.
Title: Re: Generic Application Form
Post by: Freddy on September 23, 2009, 08:25:58 PM
Nice work JP  :)
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 08:28:31 PM
THX, freddy!
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 08:49:19 PM
Hey JPDeni, is maybe possible to add some style in  the final review..?   :) :) (https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg132.imageshack.us%2Fimg132%2F4285%2Flovecz.gif&hash=ba324ff4d9ff10e4af3750f0e9330c068d3a7e31)

Like bold or color text:

""Recruitment application has been made by ... xvxvz

Heading
Name: farkle
Age: 18
Sex: F
Do you like me?: Yes
Comments: should have the original subject line""
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 08:57:38 PM
Quote from: JPDeni on September 23, 2009, 08:16:12 PM
:) There's lots of different stuff you can do with this form. I like try new things and it's interesting to see what different things people come up with that I can figure out.


(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi33.tinypic.com%2Fdmso6r.gif&hash=97cfbbd852878c425a4763f0c8694583b65bde3e)
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 09:04:52 PM
:)

You can add formatting however you want. Just add BBCode to the post:


if ($field['type'] == 'heading')
$postbody .= $field['caption'] . '<br />';
else
$postbody .= '[b]' . $field['caption'] . '[/b]: ' . $_REQUEST[$field['name']] . '<br />';


That will make each line the same, with the caption in bold print. If you want to do different formatting for different lines, it's a little more work.


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


This will just make the Comments caption in red.
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 09:38:50 PM
I m not sure were put this lines to work..  :-\ 
Title: Re: Generic Application Form
Post by: JPDeni on September 23, 2009, 09:46:18 PM
I'm sorry. Look for the section:


if ($enable_post) {  //create new forum post with application

$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 />';
}


You want to change the $postbody lines.
Title: Re: Generic Application Form
Post by: EasyRider on September 23, 2009, 11:34:54 PM
Thank you JPDeni.. :)  i try it once with no success, but is little late in my time zone..

I check it tomorrow  again and i tell you  what happen.


Good night dear..  :) :) :)
Title: Re: Generic Application Form
Post by: JPDeni on September 24, 2009, 04:58:09 AM
Possibly I was unclear as to what you needed to do, because I made the change and it worked perfectly.

Find


if ($enable_post) {  //create new forum post with application

$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 />';
}


and replace it with


if ($enable_post) {  //create new forum post with application

$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 />';
}
Title: Re: Generic Application Form
Post by: EasyRider on September 24, 2009, 03:59:07 PM
Hi JPDeni.  :)

Thank you. I go to check it now..  :up:
Title: Re: Generic Application Form
Post by: EasyRider on September 24, 2009, 04:18:02 PM
The bold caption work  perfect..!  :) but i can't see the color (red) in text area..

Is possible to add space between the captions..? i mean like this:

Heading
empty space
Name: farkle
Age: 18
Sex: F
Do you like me?: Yes
emty space
Comments: should have the original subject line""

Title: Re: Generic Application Form
Post by: JPDeni on September 24, 2009, 04:28:01 PM
Which code did you enter? I gave you two sets of code earlier. The first only will bold the caption. The second adds the red. (I was showing you different options. :) )

It's possible to format it any way you want. Tell me exactly how you want it formatted and I'll post the code. :)
Title: Re: Generic Application Form
Post by: EasyRider on September 24, 2009, 04:42:36 PM
So, i have to try again to add the correct code..  :)

And i come back to tell you what i thing for the format and tell my if it is possible.
Title: Re: Generic Application Form
Post by: EasyRider on September 24, 2009, 10:48:31 PM
Quote from: JPDeni on September 24, 2009, 04:28:01 PM
Which code did you enter? I gave you two sets of code earlier. The first only will bold the caption. The second adds the red. (I was showing you different options. :) )

It's possible to format it any way you want. Tell me exactly how you want it formatted and I'll post the code. :)


I enter the second code with red color in caption text area option. But not any red color print in post.  Only bold captions everywhere..
Title: Re: Generic Application Form
Post by: JPDeni on September 24, 2009, 10:55:07 PM
Odd. It works perfectly on my site.

I don't know what it could be ... unless ... is it possible that you do not allow the color tag in your forum? That's the only reason I can think of that it wouldn't show.
Title: Re: Generic Application Form
Post by: ed_m2 on September 25, 2009, 11:16:49 AM
out of interest... is there any permission checking on the topic posting option ?

if i use this then the topic will be sent to a private board before being approved and moved to a public board.

so if the submitter does not have access to the private board will it still post the message ?
Title: Re: Generic Application Form
Post by: EasyRider on September 25, 2009, 12:57:12 PM
Hi JPDeni  :)  my original code is this:
(i do something  wrong..?  ???)

global $sourcedir, $ID_MEMBER, $context, $scripturl, $user_info, $db_prefix;

// Guests can't fill out the form
if ($ID_MEMBER == 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 = "ΠρέÏâ,¬ÃŽÂµÃŽÂ¹ να είναι ÏÆ'υμÏâ,¬ÃŽÂ»ÃŽÂ·ÃÂÃâ€°ÃŽÂ¼ÃŽÂ­ÃŽÂ½ÃŽÂ± ÏÅ'λα τα Ïâ,¬ÃŽÂµÃŽÂ´ÃŽÂ¯ÃŽÂ± για να είναι έγκυρη η κριτική ÏÆ'ας.";
$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
//     ),
//   );

$topicOptions = array(
'id' => 0 ,
'board' => $board_id,
'poll' =>  null,
'lock_mode' =>  null,
'sticky_mode' =>  null,
'mark_as_read' => true,
);
$fielddef =
array(
array(
'caption' =>      "Πληροφορίες ΣυνάντηÏÆ'ης",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "ÃŽâ€"μερομηνία ÏÆ'υνάντηÏÆ'ης",
'name' =>         "date",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
), 

                                  array(
'caption' =>      "ΣυμÏâ,¬ÃŽÂµÃÂÃŽÂ¹Ãâ€ ÃŽÂ¿ÃÂÃŽÂ¬ Ïâ,¬ÃÂÃŽÂ±ÃŽÂºÃâ€žÃŽÂ¿ÃÂÃŽÂµÃŽÂ¯ÃŽÂ¿Ãâ€¦",
'name' =>         "feedback1",
'type' =>         "select",
'options'=>                        "select,κακη,μετρια,καλη",
'defaultvalue' => "1",
'required' =>     1
),
                                  array(
'caption' =>      "Î¥Ïâ,¬ÃŽÂ·ÃÂÃŽÂµÃÆ'ίες ΚοÏâ,¬ÃŽÂ­ÃŽÂ»ÃŽÂ±Ãâ€š",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
                                  array(
'caption' =>      "ΕμφάνιÏÆ'η (Ïâ,¬ÃÂÃÅ'ÏÆ'ωÏâ,¬ÃŽÂ¿)",
'name' =>         "feedback5",
'type' =>         "select",
'options' =>      "select,3,4,5,6,7,8,9,10",
'defaultvalue' => "1",
'required' =>     1
),
                                  array(
'caption' =>      "ΕμφάνιÏÆ'η (ÏÆ'ώμα)",
'name' =>         "feedback5",
'type' =>         "select",
'options' =>      "select,3,4,5,6,7,8,9,10",
'defaultvalue' => "1",
'required' =>     1
),
   array(
'caption' =>      "Γενική ÏÆ'υμÏâ,¬ÃŽÂµÃÂÃŽÂ¹Ãâ€ ÃŽÂ¿ÃÂÃŽÂ¬",
'name' =>         "feedback6",
'type' =>         "select",
'options' =>      "select,3,4,5,6,7,8,9,10",
'defaultvalue' => "1",
'required' =>     1
),
array(
'caption' =>      "ΕÏâ,¬ÃŽÂ¹ÃŽÂºÃŽÂ¿ÃŽÂ¹ÃŽÂ½Ãâ€°ÃŽÂ½ÃŽÂ¯ÃŽÂ±",
'name' =>         "feedback7",
'type' =>         "select",
'options' =>      "select,3,4,5,6,7,8,9,10",
'defaultvalue' => "1",
'required' =>     1
),
array(
'caption' =>      "ΔιάθεÏÆ'η ÏÆ'το ÏÆ'εξ/ÏÆ'υμμετοχή",
'name' =>         "feedback8",
'type' =>         "select",
'options' =>      "select,3,4,5,6,7,8,9,10",
'defaultvalue' => "1",
'required' =>     1
),
                                  array(
'caption' =>      "Πεολειχία",
'name' =>         "feedback2",
'type' =>         "select",
'options' =>      "select,ÃŽÅ"ε Ïâ,¬ÃÂÃŽÂ¿Ãâ€ Ãâ€¦ÃŽÂ»ÃŽÂ±ÃŽÂºÃâ€žÃŽÂ¹ÃŽÂºÃŽÂ¿,Χωρις Ïâ,¬ÃÂÃŽÂ¿Ãâ€ Ãâ€¦ÃŽÂ»ÃŽÂ±ÃŽÂºÃâ€žÃŽÂ¹ÃŽÂºÃŽÂ¿",
'defaultvalue' => "1",
'required' =>     1
),
                                  array(
'caption' =>      "A-level (Ïâ,¬ÃÂÃâ€°ÃŽÂºÃâ€žÃŽÂ¹ÃŽÂºÃÅ')",
'name' =>         "feedback3",
'type' =>         "select",
'options' =>      "select,ναι,οχι",
'defaultvalue' => "1",
'required' =>     1
),
                                  array(
'caption' =>      "ΕκÏÆ'Ïâ,¬ÃŽÂµÃÂÃŽÂ¼ÃŽÂ¬Ãâ€žÃâ€°ÃÆ'η",
'name' =>         "feedback4",
'type' =>         "select",
'options' =>      "select,Στο ÏÆ'ωμα,Στο Ïâ,¬ÃÂÃŽÂ¿ÃÆ'ωÏâ,¬ÃŽÂ¿,Στο ÏÆ'τομα (τα φτυνει),Στο ÏÆ'τομα (τα καταÏâ,¬ÃŽÂ¹ÃŽÂ½ÃŽÂµÃŽÂ¹)",
'defaultvalue' => "1",
'required' =>     1
),
array(
'caption' =>      "ΣχέÏÆ'η αÏâ,¬ÃÅ'δοÏÆ'ης/τιμής",
'name' =>         "check",
'type' =>         "select",
'options' =>      "select,3,4,5,6,7,8,9,10",
'defaultvalue' => "1",
'required' =>     1
), 
                                 array(
'caption' =>      "Θα ξαναεβλεÏâ,¬ÃŽÂµÃâ€š την κοÏâ,¬ÃŽÂµÃŽÂ»ÃŽÂ±?",
'name' =>         "feedback",
'type' =>         "select",
'options' =>      "select,Ναι,Οχι,MÏâ,¬ÃŽÂ¿ÃÂÃŽÂµÃŽÂ¹, δεν εχω αÏâ,¬ÃŽÂ¿Ãâ€ ÃŽÂ±ÃÆ'ιÏÆ'ει ακομα..",
'defaultvalue' => "1",
'required' =>     1
), 

array(
'caption' =>      "Overall",
'name' =>       "comments",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),

);

$topicOptions = array(
'id' => $_REQUEST['topic'] ,
'board' => $board_id,
'poll' =>  null,
'lock_mode' =>  null,
'sticky_mode' =>  null,
'mark_as_read' => true,
);

$thanks_text = "ΕυχαριÏÆ'τουμε για την κριτικη! ";




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


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



$topic = $_GET['topic'];
$result = db_query("SELECT m.subject
FROM {$db_prefix}messages as m, {$db_prefix}topics as t
WHERE m.ID_TOPIC = $topic
AND t.ID_FIRST_MSG = m.ID_MSG", __FILE__, __LINE__);

$row = mysql_fetch_assoc($result);
$subject = $row['subject'];
mysql_free_result($result);

$postbody = 'ΕυχαριÏÆ'τουμε για την κριτικη ' . $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' => 'Re: ' . $subject,
'body' => addslashes($postbody) ,
'icon' => 'xx',
'smileys_enabled' => true,
'attachments' =>  array(),
);
$topicOptions = array(
'id' => $_GET['topic'] ,
'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,
);
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>';  }

$place = $_SERVER['REQUEST_URI'];
echo '
<form action="' . $place . '" 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; font-weight:bold;">' .
$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="6" cols="50">';
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>';
}
}
Title: Re: Generic Application Form
Post by: ZarPrime on September 25, 2009, 03:01:56 PM
Quote from: ed_m on September 25, 2009, 11:16:49 AM
out of interest... is there any permission checking on the topic posting option ?

if i use this then the topic will be sent to a private board before being approved and moved to a public board.

so if the submitter does not have access to the private board will it still post the message ?

ed_m,

The original intent of this code was as an application form that could be filled out by a member that would start a new topic in a board.  The board need not be visible to the poster but it could just as easily be visible.  You set the board that the new topic is placed into in the code.  There is also a way in the code to send the Admin an EMail when the form is filled out and submitted.

ZarPrime
Title: Re: Generic Application Form
Post by: JPDeni on September 25, 2009, 03:18:47 PM
EasyRider, you have the code right. I don't know what the problem could be. I'm sorry.
Title: Re: Generic Application Form
Post by: Freddy on September 25, 2009, 04:14:59 PM
This bit....

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


Does he actually have a field called "Comments" ?

The way I read it the red will only display if the field is specifically named 'Comments'...so I am thinking he would need to test for each and every heading type that he wants to be red.

Hmmm  :-\
Title: Re: Generic Application Form
Post by: JPDeni on September 25, 2009, 04:22:04 PM
Good call, freddy! It didn't even occur to me.

EasyRider, you need to change the caption to match the field you have. It would be, I guess


elseif ($field['caption'] == 'Overall')

Title: Re: Generic Application Form
Post by: ed_m2 on September 25, 2009, 04:39:05 PM
*twiddles thumbs*
Title: Re: Generic Application Form
Post by: JPDeni on September 25, 2009, 04:43:22 PM
ed_m, ZarPrime answered your question. Or did you have another one?
Title: Re: Generic Application Form
Post by: EasyRider on September 25, 2009, 05:05:23 PM
Quote from: JPDeni on September 25, 2009, 04:22:04 PM
Good call, freddy! It didn't even occur to me.

EasyRider, you need to change the caption to match the field you have. It would be, I guess


elseif ($field['caption'] == 'Overall')






Great !!! Works !!!  :) :) :) :)   :up: :up: :up: :up: :up:

Title: Re: Generic Application Form
Post by: ed_m2 on September 25, 2009, 05:08:39 PM
Quote from: JPDeni on September 25, 2009, 04:43:22 PM
ed_m, ZarPrime answered your question. Or did you have another one?

oh yes sorry.. well in that case i just wanted to feel involved :)

you've saved me alot of dull form creation.
Title: Re: Generic Application Form
Post by: JPDeni on September 25, 2009, 05:10:10 PM
Quotewell in that case i just wanted to feel involved

LOL. :D

Quoteyou've saved me alot of dull form creation

I know what you mean. It is tedious.
Title: Re: Generic Application Form
Post by: EasyRider on September 25, 2009, 05:16:11 PM
Another one question

is possible to add empty space between captions,
and put bold & (or) custom color..?

So the finall (print ) post is like this:


Heading
Name: farkle
Age: 18
Sex: F

Another Heading
Do you like me?: Yes

Comments:  should have the original subject line""
Title: Re: Generic Application Form
Post by: EasyRider on September 25, 2009, 05:33:09 PM
Hey JPDeni.. if is "problem" for you,  is ok..

I'm just total irrelevant about php code and maybe i stress you with all this questions.. sorry.. :-\ :-\ :-\
Title: Re: Generic Application Form
Post by: JPDeni on September 25, 2009, 05:39:26 PM
No, that's okay. I think I got it figured out. Or, rather, freddy888 did. :)

Did you make the change I posted?
Title: Re: Generic Application Form
Post by: EasyRider on September 25, 2009, 06:00:39 PM
 freddy888 did it..?  sorry i didn't see it.. 

1'  to check it.  :)
Title: Re: Generic Application Form
Post by: JPDeni on September 25, 2009, 06:09:09 PM
Actually, I didn't see your post with the question.

I need you to tell me exactly what you want your final output to look like, using your fields and not mine.
Title: Re: Generic Application Form
Post by: EasyRider on September 25, 2009, 07:35:19 PM
Ok, i thing like this is perfect:





Ευχαριστούμε για την κριτική Easyrider

Overall: TEST REVIEW

Πληροφορίες Συνάντησης

Ημερομηνία συνάντησης: 1234567
Διάρκεια συνάντησης: 3 ώρες
Χωρος: Στο χωρο μου
Κόστος €: 000
Συμπεριφορά του γραφείου:  κακή

Εντυπώσεις Γενικά

Εμφάνιση (πρόσωπο): 4
Εμφάνιση (σώμα): 4
Συμπεριφορά: 3
Επικοινωνία: 3

Service

Φιλάει: Καθόλου
Πεολειχία: Με προφυλακτικο
A-level (πρωκτικό): ναι
Εκσπερμάτωση: Στο προσωπο
Εξτρά εκσπερματώσεις: Μόνο μια φορά
Διάθεση στο σεξ/συμμετοχή: 9
Σχέση απόδοσης/τιμής:  9
Θα ξαναέβλεπες την κοπέλα?: Mπορεί  

Σχόλια: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus id urna ut arcu mattis convallis. Nam consequat bibendum ullamcorper. Fusce malesuada commodo nibh, sit amet adipiscing enim commodo eget. Aliquam erat volutpat. Integer id mi urna. Curabitur egestas urna at turpis interdum at mollis odio lobortis. Vivamus eu urna tellus. Nulla interdum cursus elit. Mauris interdum urna at lorem fermentum mollis. Vivamus non arcu sed magna bibendum commodo quis vitae sem. Aliquam erat volutpat. Curabitur pellentesque, lectus ut vestibulum dapibus, quam ligula euismod leo, vitae auctor ligula leo vitae nisi. Curabitur dapibus arcu justo, sed lacinia quam. Curabitur eleifend egestas est, at eleifend eros dignissim at. Pellentesque vel nunc et dolor iaculis dapibus eu ut tellus. Suspendisse nisi mauris, rutrum in gravida id, viverra at dolor. Curabitur id volutpat tellus. Vivamus enim nulla, feugiat eu molestie et, ornare id tortor.




I add and the original code if that help.!
Title: Re: Generic Application Form
Post by: JPDeni on September 25, 2009, 08:11:18 PM
I'm not sure about all this because I don't read Greek  (I'm assuming Greek because that's what the letters look like) and the text file shows different letters for the captions than you have. I'll try to figure out what's going on, but I'm not going to guarantee anything. :)

Because of the problems with the text, I won't post the whole code, but just the code you need to change.


foreach ($fielddef as $field) {
if ($field['type'] == 'heading')
$postbody .= '<br />' . $field['caption'] . '<br /><br />';
elseif ($field['name'] == 'comments')
$postbody .= '[b]' . $field['caption'] . '[/b]: ' . $_REQUEST[$field['name']] . '<br />';
elseif ($field['name'] == 'overall')
$postbody .= $field['caption'] . ': [b]' . $_REQUEST[$field['name']] . '[/b]<br />';
else
$postbody .= '[b]' . $field['caption'] . ': [color=red]' . $_REQUEST[$field['name']] . '[/color][/b]<br />';
}
Title: Re: Generic Application Form
Post by: EasyRider on September 25, 2009, 08:19:18 PM
Ok! and.. were exactly  i m gone put this ^^^ code..??  ???
Title: Re: Generic Application Form
Post by: JPDeni on September 25, 2009, 08:23:04 PM
In the same place you put the other code.

Here's the whole section, but there's a line in there that you'll have to change back to your language.


if ($enable_post) {  //create new forum post with application



$topic = $_GET['topic'];
$result = db_query("SELECT m.subject
FROM {$db_prefix}messages as m, {$db_prefix}topics as t
WHERE m.ID_TOPIC = $topic
AND t.ID_FIRST_MSG = m.ID_MSG", __FILE__, __LINE__);

$row = mysql_fetch_assoc($result);
$subject = $row['subject'];
mysql_free_result($result);

$postbody = 'Åõ÷áñéóôïýìå ãéá ôçí êñéôéêÞ ' . $context['user']['name'] .'<br /><br/>';
foreach ($fielddef as $field) {
if ($field['type'] == 'heading')
$postbody .= '<br />' . $field['caption'] . '<br /><br />';
elseif ($field['name'] == 'comments')
$postbody .= '[b]' . $field['caption'] . '[/b]: ' . $_REQUEST[$field['name']] . '<br />';
elseif ($field['name'] == 'overall')
$postbody .= $field['caption'] . ': [b]' . $_REQUEST[$field['name']] . '[/b]<br />';
else
$postbody .= '[b]' . $field['caption'] . ': [color=red]' . $_REQUEST[$field['name']] . '[/color][/b]<br />';
}
$msgOptions = array(
'id' =>  0 ,
'subject' => 'Re: ' . $subject,
'body' => addslashes($postbody) ,
'icon' => 'xx',
'smileys_enabled' => true,
'attachments' =>  array(),
);
$topicOptions = array(
'id' => $_GET['topic'] ,
'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,
);
createPost($msgOptions, $topicOptions, $posterOptions);
}

Title: Re: Generic Application Form
Post by: EasyRider on September 25, 2009, 08:33:33 PM
OKK..!!  i try it now..!!   :up:
Title: Re: Generic Application Form
Post by: EasyRider on September 25, 2009, 08:55:28 PM
just PERFECT!! !!  :)  :) :) :) :)

i attach screen about what i print and what i thing is missing.  headers in bold, and space  between last caption and comments.


Title: Re: Generic Application Form
Post by: JPDeni on September 25, 2009, 09:06:10 PM
I thought I had done that. I guess not. :)


if ($enable_post) {  //create new forum post with application



$topic = $_GET['topic'];
$result = db_query("SELECT m.subject
FROM {$db_prefix}messages as m, {$db_prefix}topics as t
WHERE m.ID_TOPIC = $topic
AND t.ID_FIRST_MSG = m.ID_MSG", __FILE__, __LINE__);

$row = mysql_fetch_assoc($result);
$subject = $row['subject'];
mysql_free_result($result);

$postbody = 'Åõ÷áñéóôïýìå ãéá ôçí êñéôéêÞ ' . $context['user']['name'] .'<br /><br/>';
foreach ($fielddef as $field) {
if ($field['type'] == 'heading')
$postbody .= '<br />[b]' . $field['caption'] . '[/b]<br /><br />';
elseif ($field['name'] == 'comments')
$postbody .= '<br />[b]' . $field['caption'] . '[/b]: ' . $_REQUEST[$field['name']] . '<br />';
elseif ($field['name'] == 'overall')
$postbody .= $field['caption'] . ': [b]' . $_REQUEST[$field['name']] . '[/b]<br />';
else
$postbody .= '[b]' . $field['caption'] . ': [color=red]' . $_REQUEST[$field['name']] . '[/color][/b]<br />';
}
$msgOptions = array(
'id' =>  0 ,
'subject' => 'Re: ' . $subject,
'body' => addslashes($postbody) ,
'icon' => 'xx',
'smileys_enabled' => true,
'attachments' =>  array(),
);
$topicOptions = array(
'id' => $_GET['topic'] ,
'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,
);
createPost($msgOptions, $topicOptions, $posterOptions);
}


Title: Re: Generic Application Form
Post by: EasyRider on September 25, 2009, 09:47:33 PM
I HAVE ONLY 1 THING TO SAY: THANK YOUUUUUUU JPDeni..!!!!!!!!!!!!


(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi37.tinypic.com%2Fei81nb.jpg&hash=8d523977216894cd5c03ab013c09cf72939930c8)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi37.tinypic.com%2Fei81nb.jpg&hash=8d523977216894cd5c03ab013c09cf72939930c8)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi37.tinypic.com%2Fei81nb.jpg&hash=8d523977216894cd5c03ab013c09cf72939930c8)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi37.tinypic.com%2Fei81nb.jpg&hash=8d523977216894cd5c03ab013c09cf72939930c8)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi37.tinypic.com%2Fei81nb.jpg&hash=8d523977216894cd5c03ab013c09cf72939930c8)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi37.tinypic.com%2Fei81nb.jpg&hash=8d523977216894cd5c03ab013c09cf72939930c8)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi37.tinypic.com%2Fei81nb.jpg&hash=8d523977216894cd5c03ab013c09cf72939930c8)
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi34.tinypic.com%2F2rghkw7.jpg&hash=961028ce36d367c4b21dce65f3e2f06bfd77e171)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi34.tinypic.com%2F2rghkw7.jpg&hash=961028ce36d367c4b21dce65f3e2f06bfd77e171)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi34.tinypic.com%2F2rghkw7.jpg&hash=961028ce36d367c4b21dce65f3e2f06bfd77e171)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi34.tinypic.com%2F2rghkw7.jpg&hash=961028ce36d367c4b21dce65f3e2f06bfd77e171)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi34.tinypic.com%2F2rghkw7.jpg&hash=961028ce36d367c4b21dce65f3e2f06bfd77e171)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi34.tinypic.com%2F2rghkw7.jpg&hash=961028ce36d367c4b21dce65f3e2f06bfd77e171)

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi38.tinypic.com%2F2niur8g.jpg&hash=b1f37f2bad307ba068de09be81a8000b590e5177)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi38.tinypic.com%2F2niur8g.jpg&hash=b1f37f2bad307ba068de09be81a8000b590e5177)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi38.tinypic.com%2F2niur8g.jpg&hash=b1f37f2bad307ba068de09be81a8000b590e5177)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi38.tinypic.com%2F2niur8g.jpg&hash=b1f37f2bad307ba068de09be81a8000b590e5177)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi38.tinypic.com%2F2niur8g.jpg&hash=b1f37f2bad307ba068de09be81a8000b590e5177)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi38.tinypic.com%2F2niur8g.jpg&hash=b1f37f2bad307ba068de09be81a8000b590e5177)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi38.tinypic.com%2F2niur8g.jpg&hash=b1f37f2bad307ba068de09be81a8000b590e5177)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi38.tinypic.com%2F2niur8g.jpg&hash=b1f37f2bad307ba068de09be81a8000b590e5177)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi38.tinypic.com%2F2niur8g.jpg&hash=b1f37f2bad307ba068de09be81a8000b590e5177)



(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F30w5dn6.jpg&hash=75cd2b9e4f3488b0506e0602603163d7e0860a67)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F30w5dn6.jpg&hash=75cd2b9e4f3488b0506e0602603163d7e0860a67)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F30w5dn6.jpg&hash=75cd2b9e4f3488b0506e0602603163d7e0860a67)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F30w5dn6.jpg&hash=75cd2b9e4f3488b0506e0602603163d7e0860a67)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F30w5dn6.jpg&hash=75cd2b9e4f3488b0506e0602603163d7e0860a67)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F30w5dn6.jpg&hash=75cd2b9e4f3488b0506e0602603163d7e0860a67)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F30w5dn6.jpg&hash=75cd2b9e4f3488b0506e0602603163d7e0860a67)
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F303l3dw.jpg&hash=276eec25a82e22bd0d6ba5a9d7343a1c53a7823e)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F303l3dw.jpg&hash=276eec25a82e22bd0d6ba5a9d7343a1c53a7823e)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F303l3dw.jpg&hash=276eec25a82e22bd0d6ba5a9d7343a1c53a7823e)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F303l3dw.jpg&hash=276eec25a82e22bd0d6ba5a9d7343a1c53a7823e)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F303l3dw.jpg&hash=276eec25a82e22bd0d6ba5a9d7343a1c53a7823e)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F303l3dw.jpg&hash=276eec25a82e22bd0d6ba5a9d7343a1c53a7823e)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F303l3dw.jpg&hash=276eec25a82e22bd0d6ba5a9d7343a1c53a7823e)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi35.tinypic.com%2F303l3dw.jpg&hash=276eec25a82e22bd0d6ba5a9d7343a1c53a7823e)
Title: Re: Generic Application Form
Post by: JPDeni on September 25, 2009, 09:48:54 PM
:D

You're welcome. I'm glad I was able to help.
Title: Re: Generic Application Form
Post by: Freddy on September 26, 2009, 02:43:30 PM
Brilliant job JP  ;D
Title: Re: Generic Application Form
Post by: ed_m2 on October 01, 2009, 08:48:36 AM
little additional question for me, i'm adapting this with two purposes:
1 - events thread creation & submission to the smf calendar with custom fields
2 - custom events search based on form input
in the first case the form data is used with an INSERT statement and the later case with a SELECT.

i'm a little concerned on security and how best to add extra validation to some of the fields to prevent SQL insertion.

if i was feeling fancy i'd suggest an extra parameter with each field for a string of illegal characters that is checked at the same location as the madatory fields.

any suggestions / tips / tricks ?
Title: Re: Generic Application Form
Post by: JPDeni on October 01, 2009, 02:34:49 PM
You might want to take a look at /Sources/Post.php, function createPost to see how SMF deals with security.
Title: Re: Generic Application Form
Post by: Freddy on October 01, 2009, 02:47:30 PM
There's an SMF function I use to clean up passed variables; you might want to take a look at that too :

cleanRequest... (http://support.simplemachines.org/function_db/index.php?action=view_function;id=359)

Really whenever you insert data to the DB you want to be using that.

Also it's a good idea to check the session before you do anything too :

checkSession... (http://support.simplemachines.org/function_db/index.php?action=view_function;id=404)

If you are worried by HTML being inserted you can use this PHP function :

strip_tags... (http://www.php.net/manual/pl/function.strip-tags.php)

There's probably a whole host of other solutions too - I would try Google and see what methods other people suggest to protect from SQL injection.
Title: Re: Generic Application Form
Post by: IchBin on October 01, 2009, 06:09:05 PM
If you're using SMF's db functions everything is already cleaned for you.
Title: Re: Generic Application Form
Post by: ed_m2 on October 02, 2009, 11:21:54 AM
thanks.. i'll do some digging.

http://www.simplemachines.org/community/index.php?topic=119652.0
and
http://www.smfmods.org/wiki/Security_practices

are my intitial hits.

i've yet to see any info on whether db_query input is cleaned or not.
Title: Re: Generic Application Form
Post by: Freddy on October 02, 2009, 11:42:06 AM
Quotei've yet to see any info on whether db_query input is cleaned or not.

I'm not sure either, but I don't doubt IchBin.  I use it because in the SMF Coding Guidelines it says use it - though docs often go out of date, though maybe they mean for regular db queries rather than the SMF function.

You can take a look for yourself :

http://www.simplemachines.org/community/index.php?topic=159824.0

There's also the practice of casting number to integers too, which is mentioned in the docs.
Title: Re: Generic Application Form
Post by: JPDeni on October 02, 2009, 03:06:20 PM
ed_m, this is code from db_query:


// First, we clean strings out of the query, reduce whitespace, lowercase, and trim - so we can check it over.
if (empty($modSettings['disableQueryCheck']))
{
$clean = '';
$old_pos = 0;
$pos = -1;
while (true)
{
$pos = strpos($db_string, '\'', $pos + 1);
if ($pos === false)
break;
$clean .= substr($db_string, $old_pos, $pos - $old_pos);

while (true)
{
$pos1 = strpos($db_string, '\'', $pos + 1);
$pos2 = strpos($db_string, '\\', $pos + 1);
if ($pos1 === false)
break;
elseif ($pos2 == false || $pos2 > $pos1)
{
$pos = $pos1;
break;
}

$pos = $pos2 + 1;
}
$clean .= ' %s ';

$old_pos = $pos + 1;
}
$clean .= substr($db_string, $old_pos);
$clean = trim(strtolower(preg_replace(array('~\s+~s', '~/\*!40001 SQL_NO_CACHE \*/~', '~/\*!40000 USE INDEX \([A-Za-z\_]+?\) \*/~'), array(' ', '', ''), $clean)));

// We don't use UNION in SMF, at least so far.  But it's useful for injections.
if (strpos($clean, 'union') !== false && preg_match('~(^|[^a-z])union($|[^[a-z])~s', $clean) != 0)
$fail = true;
// Comments?  We don't use comments in our queries, we leave 'em outside!
elseif (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
$fail = true;
// Trying to change passwords, slow us down, or something?
elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[a-z])~s', $clean) != 0)
$fail = true;
elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
$fail = true;
// Sub selects?  We don't use those either.
elseif (preg_match('~\([^)]*?select~s', $clean) != 0)
$fail = true;

if (!empty($fail))
{
log_error('Hacking attempt...' . "\n" . $db_string, $file, $line);
fatal_error('Hacking attempt...', false);
}
}


Looks like there's checking there.
Title: Re: Generic Application Form
Post by: EasyRider on October 10, 2009, 04:25:06 PM
Hi Deni !  :) :)


Is possible to add a simple date picker in some field..? for example like this one:

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi36.tinypic.com%2F68xxc5.png&hash=244a0b1137d57a97dd9d1b80965c74bd9de91e5a)


or something more simple..  :-X



I add the code in zip attachment !
Title: Re: Generic Application Form
Post by: JPDeni on October 11, 2009, 04:13:56 PM
I wouldn't know how to do it, I'm afraid. This is way beyond the capability of my simple form.
Title: Re: Generic Application Form
Post by: EasyRider on October 11, 2009, 04:30:14 PM
No problem deni ! I knew it was very difficult..

But you already  done so many things about.. !

Anwy,  thank you  dear !!  :) :) :)
Title: Re: Generic Application Form
Post by: chevman74 on October 20, 2009, 03:46:35 PM
Noted  :-\
Title: Re: Generic Application Form
Post by: JPDeni on October 20, 2009, 04:14:16 PM
Quote
I'm having troubles with this part of the code in the latest "SMF 2.0"

This code is only to be used with TinyPortal and TinyPortal does not yet work with SMF 2.0. Therefore, you need to find other code to use. Or go back to SMF1.10 and TinyPortal.
Title: Re: Generic Application Form
Post by: umiya on October 28, 2009, 05:49:13 PM
How would we make the posted thread a different color then the questions asked. and how to space the questions out

Quote from: JPDeni on May 23, 2009, 11:04:28 PM
This is designed for those who wish to make an application form for their site.


type:php article
author:JPDeni
name:Application Form

How would we make the posted thread a different color then the questions?
version:.1
date:16 Apr 2009
discussion topic:http://www.tinyportal.net/index.php/topic,9840.0.html (sort of)
description:
  • Creates a form to be filled out by prospective members
  • Form fields are defined within the text, to include text, textarea, select, radio and checkbox fields
  • Results can be emailed to an admin, posted to a specified board or both


global $sourcedir, $ID_MEMBER, $context, $scripturl, $user_info;

// Guests can't fill out the form
if ($ID_MEMBER == 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=4;


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

$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(),
);
$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,
);
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>';
}
}


23 Sep 2009 -- Minor alteration to make the script work in blocks as well as articles.
Title: Re: Generic Application Form
Post by: umiya on October 29, 2009, 02:05:18 PM
Sorry for my double post But I am in need of some help. I am trying to make the posted form text a different color then the questions asked. Make it easier to read this way. And maybe put a space between each question asked as well. I figured it would have to be in here somewhere

/ 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" style="color: red">';

// 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>';
}


Anyhelp will be greatly appreciated.
Title: Re: Generic Application Form
Post by: JPDeni on October 29, 2009, 02:29:57 PM
Quoteto make the posted form text a different color then the questions asked
Is this on the form or in the post?

It seems that you're asking about the post, but the code you posted is the printout of the form.
Title: Re: Generic Application Form
Post by: umiya on October 29, 2009, 03:10:05 PM
Either way, All I want colored is the answers when they post. And to have them spaced out accordingly

http://darknesscalls.net/index.php?topic=8.0

see how it looks cluttered?
Title: Re: Generic Application Form
Post by: JPDeni on October 29, 2009, 03:23:37 PM
No, you aren't concerned with "either way." You want it in the post. Here is the section that deals with the format of the post:


$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 />';
}


So, let's say you wanted the caption to be red.


else
  $postbody .=  '[color=red]' . $field['caption'] . '[/color]: ' . $_REQUEST[$field['name']] . '<br />';


You can adjust the printout to look like you want, using bbc code.

To be honest, the thing that makes your post look most crowded is that you don't have any spaces between the numbers and the words in your captions. You will have to add the spaces in the configuration section.

If you want to have multiple spaces show up, you may need to do a little bit of other tweaking. But it will likely improve by your adding spaces after your numbers and adding color to the captions.
Title: Re: Generic Application Form
Post by: Bika on November 30, 2009, 10:34:40 AM
Hello JPDeni :) and thank you for an amazing code.
I've done my share of editing and tuning your code for my liking.

I've also been trying to unlock a feature that could be possible but since i know a little php but nothing about how to command the forum features.

I'd like to add the ability to create a poll with every poll that maybe says ..
"Accept?" with a "Yes" & a "No" as possible answers, obviously if its possible to make dynamic question and answers it would be even better.

That's my application form Current APP (http://sanctumguild.org/index.php?page=2).

Thank you :)
//narl!
Title: Re: Generic Application Form
Post by: JPDeni on November 30, 2009, 04:14:21 PM
QuoteI'd like to add the ability to create a poll with every poll that maybe says ..
"Accept?" with a "Yes" & a "No" as possible answers, obviously if its possible to make dynamic question and answers it would be even better.

I don't understand what you want. You can make radio buttons with the code as it is. If you give me more detail and why you want it, I'll see if I can help you get what you want.
Title: Re: Generic Application Form
Post by: Bika on November 30, 2009, 05:16:52 PM
The Forum post it creates :), i'd like to have it as a poll instead of being a normal forum post.
Title: Re: Generic Application Form
Post by: JPDeni on November 30, 2009, 05:19:48 PM
Oh. I see. I'll have to look at how polls are created in SMF.
Title: Re: Generic Application Form
Post by: JPDeni on November 30, 2009, 07:01:34 PM
I'll give you the edits here and also change the code in the first post.

Change the first line

global $sourcedir, $ID_MEMBER, $context, $scripturl, $user_info;


to


global $sourcedir, $ID_MEMBER, $context, $scripturl, $user_info, $db_prefix;


After


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


(your options may be different)

Add


// Poll options
$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


After


         if ($enable_post) {  //create new forum post with application


Add


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;


Change


            $topicOptions = array(
               'id' => 0 ,
               'board' => $board_id,
               'poll' =>  null
               'lock_mode' =>  null,
               'sticky_mode' =>  null,
               'mark_as_read' => true,
            );


to


            $topicOptions = array(
               'id' => 0 ,
               'board' => $board_id,
               'poll' =>  $ID_POLL,
               'lock_mode' =>  null,
               'sticky_mode' =>  null,
               'mark_as_read' => true,
            );
Title: Re: Generic Application Form
Post by: Bika on November 30, 2009, 07:09:52 PM
Thank youuuuuuuuuuuuuuuuuu!
;)  :up:

Awesome cakes!
Title: Re: Generic Application Form
Post by: alhaudhie on December 11, 2009, 05:51:07 PM
any option to get user can upload image?

like    <form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">
   
        <h1>
            Upload form
        </h1>
       
        <p>
            <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
        </p>
       
        <p>
            <label for="file">File to upload:</label>
            <input id="file" type="file" name="file">
        </p>
               
        <p>
            <label for="submit">Press to...</label>
            <input id="submit" type="submit" name="submit" value="Upload me!">
        </p>
   
    </form>


or with bbc imagelink?
Title: Re: Generic Application Form
Post by: JPDeni on December 11, 2009, 05:55:59 PM
No. That would be beyond the capability of this mod.
Title: Re: Generic Application Form
Post by: alhaudhie on December 11, 2009, 05:59:26 PM
how about using bbc image?
Title: Re: Generic Application Form
Post by: JPDeni on December 11, 2009, 06:13:35 PM
If you want to add that, give it a try. Play around with it. Experiment.

Off the top of my head, I don't know how to do it, but maybe you can work it out.
Title: Re: Generic Application Form
Post by: nadrojcote on January 13, 2010, 07:58:06 PM
Very Nice job!! this is perfect!

but one thing,

is there anyway I could make it underline or bold the headings within the post?

thanks!
Title: Re: Generic Application Form
Post by: JPDeni on January 13, 2010, 08:15:08 PM
Obviously not perfect ;-)

Look for

$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 />';
            }


To make the headings bold, change it to


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


To make the heading underlined change it to


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


You can add any BBC code within quotation marks that you want.
Title: Re: Generic Application Form
Post by: nadrojcote on January 13, 2010, 08:17:24 PM
:D thank you very much I was messing around with that but i guess i didnt have the tags within the quotes like i was supposed to, your da best!
Title: Re: Generic Application Form
Post by: JPDeni on January 13, 2010, 08:23:23 PM
You're welcome. :) Sometimes it just takes an example to see how it's done. Now that you've seen the pattern, you'll be able to do anything you want.
Title: Re: Generic Application Form
Post by: EasyRider on February 08, 2010, 06:36:30 PM
Hi JPDeni and big thank you for this useful tool. :)

1 question.

Is possible to appear the review post in front page block..?

I mean to appear both in normal topic, and print also one post in first page block.

Like rss block option..  ???
Title: Re: Generic Application Form
Post by: JPDeni on February 08, 2010, 06:47:28 PM
You can display a post from a topic in a block. You would just need to know the post number. Or you could post the first post from the most recent topic from a given board, which I suppose would be the closest thing to an rss feed. That would be something completely separate from this code, though.
Title: Re: Generic Application Form
Post by: EasyRider on February 08, 2010, 07:10:25 PM
I see. thank you for your answer.

Until now the form print new review post only in topic i choose. This topic have not only reviews but normal posts also.

I wand to appear only the review post in front page (block) and also in his topic as is now, at once.

is that possimple..?  :)


Title: Re: Generic Application Form
Post by: JPDeni on February 08, 2010, 07:21:27 PM
You have a board.


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


In this board are topics, which are created by the script. The first post in each topic is the results of the form. Right?

It is possible that you have other topics in this board. Do you have other topics in this board or are all of the topics only the ones created by the form? That will determine what code I give you.
Title: Re: Generic Application Form
Post by: EasyRider on February 08, 2010, 07:55:53 PM
Not exactly. You make edit in this form to add the review form in existing topic. that is the different.

Look in this post
http://www.tinyportal.net/index.php?topic=29670.msg247281#msg247281
Title: Re: Generic Application Form
Post by: JPDeni on February 08, 2010, 08:07:06 PM
Okay. The code originally was supposed to do what I said. When the form is submitted a new topic is made, with the results at the top so that the rest of the topic is people discussing the form results. But things have changed.

I'll have to try out the idea I have first. It won't be done until tomorrow -- maybe later. Just to let you know what I have in mind, it would be changing the form code so it writes the same post to the body of the block when it writes it to the forum.
Title: Re: Generic Application Form
Post by: EasyRider on February 08, 2010, 08:20:47 PM
Thank you JPDeni! await for.  :) :)
Title: Re: Generic Application Form
Post by: raxavier69 on June 03, 2010, 01:22:51 AM
hey does this work with rc3 and latest tp? im getting "You must be logged in before you can apply. " even as admin logged in
Title: Re: Generic Application Form
Post by: JPDeni on June 03, 2010, 01:27:28 AM
Quotedoes this work with rc3 and latest tp?

Probably not. I haven't looked at the code for a very long time and I haven't looked closely at the changes for RC3. It might work with SMF1.whatever and the newest TP, but it's unlikely that it would work with the changes that they've put into SMF2.
Title: Re: Generic Application Form
Post by: raxavier69 on June 03, 2010, 01:44:17 AM
Quote from: JPDeni on June 03, 2010, 01:27:28 AM
Quotedoes this work with rc3 and latest tp?

Probably not. I haven't looked at the code for a very long time and I haven't looked closely at the changes for RC3. It might work with SMF1.whatever and the newest TP, but it's unlikely that it would work with the changes that they've put into SMF2.
:( any chance of an rc3 version of this :D ?
Title: Re: Generic Application Form
Post by: JPDeni on June 03, 2010, 01:51:13 AM
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.
Title: Re: Generic Application Form
Post by: 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
Title: Re: Generic Application Form
Post by: JPDeni on June 03, 2010, 04:51:51 AM
Go ahead, ZP.
Title: Re: Generic Application Form
Post by: raxavier69 on June 03, 2010, 05:10:43 AM
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
Title: Re: Generic Application Form
Post by: ZarPrime on June 06, 2010, 07:59:38 PM
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>';
   }
}
Title: Re: Generic Application Form
Post by: raxavier69 on June 07, 2010, 01:12:21 AM
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

Title: Re: Generic Application Form
Post by: ZarPrime on June 07, 2010, 05:50:46 AM
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
Title: Re: Generic Application Form
Post by: JPDeni on June 07, 2010, 04:17:40 PM
You've learned very well, ZP.  :smitten:
Title: Re: Generic Application Form
Post by: ZarPrime on June 07, 2010, 05:24:11 PM
Thanks JPDeni. :smitten: :D My mentor has been an excellent instructor.  IMHO, I have learned from the best. ;)

ZarPrime
Title: Re: Generic Application Form
Post by: Ken. on June 07, 2010, 05:40:49 PM
Alright now... that's enough of that mushiness!  :2funny:






j/k JP & ZP, you both do great work.  O0
Title: Re: Generic Application Form
Post by: raxavier69 on June 07, 2010, 07:07:41 PM
Seems to work, but when its posted is looks weird im looking at the code, isnt it suppose to be in a table? or certain things bold?
Title: Re: Generic Application Form
Post by: ZarPrime on June 08, 2010, 12:46:16 AM
raxavier69,

No tables, no bold.  As I said, this is the barebones code.  You can make any formatting changes to it that you desire.

As an example, when I first started working on editing the code for our support form, a resulting topic looked something like this ...
http://talesofthehavenexpanse.com/smf2test/index.php?topic=8.0

It looked quite a bit more unorganized than I really wanted it to be so I made changes.  After making some edits to the code, the resulting topics looked more like this ...
http://talesofthehavenexpanse.com/smf2test/index.php?topic=38.0

What I can do is post the code that I ended up with and if you want to make comparisons with the barebones code, you can see what I did to get the look I wanted.  Is that what you want me to do?

ZarPrime
Title: Re: Generic Application Form
Post by: raxavier69 on June 08, 2010, 12:59:07 AM
i got fieldmaster to help thanks :) looks great. will post how it looks in a bit.
Title: Re: Generic Application Form
Post by: raxavier69 on June 08, 2010, 01:20:49 AM
YAY!!
looks hot thanks for all the help
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg641.imageshack.us%2Fimg641%2F9499%2Fformt.png&hash=17b93c3d825a60b38d603fb3b6f760e75ff7f19e)

only thing is the check box i tried yes,no,maybe and yes;no;maybe and still didnt work. maybe its just me
Title: Re: Generic Application Form
Post by: JPDeni on June 08, 2010, 01:36:14 AM
The checkbox can not have multiple options. It's the sort of thing that is "check this if you want to get the newsletter." If you want several options, use a radio field.
Title: Re: Generic Application Form
Post by: raxavier69 on June 08, 2010, 01:48:13 AM
ah ty :)
Title: Re: Generic Application Form
Post by: Bloodlvst on August 25, 2010, 07:42:50 AM
Quote from: ZarPrime on June 08, 2010, 12:46:16 AM
raxavier69,

No tables, no bold.  As I said, this is the barebones code.  You can make any formatting changes to it that you desire.

As an example, when I first started working on editing the code for our support form, a resulting topic looked something like this ...
http://talesofthehavenexpanse.com/smf2test/index.php?topic=8.0

It looked quite a bit more unorganized than I really wanted it to be so I made changes.  After making some edits to the code, the resulting topics looked more like this ...
http://talesofthehavenexpanse.com/smf2test/index.php?topic=38.0

What I can do is post the code that I ended up with and if you want to make comparisons with the barebones code, you can see what I did to get the look I wanted.  Is that what you want me to do?

ZarPrime

I'd love that. It works great on my site except I want to make the forum output more human-readable :)
Title: Re: Generic Application Form
Post by: ZarPrime on August 26, 2010, 11:40:45 PM
If you want to setup this form for use with SMF 1.1.11, you should use the code in this topic ...
http://www.tinyportal.net/index.php?topic=29670.msg236779#msg236779

If you want to setup this form for use with SMF 2.0 RC3 and the latest TiinyPortal, you should use the code from this topic ... http://www.tinyportal.net/index.php?topic=29670.msg263560#msg263560

The code, with the markup as changed by me, for use as a Support Form on TinyPortal with SMF 2.0 RC3 and the latest TinyPortal, is shown below.  It was never used by us as there wasn't enough of a reason to use it.  However, it can be used as an example of how this code can be used to setup your own form.  Please be aware that there is a call to an image on my test site in the code.  I have changed the link to that image to a non-existent image.  You should refer to the differences between this code and the code in http://www.tinyportal.net/index.php?topic=29670.msg263560#msg263560 as this code below is specifically for SMF 2.0 RC3.


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 post a support topic.';
else {

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


// CONFIGURATION SECTION

$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/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>";
$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' =>      "Briefly describe the issue in the Subject line below",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Brief Subject",
'name' =>         "subject",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1   
),
array(
'caption' =>      "Please give a detailed description of the problem in the area below",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Detailed Description",
'name' =>       "detail",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "Click Yes below only if you have TinyPortal installed, else click No",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "TinyPortal Installed?",
'name' =>         "installed",
'type' =>         "radio",
'options' =>      "Yes,No",
'defaultvalue' => "",
'required' =>     1
), 
array(
'caption' =>      "What version of SMF is installed?",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Select SMF version",
'name' =>         "smf",
'type' =>         "select",
'options' =>      ",Older than 1.1,1.1,1.1.1,1.1.2,1.1.3,1.1.4,1.1.5,1.1.6,1.1.7,1.1.8,1.1.9,1.1.10,2.0 beta 3,2.0 beta 3.1,2.0 beta 4,2.0 RC1,2.0 RC1-1,2.0 RC1.2,2.0 RC2,2.0 RC3",
'defaultvalue' => "",
'required' =>     1
), 
array(
'caption' =>      "What version of TinyPortal is installed?",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Select TP version",
'name' =>         "tp",
'type' =>         "select",
'options' =>      ",Older than v0.98,v0.98,v1.0 beta 1,v1.0 beta 2,v1.0 beta 3,v1.0 beta 4,v1.0 beta 5,v1.0 beta 5-1,v1.0 beta 5.2,TP Not Installed",
'defaultvalue' => "",
'required' =>     1
), 
array(
'caption' =>      "Link to your site, e.g., http://www.tinyportal.net/index.php",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Your Site url",
'name' =>         "url",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1   
),
array(
'caption' =>      "List the Primary Theme and version that exhibits the problem",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Your Primary Theme",
'name' =>         "theme",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1   
),
array(
'caption' =>      "List other Themes and versions that exhibit the problem",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Other Themes in use",
'name' =>       "otherthemes",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "List the Primary Browser that exhibits the problem and the version below",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Your Primary Browser",
'name' =>         "browser",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1   
),
array(
'caption' =>      "Other Browsers that exhibit the problem and their versions below",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Other Browsers",
'name' =>       "otherbrowsers",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Cut and Paste your Mods list from the Package Manager into the area below",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Your Mod List",
'name' =>       "modlist",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "Paste related Error Messages below",
'name' =>         "heading",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Error Messages",
'name' =>       "errorlist",
'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=3;


//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 = 'Support Topic';
$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

$postbody = 'Support Topic has been initiated by ' . $context['user']['name'] .'<br /><br />';
foreach ($fielddef as $field) {
// Now we aren't going to print the headings or the subject in the post
if ($field['type'] == 'heading' || $field['name'] == 'subject')
echo '
<br />';
else
$postbody .=  '[b]' . $field['caption'] . '[/b]: ' . $_REQUEST[$field['name']] . '<br />';
}
$msgOptions = array(
'id' =>  0 ,
// Use the one below if poster doesn't enter subject
//'subject' => '[Pending] Application of ' . addslashes($_REQUEST['realname']),
// Use the one below if poster does enter subject
'subject' => ($_REQUEST['subject']),
'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,
);
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 an asterisk (*).</div>';  }

echo '
<form action="' . $scripturl . '?page='  . $_GET['page'] . '" 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="left">';
              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="5" cols="80">';
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>';
}
}
Title: Re: Generic Application Form
Post by: RaXavier on November 13, 2010, 11:52:41 PM
nvm tp error
Title: Re: Generic Application Form
Post by: ZarPrime on November 14, 2010, 12:30:39 AM
Quote from: RaXavier on November 13, 2010, 11:52:41 PM
nvm tp error

RaXavier,

I have no idea what you are talking about.  This topic was last posted to over 2 and a half months ago.  Was this post a mistake?

ZarPrime
Title: Re: Generic Application Form
Post by: Bloodlvst on March 19, 2011, 02:10:44 AM
So I finally got around to actually putting this into practice!
But I'm having a problem, it still makes everything bold, but I want each response to be indented and bulleted. It posts the code itself, but doesn't cause it to appear correctly. If I click modify and preview, it's okay...it seems like something from the form to the post is going awry. Any ideas?

Just in case it helps, the line in question is:
$postbody .=  '[list][b]' . $field['caption'] . '[/b][list][li]' . $_REQUEST[$field['name']] . '[/li][/list]<br />';

I should also note that if anyone can help me figure out how to make them numbered like how RaXavier did, that would be awesome. :)

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 have an account on our site before you can apply.';
else {

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


// CONFIGURATION SECTION

   $intro_form = "So you've decided you want to join The Angels Of Armageddon. Great! Just keep the following in mind when applying:<br><br><b>1.</b> Be involved in the forums and be active on the server as much as possible. This shows us that you're an active part of the community and are serious about joining, and will help your application more than you might think!<br><b>2.</b> Having a mic is a requirement to join. We may be willing to make exceptions for extreme cases, and you can make your case in the comments of your app.<br><br><b>Approval Process</b>:<br>Upon posting your application, a forum post will be made in the Applications Section of the board. In your post, anyone may comment and/or vote, though we will only count votes from members, and if we look for input outside of the clan, only our regulars will be taken into consideration. It's best to have been playign with us long enough that we know who you are, it's hard to want you to join us if we don't know you.<br><br>Once your application has been received, you must garner a 'yes' vote from at least 60% of the Joint Chiefs Of Staff. At that point your status as a member will be either accepted or rejected by Bloodlvst (very rarely will you actually be rejected), and you will officially be a member and be given tags. You may not wear tags until all of this has occured. <br>";
   $thanks_text = "Thanks for applying! You can check out the progress of your application in the Applications Section.";

// 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' =>      "Name On Server",
            'name' =>         "nickname",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
         array(
            'caption' =>      "Real Name",
            'name' =>         "realname",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
         array(
            'caption' =>      "Location",
            'name' =>         "location",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),         
         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' => "16",
            'required' =>     1
         ),
         array(
            'caption' =>      "Ping On Server",
            'name' =>         "ping",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),         
         array(
            'caption' =>      "Do you have a mic?",
            'name' =>         "mic",
            'type' =>         "select",
            'options' =>      "No,Yes",
            'defaultvalue' => "No",
            'required' =>     1
         ),     
         array(
            'caption' =>      "Why do you want to join?",
            'name' =>       "joinreason",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1
         ),
         array(
            'caption' =>      "Tell us a bit about yourself",
            'name' =>         "bio",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),           
         array(
            'caption' =>      "Any other comments?",
            'name' =>         "comments",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),
         array(
            'caption' =>      "Did a member invite you?",
            'name' =>         "invite",
            'type' =>         "radio",
            'options' =>      "Yes,No",
            '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=13;
//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
$postbody = 'Forum post autogenerated by application form on behalf of ' . $context['user']['name'] .'<br /><br />';
foreach ($fielddef as $field) {
// Now we aren't going to print the headings or the subject in the post
if ($field['type'] == 'heading' || $field['name'] == 'subject')
echo '
<br />';
else
$postbody .=  '[list][b]' . $field['caption'] . '[/b][li]' . $_REQUEST[$field['name']] . '[/li][/list]<br />';
}
$msgOptions = array(
'id' =>  0 ,
// Use the one below if poster doesn't enter subject
'subject' => '[Pending] Application of ' . addslashes($_REQUEST['nickname']),
// Use the one below if poster does enter subject
//'subject' => ($_REQUEST['subject']),
'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,
);
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 an asterisk (*).</div>';  }

echo '
<form action="' . $scripturl . '?page='  . $_GET['page'] . '" 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="left">';
              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="5" cols="80">';
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>';
}
}

Title: Re: Generic Application Form
Post by: Freddy on March 19, 2011, 11:53:18 AM
Remove the extra 'list' from your code :

Change...

$postbody .=  '[list][b]' . $field['caption'] . '[/b][list][li]' . $_REQUEST[$field['name']] . '[/li][/list]<br />';

To this :

$postbody .=  '[list][b]' . $field['caption'] . '[/b][li]' . $_REQUEST[$field['name']] . '[/li][/list]<br />';

And see if that works.
Title: Re: Generic Application Form
Post by: Bloodlvst on March 19, 2011, 01:48:44 PM
Thanks Freddy, didn't notice that. Unfortunately it didn't work though :(

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg25.imageshack.us%2Fimg25%2F5813%2Ftestqm.png&hash=b64763b79233f2b7c3e31c7e8cb90ccae3557069)

Like I said, if I hit modify, and don't change anything, it will be normal, but I'd rather it just work when someone applies. :)
Title: Re: Generic Application Form
Post by: Freddy on March 20, 2011, 01:24:44 PM
What are your SMF and TP versions Mr Bloodlvust ?
Title: Re: Generic Application Form
Post by: Bloodlvst on March 20, 2011, 02:05:13 PM
Freddy, I'm rocking SMF 2.0 RC4 and TP 1.0 RC1
Title: Re: Generic Application Form
Post by: Freddy on March 20, 2011, 02:29:19 PM
OK yeah, I am getting the same results here.  Leave it with me a while.
Title: Re: Generic Application Form
Post by: Freddy on March 20, 2011, 02:45:24 PM
See if this works, it seems okay here.  After taking a proper look, it was the way 'list' was getting used.  I should have suggested removing the first one, not the second doh !


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 have an account on our site before you can apply.';
else {

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


// CONFIGURATION SECTION

   $intro_form = "So you've decided you want to join The Angels Of Armageddon. Great! Just keep the following in mind when applying:<br><br><b>1.</b> Be involved in the forums and be active on the server as much as possible. This shows us that you're an active part of the community and are serious about joining, and will help your application more than you might think!<br><b>2.</b> Having a mic is a requirement to join. We may be willing to make exceptions for extreme cases, and you can make your case in the comments of your app.<br><br><b>Approval Process</b>:<br>Upon posting your application, a forum post will be made in the Applications Section of the board. In your post, anyone may comment and/or vote, though we will only count votes from members, and if we look for input outside of the clan, only our regulars will be taken into consideration. It's best to have been playign with us long enough that we know who you are, it's hard to want you to join us if we don't know you.<br><br>Once your application has been received, you must garner a 'yes' vote from at least 60% of the Joint Chiefs Of Staff. At that point your status as a member will be either accepted or rejected by Bloodlvst (very rarely will you actually be rejected), and you will officially be a member and be given tags. You may not wear tags until all of this has occured. <br>";
   $thanks_text = "Thanks for applying! You can check out the progress of your application in the Applications Section.";

// 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' =>      "Name On Server",
            'name' =>         "nickname",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
         array(
            'caption' =>      "Real Name",
            'name' =>         "realname",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
         array(
            'caption' =>      "Location",
            'name' =>         "location",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),         
         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' => "16",
            'required' =>     1
         ),
         array(
            'caption' =>      "Ping On Server",
            'name' =>         "ping",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),         
         array(
            'caption' =>      "Do you have a mic?",
            'name' =>         "mic",
            'type' =>         "select",
            'options' =>      "No,Yes",
            'defaultvalue' => "No",
            'required' =>     1
         ),     
         array(
            'caption' =>      "Why do you want to join?",
            'name' =>       "joinreason",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1
         ),
         array(
            'caption' =>      "Tell us a bit about yourself",
            'name' =>         "bio",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),           
         array(
            'caption' =>      "Any other comments?",
            'name' =>         "comments",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),
         array(
            'caption' =>      "Did a member invite you?",
            'name' =>         "invite",
            'type' =>         "radio",
            'options' =>      "Yes,No",
            '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=13;
//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
$postbody = 'Forum post autogenerated by application form on behalf of ' . $context['user']['name'] .'<br /><br />';
$fieldCounter = 0;
foreach ($fielddef as $field) {
$fieldCounter++;
// Now we aren't going to print the headings or the subject in the post
if ($field['type'] == 'heading' || $field['name'] == 'subject')
echo '
<br />';
else
$postbody .=  $fieldCounter . '. [b]' . $field['caption'] . '[/b][list][li]' . $_REQUEST[$field['name']] . '[/li][/list]<br />';
}
$msgOptions = array(
'id' =>  0 ,
// Use the one below if poster doesn't enter subject
'subject' => '[Pending] Application of ' . addslashes($_REQUEST['nickname']),
// Use the one below if poster does enter subject
//'subject' => ($_REQUEST['subject']),
'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,
);
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 an asterisk (*).</div>';  }

echo '
<form action="' . $scripturl . '?page='  . $_GET['page'] . '" 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="left">';
              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="5" cols="80">';
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>';
}
}
Title: Re: Generic Application Form
Post by: Bloodlvst on March 20, 2011, 06:44:45 PM
Thanks a ton Freddy! Works perfectly!

You da man! :D
Title: Re: Generic Application Form
Post by: NCSurfer on February 19, 2012, 02:56:30 AM
Thanks Freddy for the assistance. I do have an issue though. When I submit the form, the Thank you page does not show as well as the board I chose does not get a post of the form in it.

Using;
    Powered by SMF 2.0 RC5 | SMF © 2006â€"2011, Simple Machines LLC
    TinyPortal 1.0 RC1 | © 2005-2010 BlocWeb
    XHTML
    RSS
    WAP2
    Day Relax by Skinmod

And here is the code;
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 registered on our site before you can sign up for Horse Camp.';
else {

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


// CONFIGURATION SECTION

   $intro_form = "So you've decided you would like to attend Six Star Stables Horse Camp this summer. That is Great News! Just keep the following in mind when signing up:<br><br>
<b>1.</b> You will be required to HAVE A GREAT WEEK and be prepared to learn about horses. <br/><br/>
<b>2.</b>We will have barn projects that all the kids will participate in. <br><br>
We work this camp around the campers need to not only learn about a Horse Farm but also discipline, confidence, focus and FUN!<br> Please fill out all the fields in the Sign Up Form below. This way we will be able to get a good idea of who you are prior to meeting you for the first time.<br><br> ";

   $thanks_text = "Thanks for signing up for Horse Camp! One of our Staff members will be getting in touch with you soon. Also, please check back for NEWS about the barn on the forums.<br><br>
Thank You again. <br>
Six Star Stables Staff";

// 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' =>      "Name On The Website",
            'name' =>         "nickname",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
         array(
            'caption' =>      "Real Name",
            'name' =>         "realname",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
         array(
            'caption' =>      "Location",
            'name' =>         "location",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),         
         array(
            'caption' =>      "Age",
            'name' =>         "age",
            'type' =>         "select",
            'options' =>      "6,7,8,9,10,11,12,13,14,15,16+",
            'defaultvalue' => "10",
            'required' =>     1
         ),
         array(
            'caption' =>      "Phone Number",
            'name' =>         "phonenum",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),         
         array(
            'caption' =>      "Is phone best means of contact?",
            'name' =>         "phonecont",
            'type' =>         "select",
            'options' =>      "No,Yes",
            'defaultvalue' => "Yes",
            'required' =>     1
         ),     
         array(
            'caption' =>      "Why would you like to attend Horse Camp?",
            'name' =>       "joinreason",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1
         ),
         array(
            'caption' =>      "Tell us a bit about yourself",
            'name' =>         "bio",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),           
         array(
            'caption' =>      "Any other comments?",
            'name' =>         "comments",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0 
         ),
         array(
            'caption' =>      "Did a Barn Member invite you?",
            'name' =>         "invite",
            'type' =>         "radio",
            'options' =>      "Yes,No",
            '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=4.0;
//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
$postbody = 'Forum post autogenerated by application form on behalf of ' . $context['user']['name'] .'<br /><br />';
$fieldCounter = 0;
foreach ($fielddef as $field) {
$fieldCounter++;
// Now we aren't going to print the headings or the subject in the post
if ($field['type'] == 'heading' || $field['name'] == 'subject')
echo '
<br />';
else
$postbody .=  $fieldCounter . '. [b]' . $field['caption'] . '[/b][list][li]' . $_REQUEST[$field['name']] . '[/li][/list]<br />';
}
$msgOptions = array(
'id' =>  0 ,
// Use the one below if poster doesn't enter subject
'subject' => '[Pending] Application of ' . addslashes($_REQUEST['nickname']),
// Use the one below if poster does enter subject
//'subject' => ($_REQUEST['subject']),
'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,
);
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, those with an asterisk are required(*).</div>';  }

echo '
<form action="' . $scripturl . '?page='  . $_GET['page'] . '" 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="left">';
              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="5" cols="80">';
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>';
}
}


Thanks for any help.
Title: Re: Generic Application Form
Post by: ZarPrime on February 20, 2012, 01:24:35 AM
NCSurfer,

Since I see you on, let's try a couple of things.  First of all,

Code (Find) Select

$board_id=4.0;

and
Code (Replace With) Select

$board_id=4;


and see if that fixes the issue with the topic being posted.

Secondly, your $thanks_text probably needs to be edited so that it's all on one line though I might be able to check this and see what's going on with that.

ZarPrime
Title: Re: Generic Application Form
Post by: IchBin on February 20, 2012, 02:15:45 AM
I cleaned up the code a little bit. Change everything that I saw to be XHTML compliant and also change the tab/spacing to make it look more like SMF standards. Fixed the $board_id variable for you too. I'm sure that 4.0 makes a difference in the problem you were having as 4.0 is not necessarily an int, but a decimal.


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 registered on our site before you can sign up for Horse Camp.';
else {

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


// CONFIGURATION SECTION

$intro_form = "So you've decided you would like to attend Six Star Stables Horse Camp this summer.
That is Great News! Just keep the following in mind when signing up:<br /><br />
<b>1.</b> You will be required to HAVE A GREAT WEEK and be prepared to learn about horses. <br/><br/>
<b>2.</b>We will have barn projects that all the kids will participate in. <br /><br />
We work this camp around the campers need to not only learn about a Horse Farm but also discipline, confidence, focus and FUN!<br /> Please fill out all the fields in the Sign Up Form below. This way we will be able to get a good idea of who you are prior to meeting you for the first time.<br /><br /> ";

$thanks_text = "Thanks for signing up for Horse Camp! One of our Staff members will be getting in touch with you soon.
Also, please check back for NEWS about the barn on the forums.<br /><br />Thank You again. <br />Six Star Stables Staff";

// 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' => "Name On The Website",
'name' => "nickname",
'type' => "text",
'options' => "",
'defaultvalue' => "",
'required' =>
),
array(
'caption' => "Real Name",
'name' => "realname",
'type' => "text",
'options' => "",
'defaultvalue' => "",
'required' =>
),
array(
'caption' => "Location",
'name' => "location",
'type' => "text",
'options' => "",
'defaultvalue' => "",
'required' =>
),         
array(
'caption' => "Age",
'name' => "age",
'type' => "select",
'options' => "6,7,8,9,10,11,12,13,14,15,16+",
'defaultvalue' => "10",
'required' => 1
),
array(
'caption' => "Phone Number",
'name' => "phonenum",
'type' => "text",
'options' => "",
'defaultvalue' => "",
'required' =>
),         
array(
'caption' => "Is phone best means of contact?",
'name' => "phonecont",
'type' => "select",
'options' => "No,Yes",
'defaultvalue' => "Yes",
'required' => 1
),     
array(
'caption' => "Why would you like to attend Horse Camp?",
'name' =>        "joinreason",
'type' => "textarea",
'options' => "",
'defaultvalue' => "",
'required' => 1
),
array(
'caption' => "Tell us a bit about yourself",
'name' => "bio",
'type' => "textarea",
'options' => "",
'defaultvalue' => "",
'required' =>
),
array(
'caption' => "Any other comments?",
'name' => "comments",
'type' => "textarea",
'options' => "",
'defaultvalue' => "",
'required' =>
),
array(
'caption' => "Did a Barn Member invite you?",
'name' => "invite",
'type' => "radio",
'options' => "Yes,No",
'defaultvalue' => "",
'required' =>
),
);
//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 = 4; //(single digit only. No decimals)

//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
$postbody = 'Forum post autogenerated by application form on behalf of ' . $context['user']['name'] .'<br /><br />';
$fieldCounter = 0;
foreach ($fielddef as $field) {
$fieldCounter++;
// Now we aren't going to print the headings or the subject in the post
if ($field['type'] == 'heading' || $field['name'] == 'subject')
echo '
<br />';
else
$postbody .=  $fieldCounter . '. [b]' . $field['caption'] . '[/b][list][li]' . $_REQUEST[$field['name']] . '[/li][/list]<br />';
}
$msgOptions = array(
'id' =>  0,
// Use the one below if poster doesn't enter subject
'subject' => '[Pending] Application of ' . addslashes($_REQUEST['nickname']),
// Use the one below if poster does enter subject
//'subject' => ($_REQUEST['subject']),
'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,
);
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, those with an asterisk are required(*).</div>';

echo '
<form action="' . $scripturl . '?page='  . $_GET['page'] . '" 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="left">';
              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="5" cols="80">';
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>';
}
}
Title: Re: Generic Application Form
Post by: NCSurfer on February 20, 2012, 03:57:04 AM
Great, thanks IchBin.

I just tried out the new code but still do not get the Thank You page or a post in the forums. Double checked all the info but can not seem to make it work. I did not change anything from the code you modified. Any other ideas?

Thanks
Title: Re: Generic Application Form
Post by: IchBin on February 20, 2012, 04:21:00 AM
I just copy and pasted it into my test site. Enabled email to see if I'd get an email as well. When I submit the form it both sends me an email as well as posts the topic to the board I assigned in the variable. Not sure what your problem is. Check your logs and see if you have any errors or something.
Title: Re: Generic Application Form
Post by: NCSurfer on February 21, 2012, 12:34:29 AM
ccf6e5b21196e9b3446427b095065057
Type of error: Undefined
http://www.sxxxxxxxxxs.com/index.php?
8: Undefined index: page
File: /home/sxxxxxxxxs/public_html/Themes/default/languages/Post.english.php (tp_below sub template - eval?)
Line: 228

This is the error that is showing up.
Title: Re: Generic Application Form
Post by: IchBin on February 21, 2012, 12:55:26 AM
You need to disable template eval. If you are running SMF2 you can do that in the Admin > Configuration > server settings.

Clear the log then try the page again. Post the new error in the log when you get it. You can actually search for the error first, and likely find that it's been fixed.
Title: Re: Generic Application Form
Post by: NCSurfer on February 21, 2012, 02:24:35 AM
I turned the evaluation off, but still get this error. Also, I still am not getting the thank you or post in forum when submitting the form.

File: /home/sixstars/public_html/Themes/default/TPsubs.template.php(112) : eval()'d code
Line: 232
Title: Re: Generic Application Form
Post by: IchBin on February 21, 2012, 02:49:38 AM
You need to post the full error. Which includes the URL. The error you posted is saying that you have an error in either a PHP article or block. If the error you posted is not in relation to the article code you are using here, I'm afraid there won't be anything we can do to help you.
Title: Re: Generic Application Form
Post by: NCSurfer on February 21, 2012, 04:02:29 AM
Sorry, this is the error that is showing up.

http://www.sxxxxxxxs dot com/index.php?http://www.sxxxxxxxs dot com/
8: Undefined index: page
File: /home/sixstars/public_html/Themes/default/TPsubs.template.php(112) : eval()'d code
Line: 232

why would it have this line http://www.sxxxxxxxs dot com/index.php?http://www.sxxxxxxxs dot com/ with the domain twice?
Title: Re: Generic Application Form
Post by: IchBin on February 21, 2012, 02:10:47 PM
My guess is that the error is from one of your blocks. You can disable your custom blocks and then enable them one by one to see which one is throwing the error. But I don't think the error is related to your problem with this code.
Title: Re: Generic Application Form
Post by: GreenEyed on September 06, 2012, 07:51:58 PM
We've been using this Form for a while and love it.  Have made changes to it using you guru's ideas (bold lettering, colors, etc)  so I'm sure this is a problem on my end than the form.


We have recently tried to add a recruiter's address to the form for an email send as well and it won't work.  The site does send notifications for PMs and new member joins just fine.

Is this a switch I need to turn on somewhere or something else?

Using SMF 2.0.2 and TP 1.104.
Title: Re: Generic Application Form
Post by: ZarPrime on September 10, 2012, 04:46:06 AM
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
Title: Re: Generic Application Form
Post by: GreenEyed on September 13, 2012, 09:56:51 PM
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>';
   }
}
Title: Re: Generic Application Form
Post by: IchBin on September 14, 2012, 05:50:43 PM
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.
Title: Re: Generic Application Form
Post by: GreenEyed on September 14, 2012, 06:25:22 PM
No go for the test mails.  I will dig into the PHPmail issue then.

Thanks much, all!
Title: Re: Generic Application Form
Post by: GreenEyed on September 14, 2012, 07:50:04 PM
Okay guys, I have it working now!  :D  It was an issue on cpanel and we have emails going out.  Much obliged, Ich!
Title: Re: Generic Application Form
Post by: IchBin on September 14, 2012, 08:31:35 PM
woohoo. Glad you got it working.
Title: Re: Generic Application Form
Post by: GreenEyed on November 21, 2012, 06:25:33 PM
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?
Title: Re: Generic Application Form
Post by: ZarPrime on November 23, 2012, 01:02:02 AM
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
Title: Re: Generic Application Form
Post by: GreenEyed on December 09, 2012, 06:06:04 AM
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
Title: Re: Generic Application Form
Post by: leroymcqy on March 24, 2013, 03:21:19 AM
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.
Title: Re: Generic Application Form
Post by: IchBin on March 26, 2013, 09:35:26 PM
The last I remember this code was only for SMF1. Did I miss the update somewhere in this topic?
Title: Re: Generic Application Form
Post by: leroymcqy on March 29, 2013, 12:39:28 AM
i gotten it fixed. i found a updated source code for it. thanks for the help