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: 429
  • Total: 429

Generic Application Form error

Started by GreenEyed, October 27, 2011, 05:05:46 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GreenEyed

I have a small issue that maybe someone with more experience than I can fix.

I am using the "Generic Application Form" that JPDeni wrote here http://www.tinyportal.net/index.php?topic=29670.msg236779#msg236779

It worked fine when I first installed it, but now that we are actually needing it decided to go pear shaped. 

Whenever an app is filled out and the submit button is hit it returns this error: Fatal error: Function name must be a string in /home/xxx/public_html/forums/Sources/TPortal.php on line 3041

Can anyone tell me what has happened? 

Tportal.php line 3041 is:      $smcFunc['db_query']($code)

GreenEyed

It is working now. I removed the option to add a poll to the application and it works now.  Any way to fix that?

IchBin

That code should probably be updated for SMF2. It looks to me like that code has only been written for SMF1. And I can only assume you are using SMF2 since you did not provide any information about your setup.

GreenEyed

Yessir, using SMF2.  We had a similar variation of that when we were on 1.4 that went toes up after I upgraded.  I found that one and it worked fine after the upgrade, just the issue with the poll feature now.

IchBin

See if this code works. I've changed a bit of the logic and updated it for SMF2. Let me know if you have any errors or problems.


global $sourcedir, $smcFunc, $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 ($user_info['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
$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']);
}

//create new forum post with application
if ($enable_post) { 
if ($add_poll === 1) {
$posterName = $context['user']['name'];
if ($expireTime > 0)
$expireTime = time() + $expireTime * 3600 * 24;
$smcFunc['db_insert']('INSERT',
'{db_prefix}polls',
array(
'question' => 'string',
'hide_results' => 'int',
'max_votes' => 'int',
'expire_time' => 'int',
'id_member' => 'int',
'poster_name' => 'string',
'change_vote' => 'int',
),
array($question, $hideResults, 1, $expireTime, $user_info['id'], $posterName, $changeVote),
array('id_poll')
);

$ID_POLL = $smcFunc['db_insert_id']('{db_prefix}polls', 'id_poll');

// Create each answer choice.
$i = 0;
$setString = '';
foreach ($poll_choices as $option)
{
$setString = array(
'id_poll' => $ID_POLL,
'id_choice' => $i,
'label' => substr($option, 1, 255),
);
$i++;
}
foreach ($setString as $value)
{
$smcFunc['db_insert']('INSERT',
'{db_prefix}poll_choices',
array('id_poll' => 'int', 'id_choice' => 'int', 'label' => 'string'),
array($value['id_poll'], $value['id_choice'], $value['label']),
array('id_poll', 'id_choice')
);
}
}
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"> ', $fieldvalue[$field['name']] ,'</' . '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>';
}
}

This website is proudly hosted on Crocweb Cloud Website Hosting.