mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Handling onsubmit
This commit is contained in:
parent
6e4c80a29e
commit
9cc9db4e24
@ -91,6 +91,7 @@ done_form(struct form *form)
|
||||
|
||||
mem_free_if(form->action);
|
||||
mem_free_if(form->name);
|
||||
mem_free_if(form->onsubmit);
|
||||
mem_free_if(form->target);
|
||||
|
||||
foreach (fc, form->items) {
|
||||
|
@ -32,6 +32,7 @@ struct form {
|
||||
|
||||
unsigned char *action;
|
||||
unsigned char *name;
|
||||
unsigned char *onsubmit;
|
||||
unsigned char *target;
|
||||
enum form_method method;
|
||||
|
||||
|
@ -69,7 +69,7 @@ html_form(struct html_context *html_context, unsigned char *a,
|
||||
}
|
||||
mem_free(al);
|
||||
}
|
||||
|
||||
form->onsubmit = get_attr_val(a, "onsubmit", html_context->options);
|
||||
al = get_attr_val(a, "name", html_context->options);
|
||||
if (al) form->name = al;
|
||||
|
||||
|
@ -933,7 +933,7 @@ js_form_submit(struct SEE_interpreter *interp, struct SEE_object *self,
|
||||
|
||||
assert(form);
|
||||
checktime(interp);
|
||||
submit_given_form(ses, doc_view, form);
|
||||
submit_given_form(ses, doc_view, form, 0);
|
||||
SEE_SET_BOOLEAN(res, 0);
|
||||
}
|
||||
|
||||
|
@ -805,7 +805,7 @@ form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
struct form *form = find_form_by_form_view(doc_view->document, fv);
|
||||
|
||||
assert(form);
|
||||
submit_given_form(ses, doc_view, form);
|
||||
submit_given_form(ses, doc_view, form, 0);
|
||||
|
||||
boolean_to_jsval(ctx, rval, 0);
|
||||
|
||||
|
@ -1102,7 +1102,8 @@ submit_form(struct session *ses, struct document_view *doc_view, int do_reload)
|
||||
}
|
||||
|
||||
void
|
||||
submit_given_form(struct session *ses, struct document_view *doc_view, struct form *form)
|
||||
submit_given_form(struct session *ses, struct document_view *doc_view,
|
||||
struct form *form, int do_reload)
|
||||
{
|
||||
/* Added support for submitting forms in hidden
|
||||
* links in 1.285, commented code can safely be removed once we have made sure the new
|
||||
@ -1125,11 +1126,12 @@ submit_given_form(struct session *ses, struct document_view *doc_view, struct fo
|
||||
if (!list_empty(form->items)) {
|
||||
struct form_control *fc = (struct form_control *)form->items.next;
|
||||
struct uri *uri;
|
||||
enum cache_mode mode = do_reload ? CACHE_MODE_FORCE_RELOAD : CACHE_MODE_NORMAL;
|
||||
|
||||
if (!fc) return;
|
||||
uri = get_form_uri(ses, doc_view, fc);
|
||||
if (!uri) return;
|
||||
goto_uri_frame(ses, uri, form->target, CACHE_MODE_NORMAL);
|
||||
goto_uri_frame(ses, uri, form->target, mode);
|
||||
done_uri(uri);
|
||||
}
|
||||
}
|
||||
@ -1140,7 +1142,7 @@ auto_submit_form(struct session *ses)
|
||||
struct document *document = ses->doc_view->document;
|
||||
|
||||
if (!list_empty(document->forms))
|
||||
submit_given_form(ses, ses->doc_view, document->forms.next);
|
||||
submit_given_form(ses, ses->doc_view, document->forms.next, 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,7 +88,7 @@ void draw_forms(struct terminal *term, struct document_view *doc_view);
|
||||
|
||||
enum frame_event_status reset_form(struct session *ses, struct document_view *doc_view, int a);
|
||||
enum frame_event_status submit_form(struct session *ses, struct document_view *doc_view, int do_reload);
|
||||
void submit_given_form(struct session *ses, struct document_view *doc_view, struct form *form);
|
||||
void submit_given_form(struct session *ses, struct document_view *doc_view, struct form *form, int do_reload);
|
||||
void auto_submit_form(struct session *ses);
|
||||
void do_reset_form(struct document_view *doc_view, struct form *form);
|
||||
|
||||
|
@ -854,6 +854,40 @@ 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)
|
||||
{
|
||||
#ifdef CONFIG_ECMASCRIPT
|
||||
if (form->onsubmit) {
|
||||
struct string code;
|
||||
|
||||
if (init_string(&code)) {
|
||||
struct view_state *vs = doc_view->vs;
|
||||
struct ecmascript_interpreter *interpreter;
|
||||
int res = 1;
|
||||
unsigned char *ret = form->onsubmit;
|
||||
|
||||
if (vs->ecmascript_fragile)
|
||||
ecmascript_reset_state(vs);
|
||||
interpreter = vs->ecmascript;
|
||||
assert(interpreter);
|
||||
#ifdef CONFIG_ECMASCRIPT_SEE
|
||||
/* SEE doesn't like return outside functions */
|
||||
while ((ret = strstr(ret, "return "))) {
|
||||
while (*ret != ' ') *ret++ = ' ';
|
||||
}
|
||||
#endif
|
||||
add_to_string(&code, form->onsubmit);
|
||||
res = ecmascript_eval_boolback(interpreter, &code);
|
||||
done_string(&code);
|
||||
if (!res) return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
submit_given_form(ses, doc_view, form, do_reload);
|
||||
}
|
||||
|
||||
struct link *
|
||||
goto_current_link(struct session *ses, struct document_view *doc_view, int do_reload)
|
||||
{
|
||||
@ -866,9 +900,13 @@ goto_current_link(struct session *ses, struct document_view *doc_view, int do_re
|
||||
link = get_current_link(doc_view);
|
||||
if (!link) return NULL;
|
||||
|
||||
if (link_is_form(link))
|
||||
uri = get_form_uri(ses, doc_view, get_link_form_control(link));
|
||||
else
|
||||
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;
|
||||
} else
|
||||
uri = get_link_uri(ses, doc_view, link);
|
||||
|
||||
if (!uri) return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user