1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-07-01 02:05:33 +00:00

Tell the selected submit button to the server.

Commit 9cc9db4e24 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:
Kalle Olavi Niemitalo 2006-02-06 20:57:08 +02:00 committed by Kalle Olavi Niemitalo
parent 347970988d
commit b623decfb5

View File

@ -860,12 +860,22 @@ get_link_uri(struct session *ses, struct document_view *doc_view,
}
}
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 *ses, struct document_view *doc_view,
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, struct document_view *doc_view, int do_re
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);