|
Post by Wormopolis on Apr 22, 2011 0:39:00 GMT -8
Browsers Tested: IE, FF, and Chrome placement: board footer This is an extension of Ross's predefined posting template code. This new version will allow you to create multiple templates, and it will create a drop down above the posting table that will let you select from them. standard instructions of Ross's code still apply: The parts highlighted in red are the actual posting fields. There are 3 types of field you can use, an example of each is given below where: The blue parts are the attributes for this field, unless you know HTML it's probably best to leave them as they are. The purple true/flase sets if the field is a required field or not (false means it can be left blank). You can list as many different fields as necessary where shown above. The first field will always be the subject of the posted message. Some general rules to remember when editing these fields are that you cannot place an apostrophe in any of the fields without first escaping it with a backslash \'. Also, you cannot put in any line breaks/returns by pressing the enter key, to insert a new line into a description use <br /> Single Line Input:_fields[_f++] = new Array('input', 'Field Name, ie. "Character Name" or "Description"', ['size', 40, 'maxLength', 50], 'Default Value filled in when the form loads. Can be left blank', 'A short description of what the field is for', false);Drop down menu:_fields[_f++] = new Array('select', 'Field Name, ie. "Gender" or "Type"', [], ['All Pages', 'Main Page', 'Mini-Profile', 'Info Center', 'Private Messaging', 'Profile', 'Posting', 'Thread Listing', 'Welcome Table', 'Other'], 'A short description of what the field is for.', true);Here, the red represents the different options. Each option should be wrapped in single quotation marks (') and seperated by a comma (,) Multiple-Line Text Area:_fields[_f++] = new Array('textarea', 'Field Name, ie. "History" or "Further Details"', ['cols', 40, 'rows', 10], 'Default Value', 'A short description of what the field is for.', false);Here, the red is the number of rows the textarea has. <script type="text/javascript"> <!-- // Multiple Template Forms // by Wormopolis - www.wormocodes.com // keep header intact // BASE CODE: /* Predefined Posting Template/Form Created by Ross of PBS Please do not repost outside of PBS/WormoCodes without permission */ // and yes I had permission to post on WormoCodes
// DO NOT EDIT THIS SECTION. EDITING IS BELOW THIS
var templateArray=new Array(), tA=0, keepTAnum;
// EDIT THIS SECTION:
// COPY THIS ENTIRE BLOCK FOR EACH FORM, change fields to what you need templateArray[tA]=new templateForm; templateArray[tA]._title="Form 1"; templateArray[tA]._description="Testing Form 1"; templateArray[tA]._fields[templateArray[tA]._f++] = new Array('input', 'Subject Title:', ['size', 60, 'maxLength', 50], '', 'This will be the name of your thread.', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('input', 'Character Name:', ['size', 60, 'maxLength', 50], '', 'Please write your characters name.', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('input', 'Age:', ['size', 60, 'maxLength', 50], '', 'Your characters age.', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('select', 'Gender:', [], ['Male', 'Female'], 'Either a guy or a gal', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('input', 'Parent Types:', ['size', 60, 'maxLength', 50], '', 'What are the parents\' creature types?', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('textarea', 'Physical Appearance:', ['cols', 70, 'rows', 5], '', 'A description of what your charrie looks like. A minimum of five good length sentences is required, OR an image accompanied by 2-3 good length sentences.', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('textarea', 'Personality Description:', ['cols', 70, 'rows', 5], '', 'A description of your character\'s personality. A minimum of five good length sentences is required.', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('textarea', 'History:', ['cols', 70, 'rows', 5], '', 'What happened in your person\'s past? Please make it realistic. A minimum of seven good length sentences is required.', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('textarea', 'Likes/Dislikes(optional):', ['cols', 70, 'rows', 5], '', 'Your person\'s likes and dislikes.', false); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('textarea', 'Other:', ['cols', 70, 'rows', 5], '', 'If there\'s anything else that doesn\'t fit in any of the above categories, here\'s the place to post it.', false); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('input', 'Codeword:', ['size', 60, 'maxLength', 50], '', 'Hidden in the rules is a codeword. This item is compulsory when creating a character.', true);
tA++; //leave this alone
// END BLOCK
// COPY THIS ENTIRE BLOCK FOR EACH FORM, change fields to what you need templateArray[tA]=new templateForm; templateArray[tA]._title="Form 2"; templateArray[tA]._description="Testing Form 2"; templateArray[tA]._fields[templateArray[tA]._f++] = new Array('input', 'Car Title:', ['size', 60, 'maxLength', 50], '', 'This will be the title number of your car.', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('input', 'Car Name:', ['size', 60, 'maxLength', 50], '', 'Please write your cars name.', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('select', 'Model:', [], ['Ford', 'Chevy'], 'choose wisely', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('textarea', 'Physical Appearance:', ['cols', 70, 'rows', 5], '', 'A description of what your car looks like. A minimum of five good length sentences is required, OR an image accompanied by 2-3 good length sentences.', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('textarea', 'History:', ['cols', 70, 'rows', 5], '', 'What happened in your car\'s past? Please make it realistic. A minimum of seven good length sentences is required.', true); templateArray[tA]._fields[templateArray[tA]._f++] = new Array('textarea', 'Other:', ['cols', 70, 'rows', 5], '', 'If there\'s anything else that doesn\'t fit in any of the above categories, here\'s the place to post it.', false);
tA++; //leave this alone
// END BLOCK
// END EDITABLE SECTION
// DO NOT EDIT BELOW, unless you know what you are doing
function templateForm(){ this._title = ''; this.this_description = ''; this._fields = new Array(); this._f = 0; this._widths = ['100%', '30%', '35%', '35%'];
this.postingForm={
errors : new Array(),
init : function() { this.create_form(); },
create_form: function() { // Create new post layout var _holder = document.createElement('table'); _holder.setAttribute('className', 'bordercolor'); _holder.setAttribute('class', 'bordercolor'); _holder.setAttribute('cellSpacing','1'); _holder.setAttribute('cellPadding', '4'); _holder.setAttribute('align', 'center'); _holder.setAttribute('width', this.parent._widths[0]); _holder.setAttribute('id', 'post_form_holder'); _holder.appendChild(document.createElement('tbody')); _holder.firstChild.appendChild( document.createElement('tr') ).appendChild( document.createElement('td') ).appendChild( document.createElement('font') ); _holder.firstChild.lastChild.lastChild.className = 'titlebg'; _holder.firstChild.lastChild.lastChild.colSpan = '3'; _holder.firstChild.lastChild.lastChild.lastChild.size = '2'; _holder.firstChild.lastChild.lastChild.lastChild.appendChild(document.createTextNode(this.parent._title)); if(this.parent._description) { _holder.firstChild.appendChild( document.createElement('tr') ).appendChild( document.createElement('td') ).appendChild( document.createElement('font') ); _holder.firstChild.lastChild.lastChild.setAttribute('className', 'windowbg'); _holder.firstChild.lastChild.lastChild.setAttribute('class', 'windowbg'); _holder.firstChild.lastChild.lastChild.setAttribute('colSpan', '3'); _holder.firstChild.lastChild.lastChild.lastChild.setAttribute('size', '2'); _holder.firstChild.lastChild.lastChild.lastChild.innerHTML = this.parent._description; } for(_f=0; _f<this.parent._fields.length; _f++) { switch(this.parent._fields[_f][0]) { case 'textarea' : var _tmp = document.createElement('textarea'); break; case 'select' : var _tmp = document.createElement('select'); for(_o=0; _o<this.parent._fields[_f][3].length; _o++) { _tmp.options[_o] = new Option(this.parent._fields[_f][3][_o], this.parent._fields[_f][3][_o]); } break; default : var _tmp = document.createElement('input'); _tmp.type = 'text'; if("undefined" != typeof this.parent._fields[_f][3] && this.parent._fields[_f][3] != "") _tmp.setAttribute('value', this.parent._fields[_f][3]); break; } _tmp.setAttribute('id', _f); if("undefined" != typeof this.parent._fields[_f][2] && this.parent._fields[_f][2].length > 0) { for(_a=0; _a<this.parent._fields[_f][2].length; _a++) { _tmp.setAttribute(this.parent._fields[_f][2][_a++], this.parent._fields[_f][2][_a]); } } var _class = 'windowbg' + ((_f % 2 == 0)? '2' : ''); var _row = document.createElement('tr'); _row.appendChild(document.createElement('td')); _row.lastChild.setAttribute('class', _class); _row.lastChild.setAttribute('className', _class); _row.lastChild.setAttribute('vAlign', 'top'); _row.lastChild.setAttribute('width', this.parent._widths[1]); _row.lastChild.appendChild(document.createElement('font')); _row.lastChild.lastChild.setAttribute('size', '2'); _row.lastChild.lastChild.style.fontWeight = 'bold'; _row.lastChild.lastChild.appendChild(document.createTextNode(this.parent._fields[_f][1] + ':')); _row.appendChild(document.createElement('td')); _row.lastChild.setAttribute('class', _class); _row.lastChild.setAttribute('className', _class); _row.lastChild.setAttribute('width', this.parent._widths[2]); _row.lastChild.appendChild(document.createElement('font')); _row.lastChild.lastChild.setAttribute('size', '2'); _row.lastChild.lastChild.appendChild(_tmp); _row.appendChild(document.createElement('td')); _row.lastChild.setAttribute('class', _class); _row.lastChild.setAttribute('className', _class); _row.lastChild.setAttribute('vAlign', 'top'); _row.lastChild.setAttribute('width', this.parent._widths[3]); _row.lastChild.appendChild(document.createElement('font')); _row.lastChild.lastChild.size = '1'; _row.lastChild.lastChild.appendChild(document.createTextNode(this.parent._fields[_f][4])); _row.onclick= function() { document.getElementById('MMPT_submit').style.color=''; }; _holder.firstChild.appendChild(_row); } var _submit = document.createElement('tr'); _submit.appendChild(document.createElement('td')); _submit.lastChild.setAttribute('class', 'windowbg' + (((_f+1) % 2 == 0)? '' : '2')); _submit.lastChild.setAttribute('className', 'windowbg' + (((_f+1) % 2 == 0)? '' : '2')); _submit.lastChild.setAttribute('align', 'center'); _submit.lastChild.setAttribute('colSpan', 3); var _button = document.createElement('input'); _button.id='MMPT_submit'; _button.setAttribute('type', 'button'); _button.setAttribute('value', 'Post Message'); _button.onclick = function() { templateArray[keepTAnum].postingForm.post_it(); }; _submit.lastChild.appendChild(_button); _holder.firstChild.appendChild(_submit); var _tables = document.postForm.getElementsByTagName('table')[0]; _tables.style.display = 'none'; _tables.parentNode.insertBefore(_holder, _tables); },
post_it : function() { // create message and attempt to post it this.errors = new Array(); document.postForm.message.value = document.postForm.subject.value = ''; var _sub = document.getElementById('0').value; this.parent._fields[0][5] = true; document.postForm.subject.value = _sub; for(_f=0; _f<this.parent._fields.length; _f++) { if(document.getElementById(_f)) { _value = document.getElementById(_f).value; if(!_value || _value.match(/^\s*$/)) { if(_f > 0 && this.parent._fields[_f][5]) this.show_error('You have left the ' + this.parent._fields[_f][1] + ' option empty. This is a required field and as such must contain a description.'); else _value = 'None'; } document.postForm.message.value += '' + this.parent._fields[_f][1] + ': ' + _value + '\n\n'; } } if(this.errors.length == 0) document.postForm.submit(true); else this.show_error(); },
show_error : function() { if("undefined" != typeof arguments[0] && arguments[0]) { this.errors.push(arguments[0]); } else { // Show Errors document.getElementById('MMPT_submit').style.color='FF0000'; if(document.getElementById('error_holder')) { document.getElementById('error_holder').innerHTML = this.errors.join("<br />"); } else { var _error_holder = document.createElement('table'); _error_holder.id='error_holder_table'; _error_holder.className = 'bordercolor'; _error_holder.cellSpacing= '1'; _error_holder.cellPadding = '4'; _error_holder.align = 'center'; _error_holder.width = this.parent._widths[0]; _error_holder.appendChild(document.createElement('tbody')); _error_holder.firstChild.appendChild(document.createElement('tr')).appendChild(document.createElement('td')).appendChild (document.createElement('font')); _error_holder.firstChild.lastChild.lastChild.className='titlebg'; _error_holder.firstChild.lastChild.lastChild.lastChild.setAttribute('size', '2'); _error_holder.firstChild.lastChild.lastChild.lastChild.innerHTML= 'An Error Has Occured'; _error_holder.firstChild.appendChild(document.createElement('tr')).appendChild(document.createElement('td')).appendChild (document.createElement('font')); _error_holder.firstChild.lastChild.lastChild.className='windowbg'; _error_holder.firstChild.lastChild.lastChild.lastChild.setAttribute('size', '2'); _error_holder.firstChild.lastChild.lastChild.lastChild.setAttribute('id', 'error_holder'); _error_holder.firstChild.lastChild.lastChild.lastChild.innerHTML= this.errors.join("<br />") ; var _holder = document.getElementById('post_form_holder'); _holder.parentNode.insertBefore(_error_holder, _holder); _holder.parentNode.insertBefore(document.createElement('br'), _holder); } } } }; this.postingForm.parent=this; }
if(document.postForm && location.href.match(/action=post/) && pb_username != 'Guest') { var MPTdiv=document.createElement('div'); MPTdiv.align="left"; MPTdiv.className='windowbg'; MPTdiv.innerHTML='<font size="2">Posting Templates: </font>'; var MPTdd=document.createElement('select'); MPTdd.onchange=function() {MPTinitForm(MPTdd.value);}; MPTddNorm=document.createElement('option'); MPTddNorm.value='-1'; MPTddNorm.innerHTML="Normal"; MPTdd.appendChild(MPTddNorm); for (pt=0; pt<tA; pt++) { var MPTddOpt=document.createElement('option'); MPTddOpt.value=pt; MPTddOpt.innerHTML=templateArray[pt]._title; MPTdd.appendChild(MPTddOpt); } MPTdiv.appendChild(MPTdd); document.postForm.insertBefore(MPTdiv, document.postForm.firstChild);
function MPTinitForm(num) { if (document.getElementById('post_form_holder')) { tmp=document.getElementById('post_form_holder'); tmp.parentNode.removeChild(tmp); } if (document.getElementById('error_holder_table')) { tmp=document.getElementById('error_holder_table'); tmp.parentNode.removeChild(tmp.nextSibling); tmp.parentNode.removeChild(tmp); } if (num>-1) { keepTAnum=num; templateArray[num].postingForm.init(); } else { document.postForm.getElementsByTagName('table')[0].style.display=''; } }
} // DO NOT EDIT ABOVE SECTION
//--> </script>
|
|