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

Generic Application Form

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

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IchBin

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

NCSurfer

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

IchBin

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.

NCSurfer

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.

IchBin

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.

NCSurfer

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

IchBin

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.

NCSurfer

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?

IchBin

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.

GreenEyed

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.

This website is proudly hosted on Crocweb Cloud Website Hosting.