From 032a745e654e733c1ac8bb385d9d36b58f527f14 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Mon, 2 Feb 2004 21:13:06 +0000 Subject: [PATCH] Form validatin now also works for radio buttons SVN revision: 732 --- src/elogd.c | 115 +++++++++++++++++++++++++------------ themes/default/default.css | 7 +++ 2 files changed, 84 insertions(+), 38 deletions(-) diff --git a/src/elogd.c b/src/elogd.c index 51702c6b..1813202b 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 1.224 2004/02/02 21:13:06 midas + Form validatin now also works for radio buttons + Revision 1.223 2004/02/02 16:28:04 midas Added javascript for required attributes checking @@ -4189,7 +4192,7 @@ void rsputs2(const char *str) sprintf(return_buffer + j, "%s", list[l], link, list[l]); j += strlen(return_buffer + j); strlen_retbuf = j; - + /* link_text can contain special characters */ rsputs2(link_text); j = strlen_retbuf; @@ -4813,7 +4816,7 @@ void show_html_header(LOGBOOK * lbs, BOOL expires, char *title, BOOL close_head) rsprintf("\n", css); if (close_head) - rsprintf("\n"); + rsprintf("\n"); } void show_standard_header(LOGBOOK * lbs, BOOL expires, char *title, char *path) @@ -6033,15 +6036,38 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL for (i = 0; i < lbs->n_attr; i++) if (attr_flags[i] & AF_REQUIRED) { - - if ((attr_flags[i] & AF_MULTI) == 0) { + + if (attr_flags[i] & AF_MULTI) { + rsprintf(" if (\n"); + for (j = 0; j < MAX_N_LIST && attr_options[i][j][0]; j++) { + sprintf(str, "%s_%d", attr_list[i], j); + rsprintf(" !document.form1.%s.checked", str); + if (attr_options[i][j + 1][0]) + rsprintf(" &&\n"); + } + rsprintf(") {\n"); + sprintf(str, loc("Please select at least one '%s'"), attr_list[i]); + rsprintf(" alert(\"%s\");\n", str); + rsprintf(" document.form1.%s_0.focus();\n", attr_list[i]); + rsprintf(" return false;\n"); + rsprintf(" }\n"); + } else if (attr_flags[i] & AF_RADIO) { + rsprintf(" for (var i=0 ; i\n"); rsprintf("
\n"); + rsprintf("enctype=\"multipart/form-data\">\n"); /*---- add password in case cookie expires during edit ----*/ @@ -6076,7 +6102,9 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* default cmd */ rsprintf("\n", loc("Update")); - rsprintf("\n", loc("Submit")); + rsprintf + ("\n", + loc("Submit")); rsprintf("\n", loc("Back")); rsprintf("\n\n"); @@ -6203,7 +6231,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL if (attr_flags[index] & AF_MULTI) { for (i = 0; i < MAX_N_LIST && attr_options[index][i][0]; i++) { - sprintf(str, "%s#%d", attr_list[index], i); + sprintf(str, "%s_%d", attr_list[index], i); if (strstr(attrib[index], attr_options[index][i])) rsprintf("\n", str, @@ -6211,7 +6239,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL } } else if (attr_flags[index] & AF_RADIO) { for (i = 0; i < MAX_N_LIST && attr_options[index][i][0]; i++) { - sprintf(str, "%s#%d", attr_list[index], i); + sprintf(str, "%s_%d", attr_list[index], i); if (strstr(attrib[index], attr_options[index][i])) rsprintf("\n", str, @@ -6219,7 +6247,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL } } else if (attr_flags[index] & AF_ICON) { for (i = 0; i < MAX_N_LIST && attr_options[index][i][0]; i++) { - sprintf(str, "%s#%d", attr_list[index], i); + sprintf(str, "%s_%d", attr_list[index], i); if (strstr(attrib[index], attr_options[index][i])) rsprintf("\n", str, @@ -6250,7 +6278,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL rsprintf("\n"); for (i = 0; i < MAX_N_LIST && attr_options[index][i][0]; i++) { - sprintf(str, "%s#%d", attr_list[index], i); + sprintf(str, "%s_%d", attr_list[index], i); if (strstr(attrib[index], attr_options[index][i])) rsprintf @@ -6849,7 +6877,7 @@ void show_find_form(LOGBOOK * lbs) rsprintf("