Forum Moderators: open

Message Too Old, No Replies

input type hidden syntax problem

         

hafnius

7:38 pm on Dec 10, 2005 (gmt 0)

10+ Year Member



Hi all

I have a form with two checkboxes like this:


<input type="checkbox" name="FE[tt_address][module_mail_category][1]">
<input type="checkbox" name="FE[tt_address][module_mail_category][2]">

For this form i want to send one value and thus not showing the checkboxes too the visitor so i include it as a input type hidden:


<input type="hidden" name="FE[tt_address][module_mail_category][1]" checked>

But my db is not updated with correct value, ie it does not send 1 as the value of the field.

What am i doing wrong here?

Kind Regards
Klaus b

encyclo

6:02 pm on Dec 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A hidden input is not the same as a checkbox - it is more like an invisible text box. You should try something like this:

<input type="hidden" name="hidden_field" value="FE[tt_address][module_mail_category][1]">

hafnius

7:17 pm on Dec 12, 2005 (gmt 0)

10+ Year Member



thanks for your answer, encyclo but thats does not work.

I have tryied all the variants that i can think of but it wont send the correct value to the db.

i'll have to check the receiving .php script to see how it handles the formdata but i cant cut this one right now - annoying though.

Kind Regards
Klaus b

jalarie

2:05 pm on Dec 13, 2005 (gmt 0)

10+ Year Member



Store the following code in a file named formdisp.js, add '<script type="text/javascript" src="formdisp.js"></script>' (without the outer quote marks) to your head section, add '<input type="button" value=" Show It " onclick="FormDisplay(this.form);">' (no outer quote marks) to your form, click this new button to get a popup showing what will be sent to the server:

// FormDisplay.js
// Written: 2001-03-02 by James Alarie <jalarie@umich.edu>

