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,913
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 448
  • Total: 448

[Done!] Join Us! form

Started by mebymyself, October 19, 2006, 08:10:13 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Azphat12

global $sourcedir, $ID_MEMBER, $context ;


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 = "<center><h4><font color=white>Even if this is nothing like the normal Applications that you are used too, we still expect that every field that requires a written answer to be well written.<p>Please take the time to fill out each field, as this is your first impression to the guild.</p></font></h4> </center><br>";   // Can include html

$thanks_text = "<center><h3><font color=white>Thanks for applying. Your application has been submitted successfully.<br>We'll review your application and get back to you.<p>Typical response time is 24-48 hours.</p>If you are not contacted by then, please message an officer ingame to discuss your application status.<p>Thank You,<br>Dark Aftermath Recruitment</p></h3></font></center>"; // what is displayed after the form is submitted

// 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' =>      "Personal Info",
      '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' =>      "18,13,14,15,16,17,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' =>      "Email",
      'name' =>         "charemail",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
    ),
array(
      'caption' =>      "Member Referral",
      'name' =>         "referral",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     0
    ),
array(
      'caption' =>      "Character Info",
      'name' =>         "heading1",
      'type' =>         "heading",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     0
    ),
array(
      'caption' =>      "Character Name",
      'name' =>         "charname",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1   
    ),
array(
      'caption' =>      "Level",
      'name' =>         "charlevel",
      'type' =>         "select",
      'options' =>      "80,79,78,77,76,75,74,73,72,71",
      'defaultvalue' => "80",
      'required' =>     1
    ),
array(
      'caption' =>      "Race",
      'name' =>         "charrace",
      'type' =>         "select",
      'options' =>      "Draenei,Dwarf,Gnome,Human,Night Elf",
      'defaultvalue' => "Draenei",
      'required' =>     1
    ),
array(
      'caption' =>      "Class",
      'name' =>         "charclass",
      'type' =>         "select",
      'options' =>      "Death Knight,Druid,Hunter,Mage,Paladin,Priest,Rogue,Shaman,Warlock,Warrior",
      'defaultvalue' => "Death Knight",
      'required' =>     1
    ),
array(
      'caption' =>      "Days played",
      'name' =>         "charplayed",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1   
    ),
       array(
      'caption' =>      "Profession 1",
      'name' =>         "prof1",
      'type' =>         "select",
      'options' =>      "None,Herbalism,Mining,Skinning,Alchemy,Blacksmithing,Enchanting,Engineering,Leatherworking,Tailoring,Jewelcrafting,Inscription",
      'defaultvalue' => "None",
      'required' =>     1
    ),
array(
      'caption' =>      "Profession 2",
      'name' =>         "prof2",
      'type' =>         "select",
      'options' =>      "None,Herbalism,Mining,Skinning,Alchemy,Blacksmithing,Enchanting,Engineering,Leatherworking,Tailoring,Jewelcrafting,Inscription",
      'defaultvalue' => "None",
      'required' =>     1
    ),
array(
      'caption' =>      "Primary Spec?",
      'name' =>         "primaryspec",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
    ),
array(
      'caption' =>      "Secondary Spec?",
      'name' =>         "secondaryspec",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
    ),
array(
      'caption' =>      "Armory Link?",
      'name' =>         "armory",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
    ),
array(
      'caption' =>      "Why you speced this way",
      'name' =>         "specinfo",
      'type' =>         "textarea",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
    ),
array(
     'caption' =>      "Willing to respec?",
      'name' =>         "specstats",
      'type' =>         "textarea",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
    ),
       array(
      'caption' =>      "Additional Questions",
      'name' =>         "heading2",
      'type' =>         "heading",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     0
          ),
array(
      'caption' =>      "What can you offer Dark Aftermath?",
      'name' =>         "offer",
      'type' =>         "textarea",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
    ),
array(
      'caption' =>      "What are you looking for in Dark Aftermath?",
      'name' =>         "looking",
      'type' =>         "textarea",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
    ),
