I needed an easy way to create forms which can have optional value field. Initially, I used line like

<input name=passwd value="<! sql print @myquery.7 >" size=20>

which was fine if myquery was succesful. But, to reduce html writing, I wanted an input field which would return default value if it's defined or nothing for default value if it's undefined (this way I can use same form for add and edit of data). So I made qinput tag in which

<! sql qinput @myquery.7 passwd size=20>

is equivalent to:

<input name=passwd value="<! sql print @myquery.7 >" size=20>

That solves my problem, and maybe someone else's.

However, I still have several doubts:
1. should it be called qinput or input? It actually doesn't fetch anything, so
   more precise name would be just input, right? In patch is also
   implementation of input, which is more like a real command with
   this syntax:
   <! sql input passwd @myquery.7 size=20>
2. I implemented it only in mysql.c. Shuould I implement it also in pgsql.c or
   would you do that?
3. Is mysql.c wrong place for this command? I think that it should be in
   some other module, but I can't access query variables from other
   modules.

It seems that I'm trying to get into contributers list as hard as I can :-)
Oh, I just use www-sql and want to contribute...


--- mysql.c.orig	Wed Mar 10 18:51:21 1999
+++ mysql.c	Sat Mar 20 22:13:36 1999
@@ -432,6 +432,80 @@
   fprintf(yyout, "</select>");
 }
 
+/* print a <input> tag for use in forms.
+	<! sql qinput [variable] [field_name] [opt]... >
+	varible can be any www-sql variable. if it's undefined there will be no value tag
+	field_name will be transformed to name="field_name" tag
+	opt(s) are optional arguments like type=text, size=30 etc.
+		<dpavlin@foi.hr> */
+
+void cmdQinput (int argc, char *argv[]) {
+  int arg;
+  qHandle *qh;
+  VAR *var;
+
+  checkNumArgs(2,"qinput");
+  checkConn("qinput");
+
+  fprintf(yyout, "<input name=\"%s\" ", substVars(argv[1]));
+
+  for (qh = firstQuery; qh != NULL; qh = qh->next) {
+	if (argv[0][0] == '@' && !strncmp(qh->name, argv[0]+1, strlen(qh->name)) && argv[0][strlen(qh->name)+1] == '.') {
+		fprintf(yyout, "value=\"%s\" ", substVars(argv[0]));
+		break;
+	}
+  }
+
+  for (var = firstVar; var != NULL; var = var->next)
+	if (!strcmp(argv[0]+1, var->name)) {
+		fprintf(yyout, "value=\"%s\" ", substVars(argv[0]));
+		break;
+	}
+
+  for(arg = 2; arg < argc; arg++) {	/* dump rest of arguments */
+  	fprintf(yyout, "%s ", argv[arg]);
+  }
+  fprintf(yyout, ">\n");
+}
+
+
+/* print a <input> tag for use in forms.
+	<! sql input [name] [variable] [opt]... >
+	name will be used for form field name in name="name" tag
+	varible can be any www-sql variable. if it's undefined there will be no value tag
+	opt(s) are optional arguments like type=text, size=30 etc.
+		<dpavlin@foi.hr> */
+
+void cmdInput (int argc, char *argv[]) {
+  int arg;
+  qHandle *qh;
+  VAR *var;
+
+  checkNumArgs(2,"input");
+  checkConn("input");
+
+  fprintf(yyout, "<input name=\"%s\" ", substVars(argv[0]));
+
+  for (qh = firstQuery; qh != NULL; qh = qh->next) {
+	if (argv[1][0] == '@' && !strncmp(qh->name, argv[1]+1, strlen(qh->name)) && argv[1][strlen(qh->name)+1] == '.') {
+		fprintf(yyout, "value=\"%s\" ", substVars(argv[1]));
+		break;
+	}
+  }
+
+  for (var = firstVar; var != NULL; var = var->next)
+	if (!strcmp(argv[1]+1, var->name)) {
+		fprintf(yyout, "value=\"%s\" ", substVars(argv[1]));
+		break;
+	}
+
+  for(arg = 2; arg < argc; arg++) {	/* dump rest of arguments */
+  	fprintf(yyout, "%s ", argv[arg]);
+  }
+  fprintf(yyout, ">\n");
+}
+
+
 commands db_funcs = {
   {"connect",    cmdConnect},
   {"close",      cmdClose},
@@ -444,6 +518,8 @@
   {"qtable",     cmdQtable},
   {"qlongform",  cmdQlongform},
   {"qselect",    cmdQselect},
+  {"qinput",     cmdQinput},
+  {"input",      cmdInput},
   {NULL, NULL}
 };
 
