shithub: riscv

Download patch

ref: 48d4083efa222eab86a658d45c7511fcccd0a27b
parent: aedb35af2c5defe2ede15f4e5a7bffe8a3bc32bc
author: cinap_lenrek <[email protected]>
date: Fri May 31 22:42:02 EDT 2013

mothra: implement link buttons

a button embedded in a <a> link tag should follow the link
when clicked.

--- a/sys/src/cmd/mothra/forms.c
+++ b/sys/src/cmd/mothra/forms.c
@@ -124,12 +124,18 @@
 	case Tag_input:
 	case Tag_button:
 		if(g->form==0){
-		BadTag:
-			htmlerror(g->name, g->lineno, "<%s> not in form, ignored\n",
-				tag[g->tag].name);
-			break;
-		}
-		f=newfield(g->form);
+			/* no form, assume link button */
+			form = emalloc(sizeof(Form));	
+			form->method = 0;
+			form->fields = 0;
+			form->efields = 0;
+			if(g->state->link[0])
+				form->action = strdup(g->state->link);
+			form->next = g->dst->form;
+			g->dst->form = form;
+			f=newfield(form);
+		} else
+			f=newfield(g->form);
 		s=pl_getattr(g->attr, "name");
 		if(s==0)
 			f->name=0;
@@ -201,7 +207,12 @@
 			pl_htmloutput(g, g->nsp, f->value[0]?f->value:"blank field", f);
 		break;
 	case Tag_select:
-		if(g->form==0) goto BadTag;
+		if(g->form==0){
+		BadTag:
+			htmlerror(g->name, g->lineno, "<%s> not in form, ignored\n",
+				tag[g->tag].name);
+			break;
+		}
 		f=newfield(g->form);
 		s=pl_getattr(g->attr, "name");
 		if(s==0){
@@ -455,8 +466,15 @@
 	}
 	pldraw(text, screen);
 }
+
 void h_buttoninput(Panel *p, int){
+	Field *f;
+
+	f = p->userp;
+	if(f && f->form && f->form->method != POST && f->form->action)
+		geturl(f->form->action, -1, 0, 0);
 }
+
 void h_fileinput(Panel *p, int){
 	char name[NNAME];
 	Field *f;
@@ -638,11 +656,19 @@
 	for(f=form->fields;f;f=f->next)
 		if(f->type==SUBMIT)
 			f->state = (f->p == p);
-	if(form->method==GET){
+
+	switch(form->method){
+	case GET:
 		strcpy(buf, "/tmp/mfXXXXXXXXXXX");
 		fd = create(mktemp(buf), ORDWR|ORCLOSE, 0600);
-	} else
+		break;
+	case POST:
 		fd = urlpost(selurl(form->action), form->ctype);
+		break;
+	default:
+		return;
+	}
+
 	if(fd < 0){
 		message("submit: %r");
 		return;