mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Tell the selected submit button to the server.
Commit 9cc9db4e24e54499e3736d14563ee2721012d724 broke submit buttons on HTML forms, so that the server no longer knows which button was actually pressed. <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] Originally posted as: <mid:87ek2heebh.fsf@Astalo.kon.iki.fi> <nntp://news.gmane.org/87ek2heebh.fsf@Astalo.kon.iki.fi> <http://permalink.gmane.org/gmane.comp.web.links/2745>
This commit is contained in:
parent
347970988d
commit
b623decfb5
@ -860,12 +860,22 @@ get_link_uri(struct session *ses, struct document_view *doc_view,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
try_submit_given_form(struct session *ses, struct document_view *doc_view,
|
call_onsubmit_or_submit(struct session *ses, struct document_view *doc_view,
|
||||||
struct form *form, int do_reload)
|
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
|
#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;
|
struct string code;
|
||||||
|
|
||||||
if (init_string(&code)) {
|
if (init_string(&code)) {
|
||||||
@ -886,11 +896,21 @@ try_submit_given_form(struct session *ses, struct document_view *doc_view,
|
|||||||
add_to_string(&code, form->onsubmit);
|
add_to_string(&code, form->onsubmit);
|
||||||
res = ecmascript_eval_boolback(interpreter, &code);
|
res = ecmascript_eval_boolback(interpreter, &code);
|
||||||
done_string(&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
|
#endif /* CONFIG_ECMASCRIPT */
|
||||||
submit_given_form(ses, doc_view, form, do_reload);
|
|
||||||
|
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 *
|
struct link *
|
||||||
@ -907,9 +927,10 @@ goto_current_link(struct session *ses, struct document_view *doc_view, int do_re
|
|||||||
|
|
||||||
if (link_is_form(link)) {
|
if (link_is_form(link)) {
|
||||||
struct form_control *fc = link->data.form_control;
|
struct form_control *fc = link->data.form_control;
|
||||||
struct form *form = fc->form;
|
|
||||||
|
|
||||||
try_submit_given_form(ses, doc_view, form, do_reload);
|
if (!call_onsubmit_or_submit(ses, doc_view, fc, do_reload))
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
return link;
|
return link;
|
||||||
} else
|
} else
|
||||||
uri = get_link_uri(ses, doc_view, link);
|
uri = get_link_uri(ses, doc_view, link);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user