array(
      'caption' =>      "Additional Comments?",
      'name' =>         "decision",
      'type' =>         "textarea",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
    ),
array(
      'caption' =>      "Competency Test",
      'name' =>         "heading3",
      'type' =>         "heading",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     0
    ),
);



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

// email address of recruitment staff member
$email_address='recruitment@darkaftermath.org';

//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
      if (!isset($_REQUEST['mathtest']) or ($_REQUEST['mathtest'] <> 12))
      $errors[] = 'You didn' . "'" . 't get the math problem correct';

  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 = 'Recruitment Application';
  $body = 'Recruitment application has been made by ' . $context['user']['name'] .
          ' from IP Address ' . $user_info['ip'] . '
              ';
foreach ($fielddef as $field) {
        if ($field['type'] == 'heading')
           $postbody .= '[color=white][u][b]' . $field['caption'] . '[/b][/u][/color]<br />';
        elseif ($field['type'] == 'textarea') {
$text = $_REQUEST[$field['name']];
$length = 30; // maximum length of a line
$output = '';
while (strlen($text) > $length) {
$textlen = strlen($text);
$part = substr($text,0,$length);
$partlen = $length;
while (substr($part,-1) <> ' ') {
$part = substr($part,0,-1);
--$partlen;
}
$output .= $part . '<br />';
$text = substr($text,$partlen,($textlen-$partlen));
}
$output .= $text;
          $postbody .= '[color=#5BAFDF]' . $field['caption'] . '[/color]<br />' . $output . '<br />';        }
        else
          $postbody .= '[color=#5BAFDF]' . $field['caption'] . '[/color]  ' . $_REQUEST[$field['name']] . '<br />';
}
      $postbody .= '';

      $msgOptions = array(
        'id' =>  0 ,
        'subject' => '[Pending] Application of ' . $_REQUEST['charname'] . ' ' . $_REQUEST['charclass'],
        '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;
  }
}

// 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="' . $scripturl . '?page='  . $_GET['page'] . '" method="post">
        <INPUT id="submitted" name="submitted" type="hidden" value="TRUE" />
        <center><table width="50%">';
  $bg = 'windowbg2';
  foreach ($fielddef as $field) {
    if ($field['type'] == 'text') {
      echo '<TR class ="' . $bg . '">
              <TD width = "200px" align="right">';
              if ($field['required'] == 1) { echo '* '; }
              echo $field['caption'] . ':</TD>
              <TD align="left"><INPUT id="' . $field['name'] . '" name="' . $field['name'] . '" type="text" value ="' . $fieldvalue[$field['name']] . '" /></TD>
            </TR>';
    }
    elseif ($field['type'] == 'radio') {
      echo '<TR class ="' . $bg . '">
              <TD width = "200px" align="right">';
              if ($field['required'] == 1) { echo '* '; }
              echo $field['caption'] . ':</TD>
              <TD align="left">';
              $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 . ' ';
              }
              echo '</TD>
            </TR>';   
    }
    elseif ($field['type'] == 'checkbox') {
      echo '<TR class ="' . $bg . '">
              <TD width = "200px" align="right">';
              echo $field['caption'] . ':</TD>
              <TD align="left">';
                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'] . '
            </TR>';   
    }
    elseif ($field['type'] == 'select') {
      echo '<TR class ="' . $bg . '">
              <TD width = "200px" align="right">';
              if ($field['required'] == 1) { echo '* '; }
              echo $field['caption'] . ':</TD>
              <TD align="left"><SELECT id="' . $field['name'] . '" name="' . $field['name'] . '" style="WIDTH: 152px" value ="';
              echo '" />';
              $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></TD>
            </TR>';
    }   
    elseif ($field['type'] == 'textarea') {
      echo '<TR class ="' . $bg . '">
            <TD width = "200px" align="right">';
            if ($field['required'] == 1) { echo '* '; }
            echo $field['caption'] . ':</TD>
            <TD align="left"><TEXTAREA id="' . $field['name'] . '" name="' . $field['name'] . '" rows="4" cols="40">';
            echo $fieldvalue[$field['name']];
            echo '</' . 'TEXTAREA></TD>
  </TR>';
    }
  elseif ($field['type'] == 'heading') {
      echo '<tr><TD colspan="2"><center><table cellSpacing="1" cellPadding="1" width="50%"><TR>
            <font size="8"><TD style="text-align: center; text-decoration: underline;"><font size="4">' .
            $field['caption'] .
            '</font></TD></TR></table></center></td></tr>';
    }
    if ($bg == 'windowbg2') { $bg = 'windowbg'; }
    else { $bg = 'windowbg2'; }
  }

    echo '
     <TR class ="' . $bg . '"><td>What is 5 + 7? (enter a number)</td>
     <td><input type="text" name="mathtest" value=""></td></tr>';
    if ($bg == 'windowbg2') { $bg = 'windowbg'; }
    else { $bg = 'windowbg2'; }
    echo '
    <TR class ="' . $bg . '">
      <TD colspan="2" align="center">
  <br>
        <INPUT type="submit" value="Submit">
        <INPUT type="reset" value="Reset"></TD>
    </TR></TABLE></center></form>';
}
}