function FormDisplay(Which,Detail) {
FD_f1=Which;
FD_Detail=Detail;
FD_Len=FD_f1.length;
FD_Now=new Date();
// changable options:
FD_thcolor='#ffff99';
FD_tdcolor='aqua';
FD_wcolor='#ffcccc';
// header:
FD_O ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n';
FD_O+=' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
FD_O+='\n';
FD_O+='<html lang="en-US">\n <head>\n <title>Form Display</title>\n';
FD_O+=' <meta http-equiv="Content-Script-Type" content="text/javascript" \/>\n';
FD_O+=' <meta http-equiv="Content-Style-Type" content="text/css" \/>\n';
FD_O+=' <meta http-equiv="PICS-Label" content=\'(PICS-1.1 "http:\/\/www.classify.org\/safesurf\/" l gen true for "http:\/\/spruce.flint.umich.edu\/~jalarie\/" r (SS~~000 1))\' \/>\n';
FD_O+=' <meta http-equiv="pics-label" content=\'(pics-1.1 "http:\/\/www.icra.org\/ratingsv02.html" comment "basic online form" l gen true for "http:\/\/spruce.flint.umich.edu\/~jalarie\/" r (nz 1 ns 1 vz 1 vs 1 lz 1 oz 1 cz 1) "http:\/\/www.rsac.org\/ratingsv01.html" l gen true for "http:\/\/spruce.flint.umich.edu\/~jalarie\/" r (n 0 s 0 v 0 l 0))\' \/>\n';
FD_O+=' <link href="style1.css" rel="stylesheet" type="text/css" \/>\n';
FD_O+=' <\/head>\n';
FD_O+=' <body class="body1">\n';
FD_O+=' <div align="center"><h2>Form Display<\/h2><\/div>\n';
FD_O+=' &quot;And all things, whatsoever ye shall ask in prayer, believing, ye shall receive.&quot;&nbsp; \n';
FD_O+=' Matthew&nbsp;21:22.\n';
FD_O+=' <hr \/><br \/>\n';
FD_O+=' <div align="center">\n';
FD_O+=' <b>'+FD_Now+'<\/b><br \/><br \/>\n';
// main form characteristics:
FD_O+=' <table border="1" cellspacing="2" cellpadding="2">\n';
FD_O+=' <thead>\n';
FD_O+=' <tr>\n';
FD_O+=' <th bgcolor="'+FD_thcolor+'" colspan="2">Form Characteristics <\/th>\n';
FD_O+=' <\/tr>\n';
FD_O+=' <tr>\n';
FD_O+=' <th bgcolor="'+FD_thcolor+'">Name <\/th>\n';
FD_O+=' <th bgcolor="'+FD_thcolor+'">Value <\/th>\n';
FD_O+=' <\/tr>\n';
FD_O+=' <\/thead>\n';
FD_O+=' <tbody>\n';
FD_A=new Array(
'name','length','method','action','enctype','target',
'id','accept','onsubmit','onreset','accept-charset'
)
for (FD_ix1=0; FD_ix1<FD_A.length; FD_ix1++) {
FD_A1=FD_A[FD_ix1];
FD_W1=String(Which[FD_A1]).substring(0,1);
if ((Which[FD_A1]) && (FD_W1!= '<') && (FD_W1!= '[')) {
FD_O+=' <tr>\n';
FD_O+=' <td align="left" bgcolor="'+FD_tdcolor+'">'+FD_A1+' <\/td>\n';
FD_O+=' <td align="left" bgcolor="'+FD_tdcolor+'">'+Which[FD_A1]+' <\/td>\n';
FD_O+=' <\/tr>\n';
}
}
FD_O+=' <\/tbody>\n';
FD_O+=' <\/table>\n';
FD_O+=' <br \/>\n';
// fields:
FD_O+=' <table border="1" cellspacing="2" cellpadding="2">\n';
FD_O+=' <thead>\n';
FD_O+=' <tr>\n';
if (FD_Detail) {
FD_O+=' <th bgcolor="'+FD_thcolor+'" colspan="7">The Form Contains '+FD_Len+' Items <\/th>\n';
} else {
FD_O+=' <th bgcolor="'+FD_thcolor+'" colspan="6">The Form Contains '+FD_Len+' Items <\/th>\n';
}
FD_O+=' <\/tr>\n';
FD_O+=' <tr>\n';
FD_O+=' <th bgcolor="'+FD_thcolor+'"># <\/th>\n';
FD_O+=' <th bgcolor="'+FD_thcolor+'">Type <\/th>\n';
FD_O+=' <th bgcolor="'+FD_thcolor+'">Field Name <\/th>\n';
FD_O+=' <th bgcolor="'+FD_thcolor+'">Field ID <\/th>\n';
FD_O+=' <th bgcolor="'+FD_thcolor+'">Value <\/th>\n';
FD_O+=' <th bgcolor="'+FD_thcolor+'">Success <\/th>\n';
if (FD_Detail) {
FD_O+=' <th bgcolor="'+FD_thcolor+'">Details <\/th>\n';
}
FD_O+=' <\/tr>\n';
FD_O+=' <\/thead>\n';
FD_O+=' <tbody>\n';
for (FD_ix1=0; FD_ix1<FD_Len; FD_ix1++) {
FD_Item=FD_f1[FD_ix1];
FD_Type=FD_Item.type;
FD_Processed='no';
// Types recognized: checkbox, file, hidden, password, radio, reset,
// select-one/multiple, submit, text, textarea.
// Types not processed: button, image, isindex.
if (FD_Type == 'checkbox') { // checkbox
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Value=FD_Item.checked;
if (FD_Item.checked) { FD_Success='yes'; } else { FD_Success='no'; }
FormDisplaySub();
}
if (FD_Type == 'file') { // file
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Value=FD_Item.value;
FD_Success='yes';
FormDisplaySub();
}
if (FD_Type == 'hidden') { // hidden
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Value=FD_Item.value;
FD_Success='yes';
FormDisplaySub();
}
if (FD_Type == 'password') { // password
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Value=FD_Item.value;
FD_Success='yes';
FormDisplaySub();
}
if (FD_Type == 'radio') { // radio
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Value=FD_Item.value;
if (FD_Item.checked) { FD_Success='yes'; } else { FD_Success='no'; }
FormDisplaySub();
}
if (FD_Type == 'reset') { // reset
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Value=FD_Item.value;
FD_Success='no'; // reset is never successful
FormDisplaySub();
}
if (FD_Type == 'select-one') { // select-one
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Index=FD_Item.selectedIndex;
FD_Value=FD_Item.options[FD_Index].value;
FD_Success='yes'; // always sucessful
FormDisplaySub();
}
if (FD_Type == 'select-multiple') { // select-multiple
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Length=FD_Item.length;
FD_Value='';
for (var ix2=0; ix2<FD_Length; ix2++) {
if (FD_Item.options[ix2].selected) {
var Val=FD_Item.options[ix2].value;
if (!Val) { Val=FD_Item.options[ix2].text; }
if (FD_Value) { FD_Value=FD_Value+'\n'+Val; }
else { FD_Value= Val; }
}
}
if (FD_Value) { FD_Success='yes'; } else { FD_Success='no'; }
FormDisplaySub();
}
if (FD_Type == 'submit') { // submit
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Value=FD_Item.value;
if (FD_Item.checked) { FD_Success='yes'; } else { FD_Success='no'; }
FormDisplaySub();
}
if (FD_Type == 'text') { // text
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Value=FD_Item.value;
FD_Success='yes';
FormDisplaySub();
}
if (FD_Type == 'textarea') { // textarea
FD_Name=FD_Item.name;
FD_ID=FD_Item.id;
FD_Value=FD_Item.value;
FD_Success='yes';
FormDisplaySub();
}
if (FD_Processed == 'no') { // unprocessed item
var FDI=FormDisplayEsc();
FD_O+=' <tr>\n';
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="right">'+FD_ix1+' <\/td>\n';
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="left">'+FD_Type+' <\/td>\n';
if (FD_Detail) {
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="center" colspan="4">- - not processed - - <\/td>\n';
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="left">'+FDI+' <\/td>\n';
} else {
FD_O+=' <td bgcolor="'+FD_tdcolor+'" colspan="4" align="left">'+FDI+' <\/td>\n';
}
FD_O+=' <\/tr>\n';
}
}
FD_O+=' <tr>\n';
if (FD_Detail) {
FD_O+=' <td bgcolor="'+FD_wcolor+'" colspan="7" align="center">Only named, successful fields are sent to the server. <\/td>\n';
} else {
FD_O+=' <td bgcolor="'+FD_wcolor+'" colspan="6" align="center">Only named, successful fields are sent to the server. <\/td>\n';
}
FD_O+=' <\/tr>\n';
FD_O+=' <\/tbody>\n';
FD_O+=' <\/table>\n';
FD_O+=' <br \/>\n';
FD_O+=' [<a href="javascript:void(0);" onclick="window.print();" title=" print ">Print</a>] \n';
FD_O+=' [<a href="javascript:void(0);" onclick="window.close();" title=" close ">Close</a>] \n';
FD_O+=' <\/div>\n';
// footer:
FD_O+=' <br clear="all" \/><hr \/>\n';
FD_O+=' Written on March 2, 2001, by <a href="mailto:jalarie@umich.edu" title=" e-mail ">James Alarie<\/a>.\n';
FD_O+=' <\/body>\n<\/html>\n';
FD_W=screen.width;
FD_H=screen.height;
FD_Opts='scrollbars,resizable';
// FD_Opts=FD_Opts+',width='+FD_W+',height='+FD_H; // full-screen
FD_popup1=window.open('','FormDisplay',FD_Opts);
with(FD_popup1.document) {
write(FD_O);
close();
}
// FD_popup1.window.moveTo(0,0); // move to top-left corner
return true;
}
function FormDisplaySub() {
var S=FD_Success;
if (S == 'yes') {
if (FD_Value) {
FD_Value=String(FD_Value);
FD_Value=FD_Value.replace(/\</g,'&lt;');
FD_Value=FD_Value.replace(/\>/g,'&gt;');
FD_Value=FD_Value.replace(/\"/g,'&quot;');
FD_Value=FD_Value.replace(/\n/g,'<br \/>');
}
else { S='yes - null'; }
if (!FD_Name) { S='yes - unnamed'; }
}
FD_O+=' <tr>\n';
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="right" valign="top">'+FD_ix1+' <\/td>\n';
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="left" valign="top">'+FD_Type+' <\/td>\n';
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="left" valign="top">'+FD_Name+'&nbsp;<\/td>\n';
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="left" valign="top">'+FD_ID+'&nbsp;<\/td>\n';
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="left" valign="top">'+FD_Value+'&nbsp;<\/td>\n';
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="left" valign="top">'+S+' <\/td>\n';
if (FD_Detail) {
var FDI=FormDisplayEsc();
FD_O+=' <td bgcolor="'+FD_tdcolor+'" align="left">'+FDI+' <\/td>\n';
}
FD_O+=' <\/tr>\n';
FD_Processed='yes';
return true;
}
function FormDisplayEsc() {
var FDI=String(FD_Item);
FDI=FDI.replace(/\</g,'&lt;');
FDI=FDI.replace(/\>/g,'&gt;');
FDI=FDI.replace(/\"/g,'&quot;');
FDI=FDI.replace(/\n/g,'<br \/>');
return FDI;
}