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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 321
  • Total: 321

Generic Application Form

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

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

JPDeni

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.

umiya

#141
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.

umiya

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.

JPDeni

#143
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.

umiya

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?

JPDeni

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.

Bika

#146
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.

Thank you :)
//narl!

JPDeni

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.

Bika

The Forum post it creates :), i'd like to have it as a poll instead of being a normal forum post.

JPDeni

Oh. I see. I'll have to look at how polls are created in SMF.

This website is proudly hosted on Crocweb Cloud Website Hosting.