Skip to content

Commit ceda137

Browse files
committed
LibWeb: Support <form method=POST>
Use the new support for HTTP method and request body to implement basic support for POST'ed forms. This is pretty cool! :^)
1 parent 2946a68 commit ceda137

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Libraries/LibWeb/HTML/HTMLFormElement.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ void HTMLFormElement::submit(RefPtr<HTMLInputElement> submitter)
5050
}
5151

5252
auto effective_method = method().to_lowercase();
53-
if (effective_method != "get") {
54-
if (effective_method == "post" || effective_method == "dialog") {
53+
if (effective_method != "get" && effective_method != "post") {
54+
if (effective_method == "dialog") {
5555
dbg() << "Unsupported form method '" << method() << "'";
5656
return;
5757
}
@@ -69,10 +69,24 @@ void HTMLFormElement::submit(RefPtr<HTMLInputElement> submitter)
6969
return IterationDecision::Continue;
7070
});
7171

72-
url.set_query(urlencode(parameters));
72+
if (effective_method == "get") {
73+
url.set_query(urlencode(parameters));
74+
}
7375

7476
// FIXME: We shouldn't let the form just do this willy-nilly.
75-
document().frame()->page().load(url);
77+
78+
LoadRequest request;
79+
request.set_url(url);
80+
81+
if (effective_method == "post") {
82+
auto body = urlencode(parameters).to_byte_buffer();
83+
request.set_method("POST");
84+
request.set_header("Content-Type", "application/x-www-form-urlencoded");
85+
request.set_header("Content-Length", String::number(body.size()));
86+
request.set_body(body);
87+
}
88+
89+
document().frame()->page().load(request);
7690
}
7791

7892
}

0 commit comments

Comments
 (0)