JPDeni

I found the problem. Things just weren't put the right place.

I also reformatted the code a bit to make it easier to read and edit in the future.


global $sourcedir, $ID_MEMBER, $context ;

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 = "<center><h4><font color=white>Even if this is nothing like the normal Applications that you are used too, we still expect that every field that requires a written answer to be well written.<p>Please take the time to fill out each field, as this is your first impression to the guild.</p></font></h4> </center><br>";   // Can include html

$thanks_text = "<center><h3><font color=white>Thanks for applying. Your application has been submitted successfully.<br>We'll review your application and get back to you.<p>Typical response time is 24-48 hours.</p>If you are not contacted by then, please message an officer ingame to discuss your application status.<p>Thank You,<br>Dark Aftermath Recruitment</p></h3></font></center>"; // what is displayed after the form is submitted

// 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' =>      "Personal Info",
'name' =>         "heading1",
'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' =>      "18,13,14,15,16,17,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' =>      "Email",
'name' =>         "charemail",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "Member Referral",
'name' =>         "referral",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Character Info",
'name' =>         "heading1",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "Character Name",
'name' =>         "charname",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1   
),
array(
'caption' =>      "Level",
'name' =>         "charlevel",
'type' =>         "select",
'options' =>      "80,79,78,77,76,75,74,73,72,71",
'defaultvalue' => "80",
'required' =>     1
),
array(
'caption' =>      "Race",
'name' =>         "charrace",
'type' =>         "select",
'options' =>      "Draenei,Dwarf,Gnome,Human,Night Elf",
'defaultvalue' => "Draenei",
'required' =>     1
),
array(
'caption' =>      "Class",
'name' =>         "charclass",
'type' =>         "select",
'options' =>      "Death Knight,Druid,Hunter,Mage,Paladin,Priest,Rogue,Shaman,Warlock,Warrior",
'defaultvalue' => "Death Knight",
'required' =>     1
),
array(
'caption' =>      "Days played",
'name' =>         "charplayed",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1   
),
array(
'caption' =>      "Profession 1",
'name' =>         "prof1",
'type' =>         "select",
'options' =>      "None,Herbalism,Mining,Skinning,Alchemy,Blacksmithing,Enchanting,Engineering,Leatherworking,Tailoring,Jewelcrafting,Inscription",
'defaultvalue' => "None",
'required' =>     1
),
array(
'caption' =>      "Profession 2",
'name' =>         "prof2",
'type' =>         "select",
'options' =>      "None,Herbalism,Mining,Skinning,Alchemy,Blacksmithing,Enchanting,Engineering,Leatherworking,Tailoring,Jewelcrafting,Inscription",
'defaultvalue' => "None",
'required' =>     1
),
array(
'caption' =>      "Primary Spec?",
'name' =>         "primaryspec",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "Secondary Spec?",
'name' =>         "secondaryspec",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "Armory Link?",
'name' =>         "armory",
'type' =>         "text",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "Why you speced this way",
'name' =>         "specinfo",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "Willing to respec?",
'name' =>         "specstats",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "Additional Questions",
'name' =>         "heading1",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
array(
'caption' =>      "What can you offer<br>Dark Aftermath?",
'name' =>         "offer",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "What are you looking<br>for in Dark Aftermath?",
'name' =>         "looking",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "Additional Comments?",
'name' =>         "decision",
'type' =>         "textarea",
'options' =>      "",
'defaultvalue' => "",
'required' =>     1
),
array(
'caption' =>      "Competency Test",
'name' =>         "test",
'type' =>         "heading",
'options' =>      "",
'defaultvalue' => "",
'required' =>     0
),
);



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

