|
| 1 | +## How to work with WebForms Core in Julia |
| 2 | + |
| 3 | +To use WebForms Core, first copy the WebForms class file in this directory to your project. Then create a new View file similar to the one below. |
| 4 | + |
| 5 | +```php |
| 6 | +using HTTP |
| 7 | + |
| 8 | +# Assuming WebForms and InputPlace modules are already defined in the project |
| 9 | +include("WebForms.jl") |
| 10 | +include("InputPlace.jl") |
| 11 | + |
| 12 | +function handle_request(req::HTTP.Request) |
| 13 | + if HTTP.hasheader(req, "Content-Type") && occursin("application/x-www-form-urlencoded", req.headers["Content-Type"]) |
| 14 | + body = String(req.body) |
| 15 | + params = HTTP.queryparams(body) |
| 16 | + |
| 17 | + if haskey(params, "btn_SetBodyValue") |
| 18 | + name = get(params, "txt_Name", "") |
| 19 | + background_color = get(params, "txt_BackgroundColor", "") |
| 20 | + font_size = parse(Int, get(params, "txt_FontSize", "16")) |
| 21 | + |
| 22 | + form = WebForms.WebForms() |
| 23 | + |
| 24 | + WebForms.set_font_size!(form, InputPlace.tag("form"), "$font_size" * "px") |
| 25 | + WebForms.set_background_color!(form, InputPlace.tag("form"), background_color) |
| 26 | + WebForms.set_disabled!(form, InputPlace.name("btn_SetBodyValue"), true) |
| 27 | + |
| 28 | + WebForms.add_tag!(form, InputPlace.tag("form"), "h3") |
| 29 | + WebForms.set_text!(form, InputPlace.tag("h3"), "Welcome $name!") |
| 30 | + |
| 31 | + return HTTP.Response(200, WebForms.response(form)) |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + # HTML form for the GET request |
| 36 | + html = """ |
| 37 | + <!DOCTYPE html> |
| 38 | + <html> |
| 39 | + <head> |
| 40 | + <title>Using WebForms Core</title> |
| 41 | + <script type="text/javascript" src="/script/web-forms.js"></script> |
| 42 | + </head> |
| 43 | + <body> |
| 44 | + <form method="post" action="/" > |
| 45 | + <label for="txt_Name">Your Name</label> |
| 46 | + <input name="txt_Name" id="txt_Name" type="text" /> |
| 47 | + <br> |
| 48 | + <label for="txt_FontSize">Set Font Size</label> |
| 49 | + <input name="txt_FontSize" id="txt_FontSize" type="number" value="16" min="10" max="36" /> |
| 50 | + <br> |
| 51 | + <label for="txt_BackgroundColor">Set Background Color</label> |
| 52 | + <input name="txt_BackgroundColor" id="txt_BackgroundColor" type="text" /> |
| 53 | + <br> |
| 54 | + <input name="btn_SetBodyValue" type="submit" value="Click to send data" /> |
| 55 | + </form> |
| 56 | + </body> |
| 57 | + </html> |
| 58 | + """ |
| 59 | + |
| 60 | + return HTTP.Response(200, html) |
| 61 | +end |
| 62 | + |
| 63 | +# Start the HTTP server |
| 64 | +HTTP.serve(handle_request, "127.0.0.1", 8080) |
| 65 | +``` |
| 66 | + |
| 67 | +In the upper part of the View file, it is first checked whether the submit button has been clicked or not, if it has been clicked, an instance of the WebForms class is created, then the WebForms methods are called, and then the response method is printed on the screen, and other parts Views are not displayed. |
| 68 | +Please note that if the submit button is not clicked (initial request), the view page will be displayed completely for the requester. |
| 69 | + |
| 70 | +As you can see, the WebFormsJS script has been added in the header section of the View file above. |
| 71 | + |
| 72 | +The latest version of the WebFormsJS script is available through the link below. |
| 73 | + |
| 74 | +https://github.com/elanatframework/Web_forms/blob/elanat_framework/web-forms.js |
0 commit comments