JS - FORMBUILDER
================
/*******************
* *
* JS FORM BUILDER *
* *
*******************/
// Formfield Definitions
/*
Field Types:
1: text-line -required: field_label
2: text-box -required: field_label
3: checkbox -required: field_label, return_value
4: radio-buttons -required: field_label, field_options (new Array('val1','val2','...')), free_attributes (new Array('attr1','attr2','...')) !!! number of elements FREE_ATTRIBUTES must equal number of elements FIELD_OPTIONS !!!
5: date-field -required: field_label
6: date/time-field -required: field_label, free_attributes (new Array('date-button attr','time-button attr')) !!! number of elements FREE_ATTRIBUTES must be TWO(2) !!!
7: drop-down -required: field_label, field_options (new Array('val1','val2','...')), free_attributes (new Array('drop-down attr','attr val1','attr val2','...')) !!! number of elements FREE_ATTRIBUTES must equal number of elements FIELD_OPTIONS + 1 !!!
8: check all applicable -required: field_label, field_options (new Array('val1','val2','...')), free_attributes (new Array('attr1','attr2','...')) !!! number of elements FREE_ATTRIBUTES must equal number of elements FIELD_OPTIONS !!!
9: hidden -required: field_label, return_value
10: comment/instruction -required: field_label
11: e-mail address -required: field_label, free_attributes (new Array('attr1','attr2')) !!! number of elements FREE_ATTRIBUTES must be TWO(2) !!!
12: password -required: field_label, free_attributes (new Array('attr1','attr2')) !!! number of elements FREE_ATTRIBUTES must be TWO(2) !!!
13: read-only -required: field_label, free_attributes (new Array('id="[field_id]")) !!! FREE_ATTRIBUTES must contain element id !!!
14: file -required: field_label
// Sample Array
field_type[index] = 1;
field_label[index] = 'text-line';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array();
return_value[index] = '';
prefill_value[index] = new Array('');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,\'":;,/?!$%&()-+=';
required[index] = 1;
flagged[index] = 1;
free_attributes[index] = new Array('onkeyup="getElementById(\'value_display\').value=this.value;"');
index++;
field_type[index] = 2;
field_label[index] = 'text-box';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '30';
field_rows[index] = '5';
field_options[index] = new Array();
return_value[index] = '';
prefill_value[index] = new Array('');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,\'":;,/?!$%&()-+=';
required[index] = 1;
flagged[index] = 0;
free_attributes[index] = new Array('');
index++;
field_type[index] = 3;
field_label[index] = 'checkbox';
db_label[index] = '';
linebreak[index] = 1;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array();
return_value[index] = 'selected';
prefill_value[index] = new Array('1');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 1;
flagged[index] = 0;
free_attributes[index] = new Array('');
index++;
field_type[index] = 4;
field_label[index] = 'radio button';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array('Yes','No','Who knows?');
return_value[index] = '';
prefill_value[index] = new Array('','1','');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 1;
flagged[index] = 0;
free_attributes[index] = new Array('','','');
index++;
field_type[index] = 5;
field_label[index] = 'date';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array();
return_value[index] = '';
prefill_value[index] = new Array('');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 1;
flagged[index] = 0;
free_attributes[index] = new Array('');
index++;
field_type[index] = 6;
field_label[index] = 'date and time';
db_label[index] = '';
linebreak[index] = 1;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array();
return_value[index] = '';
prefill_value[index] = new Array('');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 1;
flagged[index] = 0;
free_attributes[index] = new Array('');
index++;
field_type[index] = 7;
field_label[index] = 'dropdown list';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array('Yes','No','Who knows?');
return_value[index] = '';
prefill_value[index] = new Array('1','','');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 1;
flagged[index] = 0;
free_attributes[index] = new Array('','','');
index++;
field_type[index] = 8;
field_label[index] = 'Check all that apply';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array('Yes','No','Who knows?');
return_value[index] = '';
prefill_value[index] = new Array('1','1','1');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 1;
flagged[index] = 0;
free_attributes[index] = new Array('','','');
index++;
field_type[index] = 9;
field_label[index] = 'hidden';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array();
return_value[index] = 'This was sent by a form';
prefill_value[index] = new Array('');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 1;
flagged[index] = 0;
free_attributes[index] = new Array('');
index++;
field_type[index] = 10;
field_label[index] = 'comment/instruction';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array();
return_value[index] = '';
prefill_value[index] = new Array('');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 0;
flagged[index] = 0;
free_attributes[index] = new Array('');
index++;
field_type[index] = 11;
field_label[index] = 'e-mail address';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array('Yes','No');
return_value[index] = '';
prefill_value[index] = new Array('');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 1;
flagged[index] = 0;
free_attributes[index] = new Array('','');
index++;
field_type[index] = 12;
field_label[index] = 'password';
db_label[index] = '';
linebreak[index] = 1;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array('Yes','No');
return_value[index] = '';
prefill_value[index] = new Array('');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 1;
flagged[index] = 0;
free_attributes[index] = new Array('','');
index++;
field_type[index] = 13;
field_label[index] = 'read only';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '30';
field_rows[index] = '';
field_options[index] = new Array();
return_value[index] = '';
prefill_value[index] = new Array('copied from first field');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 0;
flagged[index] = 1;
free_attributes[index] = new Array('id="value_display" style="background-color:red;"');
index++;
field_type[index] = 14;
field_label[index] = 'file';
db_label[index] = '';
linebreak[index] = 0;
field_size[index] = '';
field_rows[index] = '';
field_options[index] = new Array();
return_value[index] = '';
prefill_value[index] = new Array('');
prefill_date[index] = '';
prefill_time[index] = '';
permitted_chars[index] = '';
required[index] = 0;
flagged[index] = 0;
free_attributes[index] = new Array('');
index++;
// Submit-Button text (only if mail-function wanted)
submitbutton_txt= 'Go!';
submit_button_id='submit_button'
submit_button_active=1;
// Subject Line text
email_subject= 'Quick Contact Form';
// Success Message
successful_sent_message='
Thank you! ';
// AJAX-Script (only if AJAX function is wanted)
ajax_script='ajax_survey.php';
viewbutton_txt='view';
// Activate
createForm();
*/
//=======================================================================//
// Check Form
function checkForm(){
var element_trace=0;
for(field_count=0;field_count**';
}
if(db_label[field_count]){
var form_field_label=db_label[field_count];
}else{
var form_field_label=field_label[field_count];
}
//--- FORMFIELD TYPES ---
// textline
if(field_type[field_count]==1){
form_html=form_html+''+field_label[field_count]+required_label+' ';
}
// textbox
else if(field_type[field_count]==2){
form_html=form_html+''+field_label[field_count]+required_label+' ';
}
// checkbox
else if(field_type[field_count]==3){
if(prefill_value[field_count][0]){prefill_value[field_count][0]='checked="true"';}
form_html=form_html+' ';
}
// radio buttons
else if(field_type[field_count]==4){
form_html=form_html+''+field_label[field_count]+required_label+' ';
}
// date-field
else if(field_type[field_count]==5){
form_html=form_html+''+field_label[field_count]+required_label+'
';
calendar_count++;
}
// date/time-field
else if(field_type[field_count]==6){
form_html=form_html+''+field_label[field_count]+required_label+'
';
calendar_count++;
}
// drop-down
else if(field_type[field_count]==7){
form_html=form_html+''+field_label[field_count]+required_label+' - Please Select - ================== ';
for(option_count=0;option_count1){
form_html=form_html+' '+sub_section[0]+'';
}else{
form_html=form_html+' '+sub_section[0]+'';
}
}
form_html=form_html+'
';
}
// applicable
else if(field_type[field_count]==8){
form_html=form_html+''+field_label[field_count]+required_label+' ';
}
// hidden
else if(field_type[field_count]==9){
form_html=form_html+' ';
}
// comment
else if(field_type[field_count]==10){
form_html=form_html+''+field_label[field_count]+' ';
}
}
// --- submit_button ---
if(submit_button_active){
submit_button_active='';
}else{
submit_button_active='disabled="true"';
}
if(ajax_script){
form_html='';
}else{
form_html='';
}
// replace form with message
if(mail_sent==1){
document.getElementById('mainform').innerHTML=''+successful_sent_message+'
';
}else if(mail_sent==2){
document.getElementById('mainform').innerHTML='Problem with the submission!
';
}else{
document.getElementById('mainform').innerHTML=form_html;
}
}
// Calendar Implementation
// USAGE: form_calendar([Date-Field ID, (opt.)], [Time-Field ID, (opt.)], [Calendar-Display-Field ID (usually
)], [preset date, (opt.)])
function form_calendar(datefield_id,timefield_id,calendarfield_id,new_date){
var content='';
if(!new_date){
var new_date='';
}
if(datefield_id){
var sdt=new Date();
o_month=sdt.getMonth();
o_year=sdt.getFullYear();
if(new_date.indexOf('/')>0){
date_in=new_date.split('/');
if((date_in[0]-1==o_month) && (date_in[2]==o_year)){
cday=sdt.getDate();
}else{
cday='0';
}
sdt.setDate(1);
sdt.setYear(date_in[2]);
sdt.setMonth(date_in[0]-1);
}else{
cday=sdt.getDate();
}
sdt.setDate(1);
wkday=sdt.getDay();
var mnth_name=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var mnth_days=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
cyear=sdt.getFullYear();
cmonth=sdt.getMonth();
if(!(cyear%4) && (cyear!=2000)){mnth_days[1]++;}
if(cmonth<1){
var prev_month=12;
var prev_year=cyear-1;
}else{
var prev_month=cmonth;
var prev_year=cyear;
}
if(cmonth>11){
var next_month=1;
var next_year=cyear+1;
}else{
var next_month=cmonth+2;
var next_year=cyear;
}
var prev_date=prev_month+'/1/'+prev_year;
var next_date=next_month+'/1/'+next_year;
content=content+'';
content=content+'< '+mnth_name[cmonth]+' '+cyear+' > ';
content=content+'Su Mo Tu We Th Fr Sa ';
start=sdt.getDay();
for(x=0;x<(mnth_days[cmonth]+wkday);x++){
content=content+'=wkday){
content=content+' style="cursor:pointer;';
if(!(x%7)){
content=content+'color:#ff0000;';
}
if((x-wkday+1)==cday){
content=content+'background-color:#cccccc;';
}
content=content+'" onClick="javascript:document.getElementById(\''+datefield_id+'\').value=\''+(cmonth+1)+'/'+(x-wkday+1)+'/'+cyear+'\'">'+(x-wkday+1)+' ';
if(!((x+1)%7)){
content=content+'';
}
}else{
content=content+'>';
}
}
content=content+'
';
document.getElementById(calendarfield_id).innerHTML=content;
}
content=content+' ';
if(timefield_id){
var apm = new Array('A.M.','P.M.');
content=content+'';
content=content+'Time ';
start=sdt.getDay();
for(x=0;x<24;x++){
if(!x){
y=12;
}else{
y=x
}
content=content+''+(y-13*Math.floor(x/13)+Math.floor(x/13))+' ';
if(!((x+1)%6)){
if(x==5){
content=content+''+apm[0]+' ';
}else if(x==23){
content=content+' ';
}else if(x==17){
content=content+''+apm[1]+' ';
}
content=content+'';
}
}
content=content+':00 :15 :30 :45 ';
content=content+'
';
}
content=content+'[close]
';
document.getElementById(calendarfield_id).innerHTML=content;
}