// email address of recruitment staff member
$email_address='recruitment@darkaftermath.org';

//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
if (!isset($_REQUEST['mathtest']) or ($_REQUEST['mathtest'] <> 12))
$errors[] = 'You didn' . "'" . 't get the math problem correct';

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 = 'Recruitment Application';
$body = 'Recruitment application has been made by ' . $context['user']['name'] .
' from IP Address ' . $user_info['ip'] . '
';
foreach ($fielddef as $field) {
$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 .= '[color=white][u][b]' . $field['caption'] . '[/b][/u][/color]<br />';
elseif ($field['type'] == 'textarea') {
$text = $_REQUEST[$field['name']];
$length = 30; // maximum length of a line
$output = '';
while (strlen($text) > $length) {
$textlen = strlen($text);
$part = substr($text,0,$length);
$partlen = $length;
while (substr($part,-1) <> ' ') {
$part = substr($part,0,-1);
--$partlen;
}
$output .= $part . '<br />';
$text = substr($text,$partlen,($textlen-$partlen));
}
$output .= $text;
$postbody .= '[color=#5BAFDF]' . $field['caption'] . '[/color]<br />' . $output . '<br />';
}
else
$postbody .= '[color=#5BAFDF]' . $field['caption'] . '[/color]  ' . $_REQUEST[$field['name']] . '<br />';
}
$msgOptions = array(
'id' =>  0 ,
'subject' => '[Pending] Application of ' . $_REQUEST['charname'] . ' ' . $_REQUEST['charclass'],
'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;
}
}

// 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="' . $scripturl . '?page='  . $_GET['page'] . '" method="post">
<INPUT id="submitted" name="submitted" type="hidden" value="TRUE" />
<center><table width="50%">';
$bg = 'windowbg2';
foreach ($fielddef as $field) {
if ($field['type'] == 'text') {
echo '<TR class ="' . $bg . '">
<TD width = "200px" align="right">';
              if ($field['required'] == 1) { echo '* '; }
              echo $field['caption'] . ':</TD>
<TD align="left"><INPUT id="' . $field['name'] . '" name="' . $field['name'] . '" type="text" value ="' . $fieldvalue[$field['name']] . '" /></TD>
</TR>';
}
elseif ($field['type'] == 'radio') {
echo '<TR class ="' . $bg . '">
<TD width = "200px" align="right">';
if ($field['required'] == 1) { echo '* '; }
echo $field['caption'] . ':</TD>
<TD align="left">';
$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 . ' ';
}
echo '</TD>
</TR>';   
}
elseif ($field['type'] == 'checkbox') {
echo '<TR class ="' . $bg . '">
<TD width = "200px" align="right">';
echo $field['caption'] . ':</TD>
<TD align="left">';
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'] . '</TD>
</TR>';   
}
elseif ($field['type'] == 'select') {
echo '<TR class ="' . $bg . '">
<TD width = "200px" align="right">';
if ($field['required'] == 1) { echo '* '; }
echo $field['caption'] . ':</TD>
<TD align="left"><SELECT name="' . $field['name'] . '" style="WIDTH: 152px" />';
$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></TD>
</TR>';
}   
elseif ($field['type'] == 'textarea') {
echo '<TR class ="' . $bg . '">
<TD width = "200px" align="right">';
if ($field['required'] == 1) { echo '* '; }
echo $field['caption'] . ':</TD>
<TD align="left"><TEXTAREA id="' . $field['name'] . '" name="' . $field['name'] . '" rows="4" cols="40">';
echo $fieldvalue[$field['name']];
echo '</' . 'TEXTAREA></TD>
</TR>';
}
elseif ($field['type'] == 'heading') {
echo '<tr><TD colspan="2">
<center><table cellSpacing="1" cellPadding="1" width="50%"><TR>
<TD style="text-align: center; text-decoration: underline;"><font size="4">' .
$field['caption'] .
'</font></TD></TR></table></center></td></tr>';
}
if ($bg == 'windowbg2') { $bg = 'windowbg'; }
else { $bg = 'windowbg2'; }
}
echo '
<TR class ="' . $bg . '"><td>What is 5 + 7? (enter a number)</td>
<td><input type="text" name="mathtest" value=""></td></tr>';
if ($bg == 'windowbg2') { $bg = 'windowbg'; }
else { $bg = 'windowbg2'; }
echo '
<TR class ="' . $bg . '">
<TD colspan="2" align="center">
<br />
<INPUT type="submit" value="Submit">
<INPUT type="reset" value="Reset"></TD>
</TR></TABLE></center></form>';
}
}

