DaPro |
05-30-2006 12:59 PM |
This tutorial is for anyone who wants to use this nice hack simply for an affiliation form. So enjoy.
Note: Is there anyway these forms are protected against bot flooding? I don't see an option for human input.
BE SURE TO UPLOAD THE PLUGIN BEFORE DOING ALL OF THIS!
Step 1. Create a new plugin: Plugin Manager > Add New Plugin
- Hook Location: newthread_start
- Title: Affiliation Form
- Plugin Code Below (Edit If you wish)
PHP Code:
// To add more then one form, copy this whole text, and creat a new plug-in with the hook location 'newthread_start'. // After, change the form name. You can't have 2 forms with the same name.
// Name of this form $formname = "affiliation";
if ($_REQUEST['do'] == $formname) {
// ####################################################################### // ######################## CUSTOMIZE VARIABLES ########################## // #######################################################################
//////////////////////////////////////////////////////////////////////////////////////////////////// ////// BEGIN CUSTOMIZATION BELOW//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// //VARIABLES //Study how variables are add here to add or remove any. If you add a variable to your form, you must add it to part one and part two. ////////////////////////////////////////////////////////////////////////////////////////////////////
// Part 1 $vbulletin->input->clean_array_gpc('p', array( 'normalanswer1' => TYPE_STR, 'normalanswer2' => TYPE_STR, 'normalanswer3' => TYPE_STR, 'longanswer1' => TYPE_STR ));
// Part 2 $normalanswer1 = $vbulletin->GPC['normalanswer1']; $normalanswer2 = $vbulletin->GPC['normalanswer2']; $normalanswer3 = $vbulletin->GPC['normalanswer3']; $longanswer1 = $vbulletin->GPC['longanswer1'];
//////////////////////////////////////////////////////////////////////////////////////////////////// //USERGROUPS ALLOWED //You can add or remove usegroups that are ALLOWED to use this form by changing the numbers below in the array. //To enable this feature, remove the '//' before the 'if'. ////////////////////////////////////////////////////////////////////////////////////////////////////
// if (!in_array($vbulletin->userinfo['usergroupid'], array(2,5,6,7))) print_no_permission();
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// //NAME OF TEMPLATES - DO THIS BIT IF YOU ARE MAKING MORE FORMS AND WANT TO USE A DIFFERENT LOOKING TEMPLATE ////////////////////////////////////////////////////////////////////////////////////////////////////
// Name of the main template $maintemplate = "form_affiliation"; // Name of the answer template $answertemplate = "formanswers_affiliation";
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// //CHOOSE WHETHER YOU WANT FORM TO BE POSTED IN A NEW THREAD, NEW POLL, REPLY TO EXISITING THREAD, PMed OR EMAILED ///////////////////////////////////////////////////////////////////////////////////////////////////
//ENABLE FORM TO BE POSTED - 1 = yes, 0 = no $formforum = "0";
//FORUM TO POST NEW THREAD IN //You CAN make this number a variable. You can have a drop down menu or in the link like do=form&f=1. Make sure you add it the variables list. $formforumid = "0";
//ENABLE POLL TO BE CREATED - 1 = yes, 0 = no $formpoll = "0"; $polloption[1] = "Yes"; $polloption[2] = "No"; $polloption[3] = "Maybe";
//Make poll public - 1 = yes, 0 = no $pollpublic = "0";
////////////////////////////////////////////////////////////////////////////////////////////////////
//ENABLE FORM TO REPLY TO EXISTING THREAD - 1 = yes, 0 = no $formreply = "0";
//EXISTING THREAD ID FOR FORM TO REPLY IN $formreplythreadid = "0";
////////////////////////////////////////////////////////////////////////////////////////////////////
//ENABLE FORM TO BE PMED (guests CANNOT use this option) - 1 = yes, 0 = no $formpm = "0";
//USERNAME TO PM TO $formpmname = "Abe";
////////////////////////////////////////////////////////////////////////////////////////////////////
//ENABLE FORM TO BE EMAILED - 1 = yes, 0 = no $formemail = "1";
//EMAIL ADDRESS TO EMAIL TO $formemailaddress = "youremail@domain.com";
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// //REDIRECT OPTIONS: // 0 - thank you message (thread, reply, pm, or email) // 1 - redirect to post (thread or reply) // 2 - redirect to thread (thread only) // 3 - redirect to forum (thread only) // 4 - redirect to editpost to upload attachments (thread or reply) // // Feel free to change the thank you message if you choose option 0 ////////////////////////////////////////////////////////////////////////////////////////////////////
$redirectoption = "0";
$errormessage = "Thank you for applying for affiliation with OtakuTalk.com. We will get back to you in 2-3 days time."; //This is the thank you message
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// //FORCE USER TO ANSWER ALL QUESTIONS - 1 = yes, 0 = no //If you added or deleted variables, you must edit what it checked for. Search for "$answerall ==" and edit 2 lines under it. ////////////////////////////////////////////////////////////////////////////////////////////////////
$answerall = "0";
//////////////////////////////////////////////////////////////////////////////////////////////////// //TITLE OF FORM (do not use quotation marks or you will get a parse error, besides the quotes around the whole title) ////////////////////////////////////////////////////////////////////////////////////////////////////
$formtitle = "Affiliation Request";
//////////////////////////////////////////////////////////////////////////////////////////////////// //TITLE OF THREAD/POST/PM/EMAIL (do not use quotation marks in the title or you will get a parse error) //You may use variables from the form for this. ////////////////////////////////////////////////////////////////////////////////////////////////////
$posttitle = "$formtitle";
//////////////////////////////////////////////////////////////////////////////////////////////////// //PURPOSE OF FORM (do not use quotation marks or you will get a parse error, besides the quotes around the whole text) ////////////////////////////////////////////////////////////////////////////////////////////////////
$formpurpose = "Thank you for considering affiliation with OtakuTalk.com. Please fill out the form below with all fields answered and then submit it. Thank you!";
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// //NORMAL INPUT BOX : QUESTION 1 (do not use quotation marks or you will get a parse error, besides the quotes around the whole text) ////////////////////////////////////////////////////////////////////////////////////////////////////
$normalquestion1 = "Your Name";
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// //NORMAL INPUT BOX : QUESTION 1 (do not use quotation marks or you will get a parse error, besides the quotes around the whole text) ////////////////////////////////////////////////////////////////////////////////////////////////////
$normalquestion2 = "Website Title";
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// //NORMAL INPUT BOX : QUESTION 1 (do not use quotation marks or you will get a parse error, besides the quotes around the whole text) ////////////////////////////////////////////////////////////////////////////////////////////////////
$normalquestion3 = "Website URL";
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// //LONG TEXT AREA INPUT: QUESTION 1 (do not use quotation marks or you will get a parse error, besides the quotes around the whole text) ////////////////////////////////////////////////////////////////////////////////////////////////////
$longquestion1 = "Why would you like to affiliate?"; $longexplain1 = "A simple explaination is all that is needed.";
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////// ////// END OF CUSTOMIZATION //////////////////////////////////////////////////////////////////// ///// DO NOT CHANGE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!!! //////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// ####################################################################### // ######################## START MAIN SCRIPT ############################ // ####################################################################### if ($_REQUEST['action'] == '') { $_REQUEST['action'] = "form"; }
$bbuserinfo = $vbulletin->userinfo;
// start navbar $navbits = array(); $navbits['newthread.php?' . $vbulletin->session->vars['sessionurl'] . "do=$formname"] = $formtitle;
$navbits = construct_navbits($navbits); eval('$navbar = "' . fetch_template('navbar') . '";');
if ($_REQUEST['action'] == "submit") {
if ($answerall == "1") { if ($normalanswer1 == '' OR $radioanswer1 == '' OR $radioanswer2 == '' OR $radioanswer3 == '' OR $answer1 == '' OR $answer2 == '' OR $answer3 == '' OR $longanswer1 == '') { $errormessage = "$bbuserinfo[username], you need to answer every question!"; eval('print_output("' . fetch_template('STANDARD_ERROR') . '");'); exit(); } }
$vbulletin->input->clean_array_gpc('p', array( 'wysiwyg' => TYPE_BOOL, 'message' => TYPE_STR ));
if ($vbulletin->GPC['wysiwyg']) { require_once(DIR . '/includes/functions_wysiwyg.php'); $vbtextanswer = convert_wysiwyg_html_to_bbcode($vbulletin->GPC['message'], $foruminfo['allowhtml']); } else { $vbtextanswer =& $vbulletin->GPC['message']; }
eval('$formsend = "' . fetch_template("$answertemplate") . '";');
if ($_POST['submit'] == 'Submit') { if ($formforum == "1") { $foruminfo = verify_id('forum', $formforumid, 0, 1); $forumperms = fetch_permissions($foruminfo[forumid]); $newpost['username'] =& $vbulletin->userinfo['username']; $newpost['message'] =& $formsend; $newpost['title'] =& $posttitle; $newpost['parseurl'] = '1';
if ($vbulletin->userinfo['autosubscribe'] != -1) { $newpost['emailupdate'] = $vbulletin->userinfo['autosubscribe']; } else { $newpost['emailupdate'] = 9999; }
if ($vbulletin->userinfo['signature'] != '') { $newpost['signature'] = '1'; } else { $newpost['signature'] = '0'; }
build_new_post('thread', $foruminfo, array(), array(), $newpost, $errors);
if ($formpoll == "1") { $threadinfo = verify_id('thread', $newpost[threadid], 0, 1); $polloptions = count($polloption); $question = $posttitle; $vbulletin->GPC['options'] = $polloption;
$counter = 0; $optioncount = 0; $badoption = ''; while ($counter++ < $polloptions) { // 0..Pollnum-1 we want, as arrays start with 0 if ($vbulletin->options['maxpolllength'] AND vbstrlen($vbulletin->GPC['options']["$counter"]) > $vbulletin->options['maxpolllength']) { $badoption .= iif($badoption, ', ') . $counter; } if (!empty($vbulletin->GPC['options']["$counter"])) { $optioncount++; } }
// Add the poll $poll =& datamanager_init('Poll', $vbulletin, ERRTYPE_STANDARD);
$counter = 0; while ($counter++ < $polloptions) { if ($vbulletin->GPC['options']["$counter"] != '') { $poll->set_option($vbulletin->GPC['options']["$counter"]); } }
$poll->set('question', $question); $poll->set('dateline', TIMENOW); $poll->set('active', '1'); $poll->set('public', $pollpublic);
$pollid = $poll->save(); //end create new poll
// update thread $threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_STANDARD, 'threadpost'); $threadman->set_existing($threadinfo); $threadman->set('pollid', $pollid); $threadman->save(); } }
if ($formreply == "1") { $threadinfo = verify_id('thread', $formreplythreadid, 0, 1); $forumperms = fetch_permissions($threadinfo[forumid]); $newpost['username'] =& $vbulletin->userinfo['username']; $newpost['message'] =& $formsend; $newpost['title'] =& $posttitle; $newpost['parseurl'] = "1"; if ($vbulletin->userinfo['autosubscribe'] != -1) { $newpost['emailupdate'] = $vbulletin->userinfo['autosubscribe']; } else { $newpost['emailupdate'] = 9999; }
if ($vbulletin->userinfo['signature'] != '') { $newpost['signature'] = '1'; } else { $newpost['signature'] = '0'; }
build_new_post('reply', $foruminfo, $threadinfo, $postinfo, $newpost, $errors); }
if ($formpm == "1") { $vbulletin->GPC['message'] =& $formsend; $vbulletin->GPC['title'] =& $posttitle; $vbulletin->GPC['recipients'] =& $formpmname;
$pm['message'] =& $vbulletin->GPC['message']; $pm['title'] =& $vbulletin->GPC['title']; $pm['recipients'] =& $vbulletin->GPC['recipients'];
// create the DM to do error checking and insert the new PM $pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pmdm->set('fromuserid', $vbulletin->userinfo['userid']); $pmdm->set('fromusername', $vbulletin->userinfo['username']); $pmdm->setr('title', $pm['title']); $pmdm->setr('message', $pm['message']); $pmdm->set_recipients($pm['recipients'], $permissions); $pmdm->set('dateline', TIMENOW);
// everything's good! $pmdm->save(); }
if ($formemail == "1") { vbmail($formemailaddress, $posttitle, $formsend); }
if ($redirectoption == "1") { $vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "p=$newpost[postid]"; eval(print_standard_redirect('redirect_postthanks')); exit(); } if ($redirectoption == "2") { $vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t=$newpost[threadid]"; eval(print_standard_redirect('redirect_postthanks')); exit(); } if ($redirectoption == "3") { $vbulletin->url = 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f=$foruminfo[forumid]"; eval(print_standard_redirect('redirect_postthanks')); exit(); } if ($redirectoption == "4") { $vbulletin->url = 'editpost.php?do=editpost&' . $vbulletin->session->vars['sessionurl'] . "p=$newpost[postid]"; eval(print_standard_redirect('redirect_postthanks')); exit(); } eval('print_output("' . fetch_template('STANDARD_ERROR') . '");'); exit(); } else { require_once('./includes/class_bbcode.php'); $parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list()); $preview = $parser->do_parse($formsend);
$_REQUEST['action'] = 'form'; } }
if ($_REQUEST['action'] == 'form') { // set message box width to usercp size $stylevar['messagewidth'] = $stylevar['messagewidth_usercp']; $editorid = construct_edit_toolbar($vbtextanswer);
eval('print_output("' . fetch_template("$maintemplate") . '");'); } }
- Be sure to edit the following to your information!
PHP Code:
//EMAIL ADDRESS TO EMAIL TO $formemailaddress = "youremail@domain.com";
Step 1. Create form_affiliation Template: Style Manager > Add New Template
- Title: form_affiliation
- Template code below:
HTML Code:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
$headinclude
<title>$vboptions[bbtitle] - $formtitle</title>
</head>
<body>
$header
$navbar
<!-- main -->
<if condition="$preview">
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat">
Preview
</td>
</tr>
<tr>
<td class="alt1">
$preview
</td>
</tr>
</table>
</if>
<br />
<form name="vbform" action="newthread.php" method="post"<if condition="!is_browser('webtv')"> onsubmit="return vB_Editor['$editorid'].prepare_submit(0, $vboptions[postminchars])"</if>>
<input type="hidden" value="$formname" name="do" />
<input type="hidden" value="submit" name="action" />
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat" colspan="3">
$vboptions[bbtitle] - $formtitle
</td>
</tr>
<tr>
<td class="panelsurround" align="center" colspan="3">
<table class="panel" cellpadding="0" cellspacing="$stylevar[formspacer]" border="0" width="100%">
<tr>
<td align="$stylevar[left]">
<fieldset class="fieldset" style="margin:0px">
<table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0">
<tr>
<td>
$formpurpose
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="alt1" colspan="3">
<b>$normalquestion1</b>
</td>
</tr>
<tr>
<td class="alt2" colspan="3">
<input class="bginput" type="text" size="30" value="$normalanswer1" name="normalanswer1" />
</td>
</tr>
<tr>
<td class="alt1" colspan="3">
<b>$normalquestion2</b>
</td>
</tr>
<tr>
<td class="alt2" colspan="3">
<input class="bginput" type="text" size="30" value="$normalanswer2" name="normalanswer2" />
</td>
</tr>
<tr>
<td class="alt1" colspan="3">
<b>$normalquestion3</b>
</td>
</tr>
<tr>
<td class="alt2" colspan="3">
<input class="bginput" type="text" size="30" value="$normalanswer3" name="normalanswer3" />
</td>
</tr>
<tr>
<td class="alt1" colspan="3">
<b>$longquestion1</b> - $longexplain1
</td>
</tr>
<tr>
<td class="alt2" colspan="3" align="center">
<textarea class="bginput" rows="10" cols="90" name="longanswer1">$longanswer1</textarea>
</td>
</tr>
<tr>
<td valign="top" colspan="3">
<p align="center">
<input class="bginput" type="submit" value="Submit" name="submit" style="font-family: Verdana; font-size: 10pt" class="button" />
<input class="bginput" type="submit" value="Preview" name="submit" style="font-family: Verdana; font-size: 10pt" class="button" />
<input class="bginput" type="reset" value="Reset" name="reset" style="font-family: Verdana; font-size: 10pt" class="button" />
</p></td></tr>
</table>
</form>
$footer
</body>
</html>
Step 2. Create formanswers_affiliation Template: Style Manager > Add New Template
- Title: forumanswers_affiliation
- Template Code Below:
Code:
$formtitle
$normalquestion1
$normalanswer1
$normalquestion2
$normalanswer2
$normalquestion3
$normalanswer3
-----------------------------------------------------
$longquestion1
$longanswer1
------------------------------------------------------
Step 3. Accessing your new forum for testing!
- Type the following into your browser to access it: http://www.yourforums.com/newthread.php?do=affiliation
- Fill out all the information and click submit.
- Check your e-mail to see if everything is working.
|