Commit 9cc9db4e24e54499e3736d14563ee2721012d724 broke submit buttons on HTML forms, so that the server no longer knows which button was actually pressed. The attached patch fixes this.
<kahmalo> In the current version 347970988d244afa226ceee6807bca9fbf3caeb3 plus
my incomplete accelerator-checking changes, editing a Wikipedia page
always seems to submit the "Show changes" button even if I select
"Save page" or "Show preview". [19:18]
<pasky> and without your incomplete accelerator-checking changes? ;) [19:19]
<kahmalo> I don't know, I didn't compile that tree.
<kahmalo> No such problem with 0.10.2, so not a server-side bug. [19:21]
<kahmalo> But anyway my tree worked too until I merged from elinks.cz today.
[19:23]
<kahmalo> And after that I've only edited po/perl/Locale/PO.pm which cannot
cause such a bug. [19:24]
<pasky> ok, lemme try with stock git [19:26]
<kahmalo> It fails too. [19:33]
<pasky> [EMAIL PROTECTED]:0]~/c.progs/elinks/elinks-elbuild$ src/elinks
-no-connect [19:40]
<pasky> /home/pasky/.elinks//elinks.conf:209: parse error
<pasky> /home/pasky/.elinks//elinks.conf:213: parse error
<pasky> ERROR: Unbound variable: goto-url-hooks
<pasky> hmm
<pasky> no luck for me?
<kahmalo> I'll track down the commit at which it begins to fail [19:41]
<pasky> kahmalo: git bisect might be helpful [19:44]
<kahmalo> pasky: thanks [19:47]
<kahmalo> 9cc9db4e24e54499e3736d14563ee2721012d724 is first bad commit [20:19]
<kahmalo> diff-tree 9cc9db4e24e54499e3736d14563ee2721012d724 (from
6e4c80a29ef5a35c35e4de6773aa74d9c9f6df9f)
<kahmalo> Author: <[EMAIL PROTECTED](none)>
<kahmalo> Date: Sat Jan 28 11:17:22 2006 +0100
<kahmalo>
<kahmalo> Handling onsubmit
...
<kahmalo> The bug with forms seems to be that try_submit_given_form (in
src/viewer/text/link.c) is the only function that runs "onsubmit"
scripts, and it does not care which of the submit buttons was
pressed; it calls submit_given_form which submits based on the first
item of the form. [20:57]
<kahmalo> or last, I don't know how the list works.
<kahmalo> try_submit_given_form could get the control via
get_current_link(doc_view) but I suppose it'd be cleaner to provide
that as a parameter. [20:58]
diff --git a/src/viewer/text/link.c b/src/viewer/text/link.c
index b1e6865..b3d73c6 100644
--- a/src/viewer/text/link.c
+++ b/src/viewer/text/link.c
@@ -860,12 +860,22 @@ get_link_uri(struct session *ses, struct
}
}
-static void
-try_submit_given_form(struct session *ses, struct document_view *doc_view,
- struct form *form, int do_reload)
+static int
+call_onsubmit_or_submit(struct session *ses, struct document_view *doc_view,
+ struct form_control *fc, int do_reload)
{
+ struct uri *uri = NULL;
+ enum cache_mode mode = do_reload ? CACHE_MODE_FORCE_RELOAD : CACHE_MODE_NORMAL;
+
+ assert(fc->form); /* regardless of whether there is a FORM element */
+ if_assert_failed return 0;
+
#ifdef CONFIG_ECMASCRIPT
- if (form->onsubmit) {
+ /* If the form has multiple submit buttons, this does not
+ * explicitly tell the ECMAScript code which of them was
+ * pressed. W3C DOM Level 3 doesn't seem to include such a
+ * feature. */
+ if (fc->form->onsubmit) {
struct string code;
if (init_string(&code)) {
@@ -886,11 +896,21 @@ try_submit_given_form(struct session *se
add_to_string(&code, form->onsubmit);
res = ecmascript_eval_boolback(interpreter, &code);
done_string(&code);
- if (!res) return;
+ /* If the user presses Enter in a text field,
+ * and document.browse.forms.auto_submit is
+ * true, and the form has an onsubmit script
+ * that returns false, then insert mode should
+ * end, so return 1 here rather than 0. */
+ if (!res) return 1;
}
}
-#endif
- submit_given_form(ses, doc_view, form, do_reload);
+#endif /* CONFIG_ECMASCRIPT */
+
+ uri = get_form_uri(ses, doc_view, fc);
+ if (!uri) return 0;
+ goto_uri_frame(ses, uri, fc->form->target, mode);
+ done_uri(uri);
+ return 1;
}
struct link *
@@ -907,10 +927,11 @@ goto_current_link(struct session *ses, s
if (link_is_form(link)) {
struct form_control *fc = link->data.form_control;
- struct form *form = fc->form;
- try_submit_given_form(ses, doc_view, form, do_reload);
- return link;
+ if (!call_onsubmit_or_submit(ses, doc_view, fc, do_reload))
+ return NULL;
+ else
+ return link;
} else
uri = get_link_uri(ses, doc_view, link);
pgpOhrMFVuym2.pgp
Description: PGP signature
_______________________________________________ elinks-dev mailing list [email protected] http://linuxfromscratch.org/mailman/listinfo/elinks-dev