Azphat12

That worked great.  I just have to play with the width of the wrap, but everything else is fantastic.  Thank you so much!!

Azphat12

Have 1 other small question.....

On the math question, is there a way for it to post the answer into the forum?  Or post a specific word in the forum like "Passed" or something?

or alternate method...

I have a heading called Competency Test.  On the app they see that.  On the forum it shows it, but there is no answer.  Is it possible to remove the heading in the forum, but keep it in the app similar to how the math question does.

Either way would be fine.  whichever is easier

JPDeni

You can put anything in the forum post that you want. Just add it to the $postbody variable.

shadrach

Sorry if this is a stupid question, but if I just want to add more questions, do I just make an array, or do I need to add to the code farther on as well?

JPDeni

You're talking about the code that I wrote -- the most recent one? If so, just add another array.

Inny

I was thinking if its possible to make the form in 3 steps. Currently its 2, the form and the thanks text.

Will be possible to have the intro text as a separate step?

(Using JPDeni's Form)

JPDeni

#378
Just about anything is possible.


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

// Guests can't fill out the form
if ($ID_MEMBER == 0)
    echo 'You must be logged in before you can apply.';
else {
if (!isset($_REQUEST['form'])) {
$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.";
$link = '<a href="' . $scripturl . '?page=' . $_REQUEST['page'] . ';form=1">Go to the form</a>';
echo '<div style="text-align:center">' . $intro_form . '<br />' . $link . '</div>';
}
else {
require_once($sourcedir . '/Subs.php');
require_once($sourcedir .'/Subs-Post.php');


// CONFIGURATION SECTION

$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 = 'Recruitment Application';
$body = 'Recruitment application has been made by ' . $context['user']['name'] .
' from IP Address ' . $user_info['ip'] . '
';
foreach ($fielddef as $field)
$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 .= '[color=red][u][b]' . $field['caption'] . '[/b][/u][/color]  ' . $_REQUEST[$field['name']] . '<br />';
else
$postbody .= '[color=green]' . $field['caption'] . '[/color]  ' . $_REQUEST[$field['name']] . '<br />';
}

$msgOptions = array(
'id' =>  0 ,
'subject' => '[Pending] Application of ' . $_REQUEST['charname'] . ' ' . $_REQUEST['charclass'],
'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;
}
}

// 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="' . $scripturl . '?page='  . $_GET['page'] . '" method="post">
<INPUT name="submitted" type="hidden" value="TRUE" />
<INPUT name="form" type="hidden" value="1" />
        <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>';
}
}
}

Inny

Thanks  ;)

Getting error on Line 7: Parse error: syntax error, unexpected '{'

Also which part should i remove so guests are able to fill a form.

This website is proudly hosted on Crocweb Cloud Website Hosting.