vForums Support Banner



 

Welcome Guest! Please Login or Register
vForums Support :: Programming & Coding :: Code Requests & Support :: [F] Predefined posting code - not working - View Topic
Topic Rating: *****
Printable View
Nick
Very Senior Member
*****

[Avatar]

Posts: 3,013
Status: Offline
Gender: Male
Location: vForums
Age: 35
Joined:  
Reputation: 62%  


pmwww
[F] Predefined posting code - not working (25th Feb 08 at 2:28am UTC)
Forums Board: http://freunion.vforums.co.uk/board/Pending/

Its not showing up again.

Code:
 
  1. <script type="text/javascript">
  2. <!--
  3.  
  4. /* Predefined Posting Template/Form
  5.     Created by Ross of vForums
  6.     http://virtualforums.co.uk
  7.     Please do not repost outside of
  8.     vForums support without permission */
  9.  
  10. var _title = 'Character RP form';
  11.  
  12. var _description = '';
  13.  
  14. var _fields = new Array(); var _f = 0;
  15.     _fields[_f++] = new Array('input', 'Character name', ['size', 40, 'maxLength', 50], '', 'What is the name of your role-play character?', false);
  16.     _fields[_f++] = new Array('input', 'Age', ['size', 40, 'maxLength', 50], '', 'What is your role-play characters age?', false);
  17.     _fields[_f++] = new Array('input', 'Gender', ['size', 40, 'maxLength', 50], '', 'What is the gender of your RP character?', false);
  18.     _fields[_f++] = new Array('input', 'Species', ['size', 40, 'maxLength', 250], '', 'What is your characters Species?.', false);
  19.     _fields[_f++] = new Array('input', 'Good/Evil/Neutral', ['cols', 40, 'rows', 3], '', 'Please tell us if you are good, evil, or neutral.', false);
  20.     _fields[_f++] = new Array('textarea', 'Appearance', ['size', 40, 'maxLength', 350], '', 'Please give a description of your characters appearence.', false);
  21.     _fields[_f++] = new Array('textarea', 'Personality', ['cols', 40, 'rows', 4], '', 'What is your character personality like?.', false);
  22.     _fields[_f++] = new Array('textarea', 'History', ['size', 40, 'maxLength', 350], '', 'Please tell us you characters history.', false);
  23.     _fields[_f++] = new Array('textarea', 'Abilities', ['cols', 40, 'rows', 4], '', 'Please list your characters abilities', false);
  24.     _fields[_f++] = new Array('textarea', 'Weapon', ['cols', 40, 'rows', 4], '', 'What are your weapon(s)?', false);
  25.     _fields[_f++] = new Array('textarea', 'Hobbies', ['cols', 40, 'rows', 4], '', 'What are your characters hobbies?', false);
  26.     _fields[_f++] = new Array('textarea', 'Jobs', ['cols', 40, 'rows', 4], '', 'What kind of job does your character do? IE: Soldier, merchant, unemployed, etc.', false);
  27.     _fields[_f++] = new Array('textarea', 'Summons', ['cols', 40, 'rows', 4], '', 'What are your characters summons if any?' , false);
  28.  
  29.  
  30. var _widths = ['100%', '20%', '40%', '40%'];
  31.  
  32. var _posting_form = {
  33.  
  34.     errors: new Array(),
  35.  
  36.     init: function() {
  37.         this.create_form();
  38.     },
  39.     
  40.     create_form: function() {
  41.         // Create new post layout
  42.         var _holder = document.createElement('table');
  43.         _holder.setAttribute('className', 'border');
  44.         _holder.setAttribute('class', 'border');
  45.         _holder.setAttribute('cellSpacing','1');
  46.         _holder.setAttribute('cellPadding', '4');
  47.         _holder.setAttribute('align', 'center');
  48.         _holder.setAttribute('width', _widths[0]);
  49.         _holder.setAttribute('id', 'post_form_holder');
  50.         _holder.appendChild(document.createElement('tbody'));
  51.         _holder.firstChild.appendChild( document.createElement('tr') ).appendChild( document.createElement('td') ).appendChild( document.createElement('font') );
  52.         _holder.firstChild.lastChild.lastChild.className = 'title1';
  53.         _holder.firstChild.lastChild.lastChild.colSpan = '3';
  54.         _holder.firstChild.lastChild.lastChild.lastChild.size = '2';
  55.         _holder.firstChild.lastChild.lastChild.lastChild.appendChild(document.createTextNode(_title));
  56.         if(_description) {
  57.             _holder.firstChild.appendChild( document.createElement('tr') ).appendChild( document.createElement('td') ).appendChild( document.createElement('font') );
  58.             _holder.firstChild.lastChild.lastChild.setAttribute('className', 'window1');
  59.             _holder.firstChild.lastChild.lastChild.setAttribute('class', 'window1');
  60.             _holder.firstChild.lastChild.lastChild.setAttribute('colSpan', '3');
  61.             _holder.firstChild.lastChild.lastChild.lastChild.setAttribute('size', '2');
  62.             _holder.firstChild.lastChild.lastChild.lastChild.innerHTML = _description;
  63.         }
  64.         
  65.         for(_f=0; _f<_fields.length; _f++) {
  66.             switch(_fields[_f][0]) {
  67.                 case 'textarea' :
  68.                     var _tmp = document.createElement('textarea');
  69.                 break;
  70.                 
  71.                 case 'select' :
  72.                     var _tmp = document.createElement('select');
  73.                     for(_o=0; _o<_fields[_f][3].length; _o++) {
  74.                         _tmp.options[_o] = new Option(_fields[_f][3][_o], _fields[_f][3][_o]);
  75.                     }
  76.                 break;
  77.                 
  78.                 default :
  79.                     var _tmp = document.createElement('input');
  80.                     _tmp.type = 'text';
  81.                     if("undefined" != typeof _fields[_f][3] && _fields[_f][3] != "")
  82.                         _tmp.setAttribute('value', _fields[_f][3]);
  83.                 break;
  84.             }
  85.             _tmp.setAttribute('id', _f);
  86.             if("undefined" != typeof _fields[_f][2] && _fields[_f][2].length > 0) {
  87.                 for(_a=0; _a<_fields[_f][2].length; _a++) {
  88.                     _tmp.setAttribute(_fields[_f][2][_a++], _fields[_f][2][_a]);
  89.                 }
  90.             }
  91.             var _class = 'window' + ((_f % 2 == 0)? '2' : '1');
  92.             var _row = document.createElement('tr');
  93.             _row.appendChild(document.createElement('td'));
  94.             _row.lastChild.setAttribute('class', _class);
  95.             _row.lastChild.setAttribute('className', _class);
  96.             _row.lastChild.setAttribute('vAlign', 'top');
  97.             _row.lastChild.setAttribute('width', _widths[1]);
  98.             _row.lastChild.appendChild(document.createElement('font'));
  99.             _row.lastChild.lastChild.setAttribute('size', '2');
  100.             _row.lastChild.lastChild.style.fontWeight = 'bold';
  101.             _row.lastChild.lastChild.appendChild(document.createTextNode(_fields[_f][1] + ':'));
  102.             _row.appendChild(document.createElement('td'));
  103.             _row.lastChild.setAttribute('class', _class);
  104.             _row.lastChild.setAttribute('className', _class);
  105.             _row.lastChild.setAttribute('width', _widths[2]);
  106.             _row.lastChild.appendChild(document.createElement('font'));
  107.             _row.lastChild.lastChild.setAttribute('size', '2');
  108.             _row.lastChild.lastChild.appendChild(_tmp);
  109.             _row.appendChild(document.createElement('td'));
  110.             _row.lastChild.setAttribute('class', _class);
  111.             _row.lastChild.setAttribute('className', _class);
  112.             _row.lastChild.setAttribute('vAlign', 'top');
  113.             _row.lastChild.setAttribute('width', _widths[3]);
  114.             _row.lastChild.appendChild(document.createElement('font'));
  115.             _row.lastChild.lastChild.size = '1';
  116.             _row.lastChild.lastChild.appendChild(document.createTextNode(_fields[_f][4]));
  117.             _holder.firstChild.appendChild(_row);
  118.         }
  119.         var _submit = document.createElement('tr');
  120.         _submit.appendChild(document.createElement('td'));
  121.         _submit.lastChild.setAttribute('class', 'window' + (((_f+1) % 2 == 0)? '1' : '2'));
  122.         _submit.lastChild.setAttribute('className', 'window' + (((_f+1) % 2 == 0)? '1' : '2'));
  123.         _submit.lastChild.setAttribute('align', 'center');
  124.         _submit.lastChild.setAttribute('colSpan', 3);
  125.         var _button = document.createElement('input');
  126.         _button.setAttribute('type', 'button');
  127.         _button.setAttribute('value', 'Post Message');
  128.         _button.onclick = function() { _posting_form.post_it(); };
  129.         _submit.lastChild.appendChild(_button);
  130.         _holder.firstChild.appendChild(_submit);
  131.         document.post_form.style.display = 'none';
  132.         document.post_form.parentNode.insertBefore(_holder,  document.post_form);
  133.     },
  134.     
  135.     post_it: function() {
  136.         // create message and attempt to post it
  137.         this.errors = new Array();
  138.         document.post_form.message.value = document.post_form.subject.value = '';
  139.         var _sub = document.getElementById('0').value;
  140.         _fields[0][5] = true;
  141.         document.post_form.subject.value    = _sub;
  142.         for(_f=0; _f<_fields.length; _f++) {
  143.             if(document.getElementById(_f)) {
  144.                 _value = document.getElementById(_f).value;
  145.                 if(!_value || _value.match(/^s*$/)) {
  146.                     if(_f > 0 && _fields[_f][5])
  147.                         this.show_error('You have left the ' + _fields[_f][1] + ' option empty. This is a required field and as such must contain a value.');
  148.                     else
  149.                         _value = '[i]None[/i]';
  150.                 }
  151.                 document.post_form.message.value += '[b]' + _fields[_f][1] + ':[/b] ' + _value + '\n\n';
  152.             }
  153.         }
  154.         if(this.errors.length == 0)
  155.             document.post_form.post.click();
  156.         else
  157.             this.show_error();
  158.     },
  159.     
  160.     show_error: function() {
  161.         if("undefined" != typeof arguments[0] && arguments[0]) {
  162.             this.errors.push(arguments[0]);
  163.         } else {
  164.             // Show Errors
  165.             if(document.getElementById('status_holder')) {
  166.                 document.getElementById('status_holder_title').innerHTML = "An Error Has Occured";
  167.                 document.getElementById('status_holder_message').innerHTML = this.errors.join("<br />");
  168.                 document.getElementById('status_holder').style.display = 'block';
  169.             }
  170.         }
  171.     }
  172. }
  173.  
  174.  
  175.  
  176. if(document.post_form && location.href.match(/action\/post\/?$/) && vf_username != 'Guest') {
  177.     _posting_form.init();
  178. }
  179. //-->
  180. </script>
 
Ross
Administrator
*****

[Avatar]

Posts: 3,709
Status: Offline
Gender: Male
Age: 9 14
Joined:  

Additional Groups:
Support Team
***


Reputation: 45%  


pmwwwtwittergtalkvForum
Re: Predefined posting code - not working (25th Feb 08 at 1:00pm UTC)
Should be OK now?

Image
Nick
Very Senior Member
*****

[Avatar]

Posts: 3,013
Status: Offline
Gender: Male
Location: vForums
Age: 35
Joined:  
Reputation: 62%  


pmwww
Re: Predefined posting code - not working (26th Feb 08 at 1:28am UTC)
Thanks, it works.

What was wrong?
 Printable View

All times are GMT+0 :: The current time is 2:00pm
Page generated in 1.2439 seconds
This Forum is Powered By vForums (v2.4)
Create a Forum for Free | Find Forums