-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwo_field_app.cpp
More file actions
61 lines (55 loc) · 2.09 KB
/
two_field_app.cpp
File metadata and controls
61 lines (55 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "crow.h"
int main()
{
crow::SimpleApp app;
// Define a route that serves the HTML page with two text fields
CROW_ROUTE(app, "/")
([](){
std::string page = R"(
<!DOCTYPE html>
<html>
<head>
<title>C++ Web App with Two Text Fields</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
.container { max-width: 600px; margin: 0 auto; }
.text-field { margin-bottom: 15px; }
label { display: block; margin-bottom: 5px; }
input[type="text"] { width: 100%; padding: 8px; }
button { padding: 10px 15px; background: #007bff; color: white; border: none; cursor: pointer; }
button:hover { background: #0056b3; }
</style>
</head>
<body>
<div class="container">
<h1>Two Text Field Web App</h1>
<form action="/process" method="post">
<div class="text-field">
<label for="field1">Field 1:</label>
<input type="text" id="field1" name="field1">
</div>
<div class="text-field">
<label for="field2">Field 2:</label>
<input type="text" id="field2" name="field2">
</div>
<button type="submit">Submit</button>
</form>
</div>
</body>
</html>
)";
return crow::response(page);
});
// Handle form submission
CROW_ROUTE(app, "/process").methods("POST"_method)
([](const crow::request& req){
auto field1 = req.url_params.get("field1");
auto field2 = req.url_params.get("field2");
std::string response = "You submitted:\n";
response += "Field 1: " + std::string(field1 ? field1 : "") + "\n";
response += "Field 2: " + std::string(field2 ? field2 : "");
return crow::response(response);
});
app.port(8080).multithreaded().run();
return 0;
}